Commit 9a575c8c authored by Edwin Peer's avatar Edwin Peer Committed by David S. Miller

bnxt_en: Refactor coredump functions

The coredump functionality will be used by devlink health. Refactor
these functions that get coredump and coredump length. There is no
functional change, but the following checkpatch warnings were
addressed:

  - strscpy is preferred over strlcpy.
  - sscanf results should be checked, with an additional warning.
Signed-off-by: default avatarEdwin Peer <edwin.peer@broadcom.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8cc95ceb
......@@ -3808,7 +3808,7 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
record->low_version = 0;
record->high_version = 1;
record->asic_state = 0;
strlcpy(record->system_name, utsname()->nodename,
strscpy(record->system_name, utsname()->nodename,
sizeof(record->system_name));
record->year = cpu_to_le16(tm.tm_year + 1900);
record->month = cpu_to_le16(tm.tm_mon + 1);
......@@ -3820,11 +3820,12 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
strcpy(record->commandline, "ethtool -w");
record->total_segments = cpu_to_le32(total_segs);
sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor);
if (sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor) != 2)
netdev_warn(bp->dev, "Unknown OS release in coredump\n");
record->os_ver_major = cpu_to_le32(os_ver_major);
record->os_ver_minor = cpu_to_le32(os_ver_minor);
strlcpy(record->os_name, utsname()->sysname, 32);
strscpy(record->os_name, utsname()->sysname, sizeof(record->os_name));
time64_to_tm(end, 0, &tm);
record->end_year = cpu_to_le16(tm.tm_year + 1900);
record->end_month = cpu_to_le16(tm.tm_mon + 1);
......@@ -3842,7 +3843,7 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
record->ioctl_high_version = 0;
}
static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len)
static int __bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len)
{
u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output);
u32 offset = 0, seg_hdr_len, seg_record_len, buf_len = 0;
......@@ -3945,6 +3946,30 @@ static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len)
return rc;
}
static int bnxt_get_coredump(struct bnxt *bp, u16 dump_type, void *buf, u32 *dump_len)
{
if (dump_type == BNXT_DUMP_CRASH) {
#ifdef CONFIG_TEE_BNXT_FW
return tee_bnxt_copy_coredump(buf, 0, *dump_len);
#else
return -EOPNOTSUPP;
#endif
} else {
return __bnxt_get_coredump(bp, buf, dump_len);
}
}
static u32 bnxt_get_coredump_length(struct bnxt *bp, u16 dump_type)
{
u32 len = 0;
if (dump_type == BNXT_DUMP_CRASH)
len = BNXT_CRASH_DUMP_LEN;
else
__bnxt_get_coredump(bp, NULL, &len);
return len;
}
static int bnxt_set_dump(struct net_device *dev, struct ethtool_dump *dump)
{
struct bnxt *bp = netdev_priv(dev);
......@@ -3976,10 +4001,7 @@ static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump)
bp->ver_resp.hwrm_fw_rsvd_8b;
dump->flag = bp->dump_flag;
if (bp->dump_flag == BNXT_DUMP_CRASH)
dump->len = BNXT_CRASH_DUMP_LEN;
else
bnxt_get_coredump(bp, NULL, &dump->len);
dump->len = bnxt_get_coredump_length(bp, bp->dump_flag);
return 0;
}
......@@ -3994,15 +4016,7 @@ static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump,
memset(buf, 0, dump->len);
dump->flag = bp->dump_flag;
if (dump->flag == BNXT_DUMP_CRASH) {
#ifdef CONFIG_TEE_BNXT_FW
return tee_bnxt_copy_coredump(buf, 0, dump->len);
#endif
} else {
return bnxt_get_coredump(bp, buf, &dump->len);
}
return 0;
return bnxt_get_coredump(bp, dump->flag, buf, &dump->len);
}
static int bnxt_get_ts_info(struct net_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment