Skip to contentSkip to conversation

NFC: st21nfca: fix error handling of irq_of_parse_and_map

PATCH In review Dmitry Torokhov 2 participants 2 messages Nov 14, 2014 – Nov 15, 2014 NFC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFC: st21nfca: fix error handling of irq_of_parse_and_map

Return value of irq_of_parse_and_map() is unsigned int, with 0 indicating failure, so testing for negative result never works.

Also report error returned by devm_gpio_request_one instead of clobbering it with -ENODEV.

---
 drivers/nfc/st21nfca/i2c.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/nfc/st21nfca/i2c.c +5 -6
index 0ea756b..6d6d282 100644
@@ -531,20 +531,19 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
 				  "clf_enable");
 	if (r) {
 		nfc_err(&client->dev, "Failed to request enable pin\n");
-		return -ENODEV;
+		return r;
 	}
 
 	phy->gpio_ena = gpio;
 
 	/* IRQ */
-	r = irq_of_parse_and_map(pp, 0);
-	if (r < 0) {
-		nfc_err(&client->dev, "Unable to get irq, error: %d\n", r);
-		return r;
+	client->irq = irq_of_parse_and_map(pp, 0);
+	if (!client->irq) {
+		nfc_err(&client->dev, "Unable to get irq\n");
+		return -EINVAL;
 	}
 
 	phy->irq_polarity = irq_get_trigger_type(r);
-	client->irq = r;
 
 	return 0;
 }
Signature · 5 lines
2.1.0.rc2.206.gedb03e5


-- 
Dmitry
#1 lore raw

Hi Dmitry,

Thank you for your feedback.
A patch got already pushed earlier this month:
https://lists.01.org/pipermail/linux-nfc/2014-November/003123.html

The i2c-core is already running the i2c_of_parse_and_map function when registering the slave device when using dts. This step got removed for this reason.

However, i will take into account your second point in order to report devm_gpio_request_one instead of -ENODEV in a future patchset.

Best Regards
Christophe

Quoted 43 lines · On Fri, 14 Nov 2014 14:32:24 -0800 Dmitry Torokhov <[email protected]> wrote:

Return value of irq_of_parse_and_map() is unsigned int, with 0 indicating failure, so testing for negative result never works.

Also report error returned by devm_gpio_request_one instead of clobbering it with -ENODEV.

---
 drivers/nfc/st21nfca/i2c.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/nfc/st21nfca/i2c.c +5 -6
index 0ea756b..6d6d282 100644
@@ -531,20 +531,19 @@ static int
 st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
 "clf_enable"); if (r) {
 		nfc_err(&client->dev, "Failed to request enable
 pin\n");
-		return -ENODEV;
+		return r;
 	}
 
 	phy->gpio_ena = gpio;
 
 	/* IRQ */
-	r = irq_of_parse_and_map(pp, 0);
-	if (r < 0) {
-		nfc_err(&client->dev, "Unable to get irq, error:
 %d\n", r);
-		return r;
+	client->irq = irq_of_parse_and_map(pp, 0);
+	if (!client->irq) {
+		nfc_err(&client->dev, "Unable to get irq\n");
+		return -EINVAL;
 	}
 
 	phy->irq_polarity = irq_get_trigger_type(r);
-	client->irq = r;
 

return 0;
}