Skip to contentSkip to conversation

usb: dwc3: qcom: simplify error check in dwc3_qcom_find_num_ports()

PATCH In review Zeeshan Ahmad 3 participants 10 messages Feb 18 – Feb 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: qcom: simplify error check in dwc3_qcom_find_num_ports()

The platform_get_irq_byname_optional() function returns a non-zero IRQ number on success and a negative error code on failure. It never returns zero.

The current implementation checks for a return value less than or equal to zero. Since zero is not a valid return value, simplify the check to only look for negative error codes.

---
 drivers/usb/dwc3/dwc3-qcom-legacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom-legacy.c +2 -2
index d3fad0fcfdac..34c578309802 100644
@@ -620,14 +620,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 37 lines · Zeeshan Ahmad

The platform_get_irq_byname_optional() function returns a non-zero IRQ number on success and a negative error code on failure. It never returns zero.

The current implementation checks for a return value less than or equal to zero. Since zero is not a valid return value, simplify the check to only look for negative error codes.

---
 drivers/usb/dwc3/dwc3-qcom-legacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom-legacy.c +2 -2
index d3fad0fcfdac..34c578309802 100644
@@ -620,14 +620,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Signature · 1 line
2.43.0

Since this is not a fix, I prefer new development to be on the dwc3-qcom and not the dwc3-qcom-legacy glue.

Thanks,
Thinh

#2 lore raw
Quoted 22 lines · Thinh Nguyen
Quoted 21 lines · Zeeshan Ahmad
drivers/usb/dwc3/dwc3-qcom-legacy.c +2 -2
index d3fad0fcfdac..34c578309802 100644
@@ -620,14 +620,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Quoted 6 lines
Quoted 3 lines
Signature · 1 line
2.43.0

Since this is not a fix, I prefer new development to be on the dwc3-qcom and not the dwc3-qcom-legacy glue.

There might be some static checker warnings for these? Smatch only warns if people do an explicit zero check since platform_get_irq_byname_optional() can never return zero.

regards,
dan carpenter

#3 lore raw

Hi Dan,

You are correct. I ran Smatch on dwc3-qcom-legacy.c and it did not produce a warning for these lines. I identified this issue through a manual grep search for the pattern 'platform_get_irq.* <= 0' across the drivers directory.

It appears there are several dozen instances of this pattern that Smatch currently misses because the '<= 0' check includes a valid negative error check alongside the redundant zero check.

Thank you for the technical background on why Smatch handles it this way.

Regards,
Zeeshan

maintainer
#4 lore raw
In reply to Dan Carpenter
Quoted 30 lines · Dan Carpenter
Quoted 22 lines · Thinh Nguyen
Quoted 21 lines · Zeeshan Ahmad
drivers/usb/dwc3/dwc3-qcom-legacy.c +2 -2
index d3fad0fcfdac..34c578309802 100644
@@ -620,14 +620,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Quoted 6 lines
Quoted 3 lines
Signature · 1 line
2.43.0

Since this is not a fix, I prefer new development to be on the dwc3-qcom and not the dwc3-qcom-legacy glue.

Quoted 4 lines

There might be some static checker warnings for these? Smatch only warns if people do an explicit zero check since platform_get_irq_byname_optional() can never return zero.

But that aside, since this is new development rather than a fix, I'd prefer to see it go into dwc3-qcom instead of the legacy driver. We should be pushing new features to the main driver to keep things consolidated and encourage people to migrate away from the legacy code.

BR,
Thinh

#5 lore raw

Hi Thinh,

Thank you for the suggestion. I have audited the modern drivers/usb/dwc3/dwc3-qcom.c driver on the latest usb-next branch and confirmed that it contains the same redundant IRQ error checks.

I will drop the previous patch for the legacy driver and submit a new patch targeting the main dwc3-qcom driver shortly.

Regards,
Zeeshan

maintainer
#6 lore raw
Quoted 9 lines · Zeeshan Ahmad

Hi Thinh,

Thank you for the suggestion. I have audited the modern drivers/usb/dwc3/dwc3-qcom.c driver on the latest usb-next branch and confirmed that it contains the same redundant IRQ error checks.

I will drop the previous patch for the legacy driver and submit a new patch targeting the main dwc3-qcom driver shortly.

Hi Zeeshan,

Sure. Could you also keep some relevant context from the previous email thread in your reply? This will help us follow the conversation more easily.

Thanks,
Thinh

#7 lore raw

PATCH v2 1/1 usb: dwc3: qcom: simplify error check in dwc3_qcom_find_num_ports()

The platform_get_irq_byname_optional() function returns a non-zero IRQ number on success and a negative error code on failure. It never returns zero.

The current implementation in the modern dwc3-qcom driver checks for a return value less than or equal to zero. Since zero is not a valid return value, simplify the check to only look for negative error codes. This aligns the logic with the standard return contract of the platform IRQ APIs.

---
 drivers/usb/dwc3/dwc3-qcom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +2 -2
index 9ac75547820d..f43f73ac36ff 100644
@@ -526,14 +526,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 1/1 usb: dwc3: qcom: simplify error check in dwc3_qcom_find_num_ports()

The platform_get_irq_byname_optional() function returns a non-zero IRQ number on success and a negative error code on failure. It never returns zero.

The current implementation in the modern dwc3-qcom driver checks for a return value less than or equal to zero. Since zero is not a valid return value, simplify the check to only look for negative error codes. This aligns the logic with the standard return contract of the platform IRQ APIs.

---
v3:
- Fix missing version changelog in the v2 submission.
v2:
- Targeted the modern dwc3-qcom.c driver instead of the legacy one as suggested by Thinh Nguyen.
- Audited the modern driver to confirm the same redundant error check exists there.
- Updated the commit message to specifically mention the modern dwc3-qcom driver.

 drivers/usb/dwc3/dwc3-qcom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +2 -2
index 9ac75547820d..f43f73ac36ff 100644
@@ -526,14 +526,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Signature · 1 line
2.43.0
maintainer Acked-by on v3 1/1
#9 lore raw
Quoted 49 lines · Zeeshan Ahmad

The platform_get_irq_byname_optional() function returns a non-zero IRQ number on success and a negative error code on failure. It never returns zero.

The current implementation in the modern dwc3-qcom driver checks for a return value less than or equal to zero. Since zero is not a valid return value, simplify the check to only look for negative error codes. This aligns the logic with the standard return contract of the platform IRQ APIs.

---
v3:
- Fix missing version changelog in the v2 submission.
v2:
- Targeted the modern dwc3-qcom.c driver instead of the legacy one as suggested by Thinh Nguyen.
- Audited the modern driver to confirm the same redundant error check exists there.
- Updated the commit message to specifically mention the modern dwc3-qcom driver.

 drivers/usb/dwc3/dwc3-qcom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +2 -2
index 9ac75547820d..f43f73ac36ff 100644
@@ -526,14 +526,14 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev)
 	int irq;
 
 	irq = platform_get_irq_byname_optional(pdev, "dp_hs_phy_1");
-	if (irq <= 0)
+	if (irq < 0)
 		return 1;
 
 	for (port_num = 2; port_num <= DWC3_QCOM_MAX_PORTS; port_num++) {
 		sprintf(irq_name, "dp_hs_phy_%d", port_num);
 
 		irq = platform_get_irq_byname_optional(pdev, irq_name);
-		if (irq <= 0)
+		if (irq < 0)
 			return port_num - 1;
 	}
 
Signature · 1 line
2.43.0

BR,
Thinh