Commit 1dab5877 authored by Luo bin's avatar Luo bin Committed by David S. Miller

hinic: fix strncpy output truncated compile warnings

fix the compile warnings of 'strncpy' output truncated before
terminating nul copying N bytes from a string of the same length
Signed-off-by: default avatarLuo bin <luobin9@huawei.com>
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c79f428d
...@@ -334,19 +334,14 @@ void hinic_devlink_unregister(struct hinic_devlink_priv *priv) ...@@ -334,19 +334,14 @@ void hinic_devlink_unregister(struct hinic_devlink_priv *priv)
static int chip_fault_show(struct devlink_fmsg *fmsg, static int chip_fault_show(struct devlink_fmsg *fmsg,
struct hinic_fault_event *event) struct hinic_fault_event *event)
{ {
char fault_level[FAULT_TYPE_MAX][FAULT_SHOW_STR_LEN + 1] = { const char * const level_str[FAULT_LEVEL_MAX + 1] = {
"fatal", "reset", "flr", "general", "suggestion"}; "fatal", "reset", "flr", "general", "suggestion", "Unknown"};
char level_str[FAULT_SHOW_STR_LEN + 1] = {0}; u8 fault_level;
u8 level;
int err; int err;
level = event->event.chip.err_level; fault_level = (event->event.chip.err_level < FAULT_LEVEL_MAX) ?
if (level < FAULT_LEVEL_MAX) event->event.chip.err_level : FAULT_LEVEL_MAX;
strncpy(level_str, fault_level[level], strlen(fault_level[level])); if (fault_level == FAULT_LEVEL_SERIOUS_FLR) {
else
strncpy(level_str, "Unknown", strlen("Unknown"));
if (level == FAULT_LEVEL_SERIOUS_FLR) {
err = devlink_fmsg_u32_pair_put(fmsg, "Function level err func_id", err = devlink_fmsg_u32_pair_put(fmsg, "Function level err func_id",
(u32)event->event.chip.func_id); (u32)event->event.chip.func_id);
if (err) if (err)
...@@ -361,7 +356,7 @@ static int chip_fault_show(struct devlink_fmsg *fmsg, ...@@ -361,7 +356,7 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
if (err) if (err)
return err; return err;
err = devlink_fmsg_string_pair_put(fmsg, "err_level", level_str); err = devlink_fmsg_string_pair_put(fmsg, "err_level", level_str[fault_level]);
if (err) if (err)
return err; return err;
...@@ -381,18 +376,15 @@ static int chip_fault_show(struct devlink_fmsg *fmsg, ...@@ -381,18 +376,15 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
static int fault_report_show(struct devlink_fmsg *fmsg, static int fault_report_show(struct devlink_fmsg *fmsg,
struct hinic_fault_event *event) struct hinic_fault_event *event)
{ {
char fault_type[FAULT_TYPE_MAX][FAULT_SHOW_STR_LEN + 1] = { const char * const type_str[FAULT_TYPE_MAX + 1] = {
"chip", "ucode", "mem rd timeout", "mem wr timeout", "chip", "ucode", "mem rd timeout", "mem wr timeout",
"reg rd timeout", "reg wr timeout", "phy fault"}; "reg rd timeout", "reg wr timeout", "phy fault", "Unknown"};
char type_str[FAULT_SHOW_STR_LEN + 1] = {0}; u8 fault_type;
int err; int err;
if (event->type < FAULT_TYPE_MAX) fault_type = (event->type < FAULT_TYPE_MAX) ? event->type : FAULT_TYPE_MAX;
strncpy(type_str, fault_type[event->type], strlen(fault_type[event->type]));
else
strncpy(type_str, "Unknown", strlen("Unknown"));
err = devlink_fmsg_string_pair_put(fmsg, "Fault type", type_str); err = devlink_fmsg_string_pair_put(fmsg, "Fault type", type_str[fault_type]);
if (err) if (err)
return err; return err;
......
...@@ -504,8 +504,6 @@ enum hinic_fault_type { ...@@ -504,8 +504,6 @@ enum hinic_fault_type {
FAULT_TYPE_MAX, FAULT_TYPE_MAX,
}; };
#define FAULT_SHOW_STR_LEN 16
enum hinic_fault_err_level { enum hinic_fault_err_level {
FAULT_LEVEL_FATAL, FAULT_LEVEL_FATAL,
FAULT_LEVEL_SERIOUS_RESET, FAULT_LEVEL_SERIOUS_RESET,
......
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