| Message ID | agL-Uwfn26SI4Gb0@stanley.mountain |
|---|---|
| State | New |
| Headers | show |
| Series | PCI: dwc: Fix signedness bug in fault injection test code | expand |
On 5/12/26 18:17, Dan Carpenter wrote: > 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> Reviewed-by: Hans Zhang <18255117159@163.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; > } > } >
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Register accesses without ensuring active power state (missing pm_runtime). -- commit 4899a9300a95dd54caf44bf07153849d88f68ae7 Author: Dan Carpenter <error27@gmail.com> PCI: dwc: Fix signedness bug in fault injection test code This commit fixes a signedness bug in the fault injection debugfs handler. It ensures that negative error codes from kstrtou32 are properly handled by storing the return value in an int instead of a u32. > diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c > index d0884253be97e..4bfc1748f2d73 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c > +++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c [ ... ] > @@ -327,10 +328,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; > } > } This isn't a regression introduced by this commit, but is it safe to access the hardware registers immediately after this block without ensuring the device is in an active power state? This function handles user writes to debugfs, which can happen at any time. If the PCIe controller is runtime-suspended, accessing its memory-mapped registers via dw_pcie_readl_dbi() might cause a bus hang or kernel panic. Would it make sense to call pm_runtime_get_sync() before interacting with the hardware registers later in this function?
On Tue, 12 May 2026 13:17:55 +0300, Dan Carpenter wrote: > 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. > > [...] Applied, thanks! [1/1] PCI: dwc: Fix signedness bug in fault injection test code commit: 94ac934d2c054fba4a22d8dc84749094c5fa0ec0 Best regards,
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; } }
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(-)