From: Qianfeng Rong rongqianfeng@vivo.com
[ Upstream commit bee3554d1a4efbce91d6eca732f41b97272213a5 ]
Use int instead of u32 for 'ret' variable to store negative error codes returned by PM8001_CHIP_DISP->set_nvmd_req().
Signed-off-by: Qianfeng Rong rongqianfeng@vivo.com Link: https://lore.kernel.org/r/20250826093242.230344-1-rongqianfeng@vivo.com Signed-off-by: Martin K. Petersen martin.petersen@oracle.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- What it fixes - Preserves negative errno from `set_nvmd_req()` by changing `ret` from `u32` to `int` in `pm8001_set_nvmd()`, avoiding silent conversion of negative errors to large positive values. - With `u32`, a failure such as `-ENOMEM` becomes a large positive integer, causing the sysfs store handler to return a non-error positive value instead of `-errno`.
- Where it changes - `drivers/scsi/pm8001/pm8001_ctl.c:685` changes the local variable declaration in `pm8001_set_nvmd()` to `int ret;` (was `u32 ret;` pre-change). - The function body uses `ret` as an error status: - Call site: `ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);` `drivers/scsi/pm8001/pm8001_ctl.c:705` - Error path check: `if (ret) { ... return ret; }` `drivers/scsi/pm8001/pm8001_ctl.c:706-713` - The return is propagated up to the sysfs store handler: - `pm8001_store_update_fw()` returns `ret` directly on error: `drivers/scsi/pm8001/pm8001_ctl.c:863-867`
- Why this matters (callers return negative errors) - `PM8001_CHIP_DISP->set_nvmd_req()` implementation returns negative error codes: - `return -ENOMEM;` and `return -SAS_QUEUE_FULL;` in `pm8001_chip_set_nvmd_req()` at `drivers/scsi/pm8001/pm8001_hwi.c:4468-4479`, with `rc` typed as `int` (`drivers/scsi/pm8001/pm8001_hwi.c:4460`). - Without the type fix, the sysfs store handler may return a positive value on error (misreporting failure as success or as a bogus positive byte count), violating sysfs semantics which require negative errno for errors.
- Scope and risk - Minimal, localized one-line type change in a driver’s firmware/NVMD sysfs path; no API/ABI or architectural changes. - Aligns with kernel conventions: error paths must return negative errno; the fix makes the function signature and return values consistent. - Touches only pm8001 control path, not I/O fast path.
- Stable backport criteria - Fixes an end-user-visible bug (wrong error reporting through sysfs). - Small, self-contained change with negligible regression risk. - No feature addition; strictly a correctness fix. - SCSI maintainer sign-off present.
- File references - drivers/scsi/pm8001/pm8001_ctl.c:680 - drivers/scsi/pm8001/pm8001_ctl.c:685 - drivers/scsi/pm8001/pm8001_ctl.c:705 - drivers/scsi/pm8001/pm8001_ctl.c:863 - drivers/scsi/pm8001/pm8001_hwi.c:4460 - drivers/scsi/pm8001/pm8001_hwi.c:4468 - drivers/scsi/pm8001/pm8001_hwi.c:4479
Given the clear correctness improvement, minimal risk, and user-facing impact on error propagation, this is a good candidate for stable backport.
drivers/scsi/pm8001/pm8001_ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c index 0c96875cf8fd1..cbfda8c04e956 100644 --- a/drivers/scsi/pm8001/pm8001_ctl.c +++ b/drivers/scsi/pm8001/pm8001_ctl.c @@ -682,7 +682,7 @@ static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha) struct pm8001_ioctl_payload *payload; DECLARE_COMPLETION_ONSTACK(completion); u8 *ioctlbuffer; - u32 ret; + int ret; u32 length = 1024 * 5 + sizeof(*payload) - 1;
if (pm8001_ha->fw_image->size > 4096) {