From 11e1054340885f796c9643ee6d212bd2669cd278 Mon Sep 17 00:00:00 2001 From: Ziliang Liao Date: Thu, 11 May 2023 00:03:17 -0700 Subject: [PATCH] net/hinic: reassign the variable ret after sscanf() failure driver inclusion category: other bugzilla: https://gitee.com/openeuler/kernel/issues/I6ZJSQ Reference: N/A --------------------- On line 767 of hinic_dbgtool_knl.c, when the function sscanf() fails, the variable ret will be assigned an integer less than 1. Use 'ret < 1' other than 'ret <= 0' in the 'if' judgment to change to fixed format. And if the judgment is valid, the variable ret should be reassigned an error code, which is -EINVAL in this case, for dbgtool_knl_init() suggests an error code to help find bugs. Signed-off-by: Ziliang Liao --- drivers/net/ethernet/huawei/hinic/hinic_dbgtool_knl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/huawei/hinic/hinic_dbgtool_knl.c b/drivers/net/ethernet/huawei/hinic/hinic_dbgtool_knl.c index ec2928c3db0f..0bc9ff8fd861 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_dbgtool_knl.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_dbgtool_knl.c @@ -765,8 +765,9 @@ int hinic_dbgtool_knl_init(void *vhwdev, void *chip_node) sema_init(&dbgtool_info->dbgtool_sem, 1); ret = sscanf(chip_info->chip_name, HINIC_CHIP_NAME "%d", &id); - if (ret <= 0) { + if (ret < 1) { pr_err("Failed to get hinic id\n"); + ret = -EINVAL; goto sscanf_chdev_fail; } -- Gitee