[PATCH] PCI: dwc: Fix signedness bug in fault injection test code

Dan Carpenter posted 1 patch 1 month ago
drivers/pci/controller/dwc/pcie-designware-debugfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
[PATCH] PCI: dwc: Fix signedness bug in fault injection test code
Posted by Dan Carpenter 1 month ago
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
Re: [PATCH] PCI: dwc: Fix signedness bug in fault injection test code
Posted by Manivannan Sadhasivam 3 weeks, 3 days ago
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,
-- 
Manivannan Sadhasivam <mani@kernel.org>
Re: [PATCH] PCI: dwc: Fix signedness bug in fault injection test code
Posted by Hans Zhang 1 month ago

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