Skip to contentSkip to conversation

nfc: Remove checks for nla_data returning NULL

PATCH Applied Simon Horman 3 participants 3 messages Jun 17, 2025 – Jun 18, 2025

Subsystems (3)
lore
Share & tools
lore

Simon Horman

author reviewer
#0 lore raw

PATCH 1/1 nfc: Remove checks for nla_data returning NULL

The implementation of nla_data is as follows:

static inline void *nla_data(const struct nlattr *nla)

{
	return (char *) nla + NLA_HDRLEN;
}

Excluding the case where nla is exactly -NLA_HDRLEN, it will not return NULL. And it seems misleading to assume that it can, other than in this corner case. So drop checks for this condition.

Flagged by Smatch.

Compile tested only.

---
 net/nfc/netlink.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/nfc/netlink.c +1 -5
index 6a40b8d0350d..a18e2c503da6 100644
@@ -1192,7 +1192,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
 			continue;
 
 		uri = nla_data(sdp_attrs[NFC_SDP_ATTR_URI]);
-		if (uri == NULL || *uri == 0)
+		if (*uri == 0)
 			continue;
 
 		tid = local->sdreq_next_tid++;
@@ -1540,10 +1540,6 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
-	if (!apdu) {
-		rc = -EINVAL;
-		goto put_dev;
-	}
 
 	ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
 	if (!ctx) {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Simon Horman

The implementation of nla_data is as follows:

static inline void *nla_data(const struct nlattr *nla)

{
	return (char *) nla + NLA_HDRLEN;
}

Excluding the case where nla is exactly -NLA_HDRLEN, it will not return NULL. And it seems misleading to assume that it can, other than in this corner case. So drop checks for this condition.

Quoted 6 lines

Flagged by Smatch.

Compile tested only.

---

Best regards,
Krzysztof

#2 lore raw
In reply to Simon Horman
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 17 Jun 2025 09:45:39 +0100 you wrote:

The implementation of nla_data is as follows:

static inline void *nla_data(const struct nlattr *nla)

{
	return (char *) nla + NLA_HDRLEN;
}

[...]

Here is the summary with links:
- [net-next] nfc: Remove checks for nla_data returning NULL

    https://git.kernel.org/netdev/net-next/c/a9874d961e8c

You are awesome, thank you!

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