Skip to contentSkip to conversation

mctp i3c: Fix locking in an error path

PATCH Applied Bart Van Assche 3 participants 3 messages Oct 29 – Nov 3

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

PATCH v2 1/1 mctp i3c: Fix locking in an error path

If netdev_alloc_skb() fails, mctp_i3c_read() jumps to a label that unlocks mi->lock although that mutex has not been locked yet. Fix this by returning -ENOMEM directly. This bug has been detected by the Clang thread-safety analyzer.

Cc Leo Yang <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matt Johnston <[email protected]>
Fixes 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")

---
v1 -> v2:
- Return -ENOMEM directly upon allocation failure instead of adding a free_skb label.

 drivers/net/mctp/mctp-i3c.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/mctp/mctp-i3c.c +1 -2
index 4e857dd5df64..5f225999d715 100644
@@ -111,8 +111,7 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 			       mi->mrl + sizeof(struct mctp_i3c_internal_hdr));
 	if (!skb) {
 		stats->rx_dropped++;
-		rc = -ENOMEM;
-		goto err;
+		return -ENOMEM;
 	}
 
 	skb->protocol = htons(ETH_P_MCTP);
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 25 lines · Bart Van Assche

If netdev_alloc_skb() fails, mctp_i3c_read() jumps to a label that unlocks mi->lock although that mutex has not been locked yet. Fix this by returning -ENOMEM directly. This bug has been detected by the Clang thread-safety analyzer.

Cc Leo Yang <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matt Johnston <[email protected]>
Fixes 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")

---
v1 -> v2:
- Return -ENOMEM directly upon allocation failure instead of adding a free_skb label.

 drivers/net/mctp/mctp-i3c.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/mctp/mctp-i3c.c +0 -0
index 4e857dd5df64..5f225999d715 100644

drivers/net/mctp/mctp-i3c.c static int mctp_i3c_read(struct mctp_i3c_device *mi) · line 115

Quoted 7 lines
drivers/net/mctp/mctp-i3c.c +1 -2
@@ -111,8 +111,7 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 			       mi->mrl + sizeof(struct mctp_i3c_internal_hdr));
 	if (!skb) {
 		stats->rx_dropped++;
-		rc = -ENOMEM;
-		goto err;
+		return -ENOMEM;
 	}

Thank you.

#2 lore raw
In reply to Bart Van Assche
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 13 lines · On Thu, 29 Oct 2026 11:00:39 -0700 you wrote:

If netdev_alloc_skb() fails, mctp_i3c_read() jumps to a label that unlocks mi->lock although that mutex has not been locked yet. Fix this by returning -ENOMEM directly. This bug has been detected by the Clang thread-safety analyzer.

Cc Leo Yang <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matt Johnston <[email protected]>
Fixes 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")
Quoted 1 line

[...]

Here is the summary with links:
- [v2] mctp i3c: Fix locking in an error path

    https://git.kernel.org/netdev/net/c/750eb5ab457e

You are awesome, thank you!

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