Skip to content

Commit 1dab587

Browse files
Luo bindavem330
authored andcommitted
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: Luo bin <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c79f428 commit 1dab587

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

drivers/net/ethernet/huawei/hinic/hinic_devlink.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,14 @@ void hinic_devlink_unregister(struct hinic_devlink_priv *priv)
334334
static int chip_fault_show(struct devlink_fmsg *fmsg,
335335
struct hinic_fault_event *event)
336336
{
337-
char fault_level[FAULT_TYPE_MAX][FAULT_SHOW_STR_LEN + 1] = {
338-
"fatal", "reset", "flr", "general", "suggestion"};
339-
char level_str[FAULT_SHOW_STR_LEN + 1] = {0};
340-
u8 level;
337+
const char * const level_str[FAULT_LEVEL_MAX + 1] = {
338+
"fatal", "reset", "flr", "general", "suggestion", "Unknown"};
339+
u8 fault_level;
341340
int err;
342341

343-
level = event->event.chip.err_level;
344-
if (level < FAULT_LEVEL_MAX)
345-
strncpy(level_str, fault_level[level], strlen(fault_level[level]));
346-
else
347-
strncpy(level_str, "Unknown", strlen("Unknown"));
348-
349-
if (level == FAULT_LEVEL_SERIOUS_FLR) {
342+
fault_level = (event->event.chip.err_level < FAULT_LEVEL_MAX) ?
343+
event->event.chip.err_level : FAULT_LEVEL_MAX;
344+
if (fault_level == FAULT_LEVEL_SERIOUS_FLR) {
350345
err = devlink_fmsg_u32_pair_put(fmsg, "Function level err func_id",
351346
(u32)event->event.chip.func_id);
352347
if (err)
@@ -361,7 +356,7 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
361356
if (err)
362357
return err;
363358

364-
err = devlink_fmsg_string_pair_put(fmsg, "err_level", level_str);
359+
err = devlink_fmsg_string_pair_put(fmsg, "err_level", level_str[fault_level]);
365360
if (err)
366361
return err;
367362

@@ -381,18 +376,15 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
381376
static int fault_report_show(struct devlink_fmsg *fmsg,
382377
struct hinic_fault_event *event)
383378
{
384-
char fault_type[FAULT_TYPE_MAX][FAULT_SHOW_STR_LEN + 1] = {
379+
const char * const type_str[FAULT_TYPE_MAX + 1] = {
385380
"chip", "ucode", "mem rd timeout", "mem wr timeout",
386-
"reg rd timeout", "reg wr timeout", "phy fault"};
387-
char type_str[FAULT_SHOW_STR_LEN + 1] = {0};
381+
"reg rd timeout", "reg wr timeout", "phy fault", "Unknown"};
382+
u8 fault_type;
388383
int err;
389384

390-
if (event->type < FAULT_TYPE_MAX)
391-
strncpy(type_str, fault_type[event->type], strlen(fault_type[event->type]));
392-
else
393-
strncpy(type_str, "Unknown", strlen("Unknown"));
385+
fault_type = (event->type < FAULT_TYPE_MAX) ? event->type : FAULT_TYPE_MAX;
394386

395-
err = devlink_fmsg_string_pair_put(fmsg, "Fault type", type_str);
387+
err = devlink_fmsg_string_pair_put(fmsg, "Fault type", type_str[fault_type]);
396388
if (err)
397389
return err;
398390

drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ enum hinic_fault_type {
504504
FAULT_TYPE_MAX,
505505
};
506506

507-
#define FAULT_SHOW_STR_LEN 16
508-
509507
enum hinic_fault_err_level {
510508
FAULT_LEVEL_FATAL,
511509
FAULT_LEVEL_SERIOUS_RESET,

0 commit comments

Comments
 (0)