The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] PCI: dwc: Fix signedness bug in fault injection test code
@ 2026-05-12 10:17 Dan Carpenter
  2026-05-12 10:40 ` Hans Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2026-05-12 10:17 UTC (permalink / raw)
  To: Shradha Todi
  Cc: Jingoo Han, Manivannan Sadhasivam, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas, Fan Ni,
	linux-pci, linux-kernel, kernel-janitors

The kstrtou32() function returns negative error code or zero on success.
However, in this case "val" is a u32 and the function returns signed
longs so negative error codes from kstrtou32() are returned as high
positive values.

Store the error code in an int instead.

Fixes: d20ee8e2dbd6 ("PCI: dwc: Add debugfs based Error Injection support for DWC")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/pci/controller/dwc/pcie-designware-debugfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
index 945f8f9b6d0e..a6737bdc46ac 100644
--- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c
+++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
@@ -305,6 +305,7 @@ static ssize_t err_inj_write(struct file *file, const char __user *buf,
 	u32 val, counter, vc_num, err_group, type_mask;
 	int val_diff = 0;
 	char *kern_buf;
+	int ret;
 
 	err_group = err_inj_list[pdata->idx].err_inj_group;
 	type_mask = err_inj_type_mask[err_group];
@@ -326,10 +327,10 @@ static ssize_t err_inj_write(struct file *file, const char __user *buf,
 			return -EINVAL;
 		}
 	} else {
-		val = kstrtou32(kern_buf, 0, &counter);
-		if (val) {
+		ret = kstrtou32(kern_buf, 0, &counter);
+		if (ret) {
 			kfree(kern_buf);
-			return val;
+			return ret;
 		}
 	}
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-12 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 10:17 [PATCH] PCI: dwc: Fix signedness bug in fault injection test code Dan Carpenter
2026-05-12 10:40 ` Hans Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox