Skip to contentSkip to conversation

usb: gadget/snps_udc_plat: Fix a signedness bug in probe

PATCH In review Dan Carpenter 2 participants 3 messages Jun 6, 2023

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

PATCH 1/1 usb: gadget/snps_udc_plat: Fix a signedness bug in probe

The irq_of_parse_and_map() function returns negative error codes but "udc->irq" is an unsigned int so the error handling doesn't work.

Fixes 1b9f35adb0ff ("usb: gadget: udc: Add Synopsys UDC Platform driver")
---
 drivers/usb/gadget/udc/snps_udc_plat.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/snps_udc_plat.c +4 -3
index 0ed685db149d..37edd6c35077 100644
@@ -103,7 +103,7 @@ static int udc_plat_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct resource *res;
 	struct udc *udc;
-	int ret;
+	int irq, ret;
 
 	udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL);
 	if (!udc)
@@ -132,11 +132,12 @@ static int udc_plat_probe(struct platform_device *pdev)
 
 	udc->phys_addr = (unsigned long)res->start;
 
-	udc->irq = irq_of_parse_and_map(dev->of_node, 0);
-	if (udc->irq <= 0) {
+	irq = irq_of_parse_and_map(dev->of_node, 0);
+	if (irq <= 0) {
 		dev_err(dev, "Can't parse and map interrupt\n");
 		return -EINVAL;
 	}
+	udc->irq = irq;
 
 	udc->udc_phy = devm_of_phy_get_by_index(dev, dev->of_node, 0);
 	if (IS_ERR(udc->udc_phy)) {
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The irq_of_parse_and_map() function returns negative error codes but "udc->irq" is an unsigned int so the error handling doesn't work.

Fixes 1b9f35adb0ff ("usb: gadget: udc: Add Synopsys UDC Platform driver")

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#2 lore raw
In reply to Dan Carpenter
Quoted 23 lines · Dan Carpenter

The irq_of_parse_and_map() function returns negative error codes but "udc->irq" is an unsigned int so the error handling doesn't work.

Fixes 1b9f35adb0ff ("usb: gadget: udc: Add Synopsys UDC Platform driver")
---
 drivers/usb/gadget/udc/snps_udc_plat.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/snps_udc_plat.c +1 -1
index 0ed685db149d..37edd6c35077 100644
@@ -103,7 +103,7 @@ static int udc_plat_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct resource *res;
 	struct udc *udc;
-	int ret;
+	int irq, ret;
 
 	udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL);
 	if (!udc)

drivers/usb/gadget/udc/snps_udc_plat.c static int udc_plat_probe(struct platform_device *pdev) · line 136

Quoted 7 lines
drivers/usb/gadget/udc/snps_udc_plat.c +2 -2
@@ -132,11 +132,12 @@ static int udc_plat_probe(struct platform_device *pdev)
 
 	udc->phys_addr = (unsigned long)res->start;
 
-	udc->irq = irq_of_parse_and_map(dev->of_node, 0);
-	if (udc->irq <= 0) {
+	irq = irq_of_parse_and_map(dev->of_node, 0);
+	if (irq <= 0) {

Oops. It turns out that irq_of_parse_and_map() returns zero on error, not negatives so this patch isn't needed and probably the correct thing is to change the error check to if (!irq) { instead.

regards,
dan carpenter