[PATCH] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value

Hans Zhang posted 1 patch 2 days, 6 hours ago
.../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
[PATCH] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value
Posted by Hans Zhang 2 days, 6 hours ago
kstrtou32_from_user() returns int, but the return value was stored in
a u32 variable 'val', risking sign loss. Use a dedicated int variable
to correctly handle the return code.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
index 0d1340c9b364..9461be074490 100644
--- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c
+++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
@@ -208,10 +208,11 @@ static ssize_t lane_detect_write(struct file *file, const char __user *buf,
 	struct dw_pcie *pci = file->private_data;
 	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
 	u32 lane, val;
+	int ret;
 
-	val = kstrtou32_from_user(buf, count, 0, &lane);
-	if (val)
-		return val;
+	ret = kstrtou32_from_user(buf, count, 0, &lane);
+	if (ret)
+		return ret;
 
 	val = dw_pcie_readl_dbi(pci, rinfo->ras_cap_offset + SD_STATUS_L1LANE_REG);
 	val &= ~(LANE_SELECT);
@@ -347,10 +348,11 @@ static ssize_t counter_enable_write(struct file *file, const char __user *buf,
 	struct dw_pcie *pci = pdata->pci;
 	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
 	u32 val, enable;
+	int ret;
 
-	val = kstrtou32_from_user(buf, count, 0, &enable);
-	if (val)
-		return val;
+	ret = kstrtou32_from_user(buf, count, 0, &enable);
+	if (ret)
+		return ret;
 
 	mutex_lock(&rinfo->reg_event_lock);
 	set_event_number(pdata, pci, rinfo);
@@ -408,10 +410,11 @@ static ssize_t counter_lane_write(struct file *file, const char __user *buf,
 	struct dw_pcie *pci = pdata->pci;
 	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
 	u32 val, lane;
+	int ret;
 
-	val = kstrtou32_from_user(buf, count, 0, &lane);
-	if (val)
-		return val;
+	ret = kstrtou32_from_user(buf, count, 0, &lane);
+	if (ret)
+		return ret;
 
 	mutex_lock(&rinfo->reg_event_lock);
 	set_event_number(pdata, pci, rinfo);

base-commit: 9147566d801602c9e7fc7f85e989735735bf38ba
-- 
2.34.1
Re: [PATCH] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value
Posted by Manivannan Sadhasivam 15 hours ago
On Wed, 01 Apr 2026 10:30:48 +0800, Hans Zhang wrote:
> kstrtou32_from_user() returns int, but the return value was stored in
> a u32 variable 'val', risking sign loss. Use a dedicated int variable
> to correctly handle the return code.

Applied, thanks!

[1/1] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value
      commit: 445588a3b18bb0702d746cb61f7a443639027651

Best regards,
-- 
Manivannan Sadhasivam <mani@kernel.org>
Re: [PATCH] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value
Posted by Manivannan Sadhasivam 1 day, 20 hours ago
On Wed, Apr 01, 2026 at 10:30:48AM +0800, Hans Zhang wrote:
> kstrtou32_from_user() returns int, but the return value was stored in
> a u32 variable 'val', risking sign loss. Use a dedicated int variable
> to correctly handle the return code.
> 
> Signed-off-by: Hans Zhang <18255117159@163.com>

Can you add Fixes tag also?

- Mani

> ---
>  .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> index 0d1340c9b364..9461be074490 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> @@ -208,10 +208,11 @@ static ssize_t lane_detect_write(struct file *file, const char __user *buf,
>  	struct dw_pcie *pci = file->private_data;
>  	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>  	u32 lane, val;
> +	int ret;
>  
> -	val = kstrtou32_from_user(buf, count, 0, &lane);
> -	if (val)
> -		return val;
> +	ret = kstrtou32_from_user(buf, count, 0, &lane);
> +	if (ret)
> +		return ret;
>  
>  	val = dw_pcie_readl_dbi(pci, rinfo->ras_cap_offset + SD_STATUS_L1LANE_REG);
>  	val &= ~(LANE_SELECT);
> @@ -347,10 +348,11 @@ static ssize_t counter_enable_write(struct file *file, const char __user *buf,
>  	struct dw_pcie *pci = pdata->pci;
>  	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>  	u32 val, enable;
> +	int ret;
>  
> -	val = kstrtou32_from_user(buf, count, 0, &enable);
> -	if (val)
> -		return val;
> +	ret = kstrtou32_from_user(buf, count, 0, &enable);
> +	if (ret)
> +		return ret;
>  
>  	mutex_lock(&rinfo->reg_event_lock);
>  	set_event_number(pdata, pci, rinfo);
> @@ -408,10 +410,11 @@ static ssize_t counter_lane_write(struct file *file, const char __user *buf,
>  	struct dw_pcie *pci = pdata->pci;
>  	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>  	u32 val, lane;
> +	int ret;
>  
> -	val = kstrtou32_from_user(buf, count, 0, &lane);
> -	if (val)
> -		return val;
> +	ret = kstrtou32_from_user(buf, count, 0, &lane);
> +	if (ret)
> +		return ret;
>  
>  	mutex_lock(&rinfo->reg_event_lock);
>  	set_event_number(pdata, pci, rinfo);
> 
> base-commit: 9147566d801602c9e7fc7f85e989735735bf38ba
> -- 
> 2.34.1
> 

-- 
மணிவண்ணன் சதாசிவம்
Re: [PATCH] PCI: dwc: Fix type mismatch for kstrtou32_from_user return value
Posted by Hans Zhang 1 day, 18 hours ago

On 4/1/26 20:27, Manivannan Sadhasivam wrote:
> On Wed, Apr 01, 2026 at 10:30:48AM +0800, Hans Zhang wrote:
>> kstrtou32_from_user() returns int, but the return value was stored in
>> a u32 variable 'val', risking sign loss. Use a dedicated int variable
>> to correctly handle the return code.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
> 
> Can you add Fixes tag also?
> 

Hi Mani,

Sorry, below is the "Fixes" tag that I found. Could it be that you added 
it when receiving the patch? Or do I need to send the v2 version?

Fixes: 4fbfa17f9a07 ("PCI: dwc: Add debugfs based Silicon Debug support 
for DWC")


Best regards,
Hans

> - Mani
> 
>> ---
>>   .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
>>   1 file changed, 12 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
>> index 0d1340c9b364..9461be074490 100644
>> --- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c
>> +++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c
>> @@ -208,10 +208,11 @@ static ssize_t lane_detect_write(struct file *file, const char __user *buf,
>>   	struct dw_pcie *pci = file->private_data;
>>   	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>>   	u32 lane, val;
>> +	int ret;
>>   
>> -	val = kstrtou32_from_user(buf, count, 0, &lane);
>> -	if (val)
>> -		return val;
>> +	ret = kstrtou32_from_user(buf, count, 0, &lane);
>> +	if (ret)
>> +		return ret;
>>   
>>   	val = dw_pcie_readl_dbi(pci, rinfo->ras_cap_offset + SD_STATUS_L1LANE_REG);
>>   	val &= ~(LANE_SELECT);
>> @@ -347,10 +348,11 @@ static ssize_t counter_enable_write(struct file *file, const char __user *buf,
>>   	struct dw_pcie *pci = pdata->pci;
>>   	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>>   	u32 val, enable;
>> +	int ret;
>>   
>> -	val = kstrtou32_from_user(buf, count, 0, &enable);
>> -	if (val)
>> -		return val;
>> +	ret = kstrtou32_from_user(buf, count, 0, &enable);
>> +	if (ret)
>> +		return ret;
>>   
>>   	mutex_lock(&rinfo->reg_event_lock);
>>   	set_event_number(pdata, pci, rinfo);
>> @@ -408,10 +410,11 @@ static ssize_t counter_lane_write(struct file *file, const char __user *buf,
>>   	struct dw_pcie *pci = pdata->pci;
>>   	struct dwc_pcie_rasdes_info *rinfo = pci->debugfs->rasdes_info;
>>   	u32 val, lane;
>> +	int ret;
>>   
>> -	val = kstrtou32_from_user(buf, count, 0, &lane);
>> -	if (val)
>> -		return val;
>> +	ret = kstrtou32_from_user(buf, count, 0, &lane);
>> +	if (ret)
>> +		return ret;
>>   
>>   	mutex_lock(&rinfo->reg_event_lock);
>>   	set_event_number(pdata, pci, rinfo);
>>
>> base-commit: 9147566d801602c9e7fc7f85e989735735bf38ba
>> -- 
>> 2.34.1
>>
>