usb: dwc3: qcom: simplify error check in dwc3_qcom_find_num_ports()
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
@@ -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
Thinh Nguyen
maintainerQuoted 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.
Signed-off-by Zeeshan Ahmad <[email protected]>--- drivers/usb/dwc3/dwc3-qcom-legacy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-qcom-legacy.c +2
-2@@ -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
Quoted 22 lines · Thinh Nguyen
Quoted 21 lines · Zeeshan Ahmad
drivers/usb/dwc3/dwc3-qcom-legacy.c +2
-2@@ -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.0Since 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
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
Thinh Nguyen
maintainerQuoted 30 lines · Dan Carpenter
Quoted 22 lines · Thinh Nguyen
Quoted 21 lines · Zeeshan Ahmad
drivers/usb/dwc3/dwc3-qcom-legacy.c +2
-2@@ -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.0Since 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
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
Thinh Nguyen
maintainerQuoted 9 lines · Zeeshan Ahmad
Hi Thinh,
Thank you for the suggestion. I have audited the modern
drivers/usb/dwc3/dwc3-qcom.cdriver 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
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
@@ -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
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
@@ -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
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.
Signed-off-by Zeeshan Ahmad <[email protected]>---
v3:
- Fix missing version changelog in the v2 submission.
v2:
- Targeted the moderndwc3-qcom.cdriver 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@@ -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