Skip to contentSkip to conversation

PCI: dwc: Fix type mismatch for kstrtou32_from_user return value

PATCH Applied Hans Zhang 3 participants 4 messages Apr 1 – Apr 2

Subsystems (3)
lore
Share & tools
lore

Hans Zhang

author
#0 lore raw

PATCH 1/1 PCI: dwc: Fix type mismatch for kstrtou32_from_user return value

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.

---
 .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +12 -9
index 0d1340c9b364..9461be074490 100644
@@ -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

Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Hans Zhang

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.

Can you add Fixes tag also?

- Mani

Quoted 58 lines
---
 .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +12 -9
index 0d1340c9b364..9461be074490 100644
@@ -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

Signature · 1 line
2.34.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#2 lore raw
Quoted 9 lines · Manivannan Sadhasivam
Quoted 5 lines · Hans Zhang

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.

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

Quoted 61 lines

- Mani

Quoted 58 lines
---
  .../controller/dwc/pcie-designware-debugfs.c  | 21 +++++++++++--------
  1 file changed, 12 insertions(+), 9 deletions(-)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +12 -9
index 0d1340c9b364..9461be074490 100644
@@ -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

Signature · 1 line
2.34.1
#3 lore raw
In reply to Hans Zhang
Quoted 3 lines · Hans Zhang

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,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>