From eb22d3349954e68ce1f2bd4cb7c8772150cc7b2e Mon Sep 17 00:00:00 2001 From: Haoyi Liu Date: Wed, 10 May 2023 10:06:46 +0800 Subject: [PATCH] scsi/hifc: fix error handling condition incorrect driver inclusion category: bugfix bugzilla: NA CVE: NA Reference: N/A ---------------------------------------------------------------- We use condition 'if (ret < 0)' here for error handling. However, since sscanf returns the number of format string "%d", at sscanf(chip_info->chip_name, HIFC_CHIP_NAME "%d", &id) in line 843, it still fails when ret == 0. Fix this by modify the condition to 'ret < 1'. In addition, Since sscanf returns EOF, instead of an error code, we need to assign appropriate error code to 'ret'. Fix this by assign '-EFAULT' to 'ret' after getting id fails. Signed-off-by: Haoyi Liu --- drivers/scsi/huawei/hifc/hifc_dbgtool_knl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/huawei/hifc/hifc_dbgtool_knl.c b/drivers/scsi/huawei/hifc/hifc_dbgtool_knl.c index 87f0c9fd3965..b42225723deb 100644 --- a/drivers/scsi/huawei/hifc/hifc_dbgtool_knl.c +++ b/drivers/scsi/huawei/hifc/hifc_dbgtool_knl.c @@ -843,8 +843,9 @@ int dbgtool_knl_init(void *vhwdev, void *chip_node) sema_init(&dbgtool_info->dbgtool_sem, 1); ret = sscanf(chip_info->chip_name, HIFC_CHIP_NAME "%d", &id); - if (ret < 0) { + if (ret < 1) { pr_err("Failed to get hifc id\n"); + ret = -EFAULT; goto sscanf_chdev_fail; } -- Gitee