All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv()
@ 2022-06-26 19:42 Michael Walle
  2022-06-26 19:42 ` [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read() Michael Walle
  2022-06-26 19:49 ` [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Krzysztof Kozlowski
  0 siblings, 2 replies; 9+ messages in thread
From: Michael Walle @ 2022-06-26 19:42 UTC (permalink / raw)
  To: Charles Gorand, Krzysztof Kozlowski
  Cc: Clément Perrochaud, netdev, linux-kernel, Michael Walle

Check the return code of i2c_master_recv() for actual errors and
propagate it to the caller.

Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nfc/nxp-nci/i2c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
index 7e451c10985d..9c80d5a6d56b 100644
--- a/drivers/nfc/nxp-nci/i2c.c
+++ b/drivers/nfc/nxp-nci/i2c.c
@@ -163,7 +163,10 @@ static int nxp_nci_i2c_nci_read(struct nxp_nci_i2c_phy *phy,
 	skb_put_data(*skb, (void *)&header, NCI_CTRL_HDR_SIZE);
 
 	r = i2c_master_recv(client, skb_put(*skb, header.plen), header.plen);
-	if (r != header.plen) {
+	if (r < 0) {
+		nfc_err(&client->dev, "I2C receive error %pe\n", ERR_PTR(r));
+		goto nci_read_exit_free_skb;
+	} else if (r != header.plen) {
 		nfc_err(&client->dev,
 			"Invalid frame payload length: %u (expected %u)\n",
 			r, header.plen);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-26 19:42 [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Michael Walle
@ 2022-06-26 19:42 ` Michael Walle
  2022-06-26 19:51   ` Krzysztof Kozlowski
  2022-06-28  5:03   ` Jakub Kicinski
  2022-06-26 19:49 ` [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Krzysztof Kozlowski
  1 sibling, 2 replies; 9+ messages in thread
From: Michael Walle @ 2022-06-26 19:42 UTC (permalink / raw)
  To: Charles Gorand, Krzysztof Kozlowski
  Cc: Clément Perrochaud, netdev, linux-kernel, Michael Walle

There are packets which doesn't have a payload. In that case, the second
i2c_master_read() will have a zero length. But because the NFC
controller doesn't have any data left, it will NACK the I2C read and
-ENXIO will be returned. In case there is no payload, just skip the
second i2c master read.

Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nfc/nxp-nci/i2c.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
index 9c80d5a6d56b..c9361b5249b7 100644
--- a/drivers/nfc/nxp-nci/i2c.c
+++ b/drivers/nfc/nxp-nci/i2c.c
@@ -162,6 +162,9 @@ static int nxp_nci_i2c_nci_read(struct nxp_nci_i2c_phy *phy,
 
 	skb_put_data(*skb, (void *)&header, NCI_CTRL_HDR_SIZE);
 
+	if (!header.plen)
+		return 0;
+
 	r = i2c_master_recv(client, skb_put(*skb, header.plen), header.plen);
 	if (r < 0) {
 		nfc_err(&client->dev, "I2C receive error %pe\n", ERR_PTR(r));
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv()
  2022-06-26 19:42 [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Michael Walle
  2022-06-26 19:42 ` [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read() Michael Walle
@ 2022-06-26 19:49 ` Krzysztof Kozlowski
  2022-06-26 19:55   ` Michael Walle
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-26 19:49 UTC (permalink / raw)
  To: Michael Walle, Charles Gorand
  Cc: Clément Perrochaud, netdev, linux-kernel

On 26/06/2022 21:42, Michael Walle wrote:
> Check the return code of i2c_master_recv() for actual errors and
> propagate it to the caller.
> 
> Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")

The check was there, so I don't see here bug. The only thing missing was
a bit more detailed error message (without cast to %u) and propagating
error code instead of EBADMSG, but these are not bugs. The commit msg
should sound different and Fixes tag is not appropriate.

> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/nfc/nxp-nci/i2c.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
> index 7e451c10985d..9c80d5a6d56b 100644
> --- a/drivers/nfc/nxp-nci/i2c.c
> +++ b/drivers/nfc/nxp-nci/i2c.c
> @@ -163,7 +163,10 @@ static int nxp_nci_i2c_nci_read(struct nxp_nci_i2c_phy *phy,
>  	skb_put_data(*skb, (void *)&header, NCI_CTRL_HDR_SIZE);
>  
>  	r = i2c_master_recv(client, skb_put(*skb, header.plen), header.plen);
> -	if (r != header.plen) {
> +	if (r < 0) {
> +		nfc_err(&client->dev, "I2C receive error %pe\n", ERR_PTR(r));

Print just 'r'.

> +		goto nci_read_exit_free_skb;
> +	} else if (r != header.plen) {
>  		nfc_err(&client->dev,
>  			"Invalid frame payload length: %u (expected %u)\n",
>  			r, header.plen);


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-26 19:42 ` [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read() Michael Walle
@ 2022-06-26 19:51   ` Krzysztof Kozlowski
  2022-06-26 19:56     ` Michael Walle
  2022-06-28  5:03   ` Jakub Kicinski
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-26 19:51 UTC (permalink / raw)
  To: Michael Walle, Charles Gorand
  Cc: Clément Perrochaud, netdev, linux-kernel

On 26/06/2022 21:42, Michael Walle wrote:
> There are packets which doesn't have a payload. In that case, the second
> i2c_master_read() will have a zero length. But because the NFC
> controller doesn't have any data left, it will NACK the I2C read and
> -ENXIO will be returned. In case there is no payload, just skip the
> second i2c master read.
> 
> Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")
> Signed-off-by: Michael Walle <michael@walle.cc>

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv()
  2022-06-26 19:49 ` [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Krzysztof Kozlowski
@ 2022-06-26 19:55   ` Michael Walle
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Walle @ 2022-06-26 19:55 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Charles Gorand, Clément Perrochaud, netdev, linux-kernel

Am 2022-06-26 21:49, schrieb Krzysztof Kozlowski:
> On 26/06/2022 21:42, Michael Walle wrote:
>> Check the return code of i2c_master_recv() for actual errors and
>> propagate it to the caller.
>> 
>> Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI 
>> driver")
> 
> The check was there, so I don't see here bug. The only thing missing 
> was
> a bit more detailed error message (without cast to %u) and propagating
> error code instead of EBADMSG, but these are not bugs. The commit msg
> should sound different and Fixes tag is not appropriate.

Well one could argue the nfc_err() is very misleading as it prints
an unreasonable large number. Will remove the Fixes tag and reword
the commit message.

>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  drivers/nfc/nxp-nci/i2c.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
>> index 7e451c10985d..9c80d5a6d56b 100644
>> --- a/drivers/nfc/nxp-nci/i2c.c
>> +++ b/drivers/nfc/nxp-nci/i2c.c
>> @@ -163,7 +163,10 @@ static int nxp_nci_i2c_nci_read(struct 
>> nxp_nci_i2c_phy *phy,
>>  	skb_put_data(*skb, (void *)&header, NCI_CTRL_HDR_SIZE);
>> 
>>  	r = i2c_master_recv(client, skb_put(*skb, header.plen), 
>> header.plen);
>> -	if (r != header.plen) {
>> +	if (r < 0) {
>> +		nfc_err(&client->dev, "I2C receive error %pe\n", ERR_PTR(r));
> 
> Print just 'r'.

Personally, I prefer seeing the actual error string and this idiom is
also used in other drivers. But I wont insist, will change it.

> 
>> +		goto nci_read_exit_free_skb;
>> +	} else if (r != header.plen) {
>>  		nfc_err(&client->dev,
>>  			"Invalid frame payload length: %u (expected %u)\n",
>>  			r, header.plen);
> 
> 
> Best regards,
> Krzysztof

-michael

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-26 19:51   ` Krzysztof Kozlowski
@ 2022-06-26 19:56     ` Michael Walle
  2022-06-26 20:02       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Walle @ 2022-06-26 19:56 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Charles Gorand, Clément Perrochaud, netdev, linux-kernel

Am 2022-06-26 21:51, schrieb Krzysztof Kozlowski:
> On 26/06/2022 21:42, Michael Walle wrote:
>> There are packets which doesn't have a payload. In that case, the 
>> second
>> i2c_master_read() will have a zero length. But because the NFC
>> controller doesn't have any data left, it will NACK the I2C read and
>> -ENXIO will be returned. In case there is no payload, just skip the
>> second i2c master read.
>> 
>> Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI 
>> driver")
>> Signed-off-by: Michael Walle <michael@walle.cc>
> 
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Thanks, I'll reorder the patches in the next version otherwise
there will likely be a conflict. That should work with any patch
tools (i.e. b4), shouldn't it?

-michael

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-26 19:56     ` Michael Walle
@ 2022-06-26 20:02       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-26 20:02 UTC (permalink / raw)
  To: Michael Walle
  Cc: Charles Gorand, Clément Perrochaud, netdev, linux-kernel

On 26/06/2022 21:56, Michael Walle wrote:
> Am 2022-06-26 21:51, schrieb Krzysztof Kozlowski:
>> On 26/06/2022 21:42, Michael Walle wrote:
>>> There are packets which doesn't have a payload. In that case, the 
>>> second
>>> i2c_master_read() will have a zero length. But because the NFC
>>> controller doesn't have any data left, it will NACK the I2C read and
>>> -ENXIO will be returned. In case there is no payload, just skip the
>>> second i2c master read.
>>>
>>> Fixes: 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI 
>>> driver")
>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>
>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> Thanks, I'll reorder the patches in the next version otherwise
> there will likely be a conflict.

Yes.

> That should work with any patch
> tools (i.e. b4), shouldn't it?

You mean - re-ordering should work? Yes, no problem with that.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-26 19:42 ` [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read() Michael Walle
  2022-06-26 19:51   ` Krzysztof Kozlowski
@ 2022-06-28  5:03   ` Jakub Kicinski
  2022-06-28  6:42     ` Michael Walle
  1 sibling, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2022-06-28  5:03 UTC (permalink / raw)
  To: Michael Walle
  Cc: Charles Gorand, Krzysztof Kozlowski, Clément Perrochaud,
	netdev, linux-kernel

On Sun, 26 Jun 2022 21:42:43 +0200 Michael Walle wrote:
> There are packets which doesn't have a payload. In that case, the second
> i2c_master_read() will have a zero length. But because the NFC
> controller doesn't have any data left, it will NACK the I2C read and
> -ENXIO will be returned. In case there is no payload, just skip the
> second i2c master read.

Whoa, are you using this code or just found the problem thru code
inspection? NFC is notorious for having no known users.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()
  2022-06-28  5:03   ` Jakub Kicinski
@ 2022-06-28  6:42     ` Michael Walle
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Walle @ 2022-06-28  6:42 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Krzysztof Kozlowski, Clément Perrochaud, netdev, linux-kernel

Am 2022-06-28 07:03, schrieb Jakub Kicinski:
> On Sun, 26 Jun 2022 21:42:43 +0200 Michael Walle wrote:
>> There are packets which doesn't have a payload. In that case, the 
>> second
>> i2c_master_read() will have a zero length. But because the NFC
>> controller doesn't have any data left, it will NACK the I2C read and
>> -ENXIO will be returned. In case there is no payload, just skip the
>> second i2c master read.
> 
> Whoa, are you using this code or just found the problem thru code
> inspection? NFC is notorious for having no known users.

Ha! Well, I *try* to use it with a PN7160. No luck so far, we'll see.
At least the communication with the chip works now. I was also kinda
tricked by the Supported status ;)

-michael

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-06-28  6:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-26 19:42 [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Michael Walle
2022-06-26 19:42 ` [PATCH 2/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read() Michael Walle
2022-06-26 19:51   ` Krzysztof Kozlowski
2022-06-26 19:56     ` Michael Walle
2022-06-26 20:02       ` Krzysztof Kozlowski
2022-06-28  5:03   ` Jakub Kicinski
2022-06-28  6:42     ` Michael Walle
2022-06-26 19:49 ` [PATCH 1/2] NFC: nxp-nci: check return code of i2c_master_recv() Krzysztof Kozlowski
2022-06-26 19:55   ` Michael Walle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.