Linux PCI subsystem development
 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
  2026-05-13 20:19 ` sashiko-bot
  0 siblings, 2 replies; 3+ 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] 3+ messages in thread

* Re: [PATCH] PCI: dwc: Fix signedness bug in fault injection test code
  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
  2026-05-13 20:19 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Hans Zhang @ 2026-05-12 10:40 UTC (permalink / raw)
  To: Dan Carpenter, Shradha Todi
  Cc: Jingoo Han, Manivannan Sadhasivam, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas, Fan Ni,
	linux-pci, linux-kernel, kernel-janitors



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;
>   		}
>   	}
>   


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

* Re: [PATCH] PCI: dwc: Fix signedness bug in fault injection test code
  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
@ 2026-05-13 20:19 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-05-13 20:19 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-pci

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?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/agL-Uwfn26SI4Gb0@stanley.mountain?part=1

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

end of thread, other threads:[~2026-05-13 20:19 UTC | newest]

Thread overview: 3+ 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
2026-05-13 20:19 ` sashiko-bot

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