Skip to contentSkip to conversation

NFC: nxp-nci: Don't issue a zero length i2c_master_read()

PATCH Applied Michael Walle 3 participants 4 messages Jun 27, 2022 – Jun 29, 2022

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

PATCH v2 1/2 NFC: nxp-nci: Don't issue a zero length i2c_master_read()

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")

---
changes since v1:
- none

 drivers/nfc/nxp-nci/i2c.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nfc/nxp-nci/i2c.c +3 -0
index 7e451c10985d..e8f3b35afbee 100644
@@ -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 != header.plen) {
 		nfc_err(&client->dev,
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 2/2 NFC: nxp-nci: don't print header length mismatch on i2c error

Don't print a misleading header length mismatch error if the i2c call returns an error. Instead just return the error code without any error message.

---
changes since v1:
- reworded commit message
- removed fixes tag
- removed nfc_err() call, as it is done elsewhere in this driver
- nxp_nci_i2c_fw_read() has the same issue. also handle it there

 drivers/nfc/nxp-nci/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nfc/nxp-nci/i2c.c +6 -2
index e8f3b35afbee..ae2ba08d8ac3 100644
@@ -122,7 +122,9 @@ static int nxp_nci_i2c_fw_read(struct nxp_nci_i2c_phy *phy,
 	skb_put_data(*skb, &header, NXP_NCI_FW_HDR_LEN);
 
 	r = i2c_master_recv(client, skb_put(*skb, frame_len), frame_len);
-	if (r != frame_len) {
+	if (r < 0) {
+		goto fw_read_exit_free_skb;
+	} else if (r != frame_len) {
 		nfc_err(&client->dev,
 			"Invalid frame length: %u (expected %zu)\n",
 			r, frame_len);
@@ -166,7 +168,9 @@ static int nxp_nci_i2c_nci_read(struct nxp_nci_i2c_phy *phy,
 		return 0;
 
 	r = i2c_master_recv(client, skb_put(*skb, header.plen), header.plen);
-	if (r != header.plen) {
+	if (r < 0) {
+		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);
Signature · 1 line
2.30.2
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] NFC: nxp-nci: don't print header length mismatch on i2c error

Quoted 4 lines · Michael Walle

Don't print a misleading header length mismatch error if the i2c call returns an error. Instead just return the error code without any error message.

Quoted 8 lines

---
changes since v1:
- reworded commit message
- removed fixes tag
- removed nfc_err() call, as it is done elsewhere in this driver
- nxp_nci_i2c_fw_read() has the same issue. also handle it there

Best regards,
Krzysztof

#3 lore raw
In reply to Michael Walle
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 11 lines · On Mon, 27 Jun 2022 19:06:42 +0200 you 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")

[...]

Here is the summary with links:
- [v2,1/2] NFC: nxp-nci: Don't issue a zero length i2c_master_read()

    https://git.kernel.org/netdev/net/c/eddd95b94239
  - [v2,2/2] NFC: nxp-nci: don't print header length mismatch on i2c error
    https://git.kernel.org/netdev/net/c/9577fc5fdc8b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html