mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] mctp i3c: Fix locking in an error path
@ 2026-10-29 18:00 Bart Van Assche
  2026-11-02  4:03 ` Matt Johnston
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2026-10-29 18:00 UTC (permalink / raw)
  To: Jeremy Kerr, Matt Johnston
  Cc: Leo Yang, Paolo Abeni, netdev, linux-kernel, Bart Van Assche,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Nathan Chancellor, Leo Yang

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 <Leo-Yang@quantatw.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Jeremy Kerr <jk@codeconstruct.com.au>
Cc: Matt Johnston <matt@codeconstruct.com.au>
Cc: netdev@vger.kernel.org
Fixes: 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
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(-)

diff --git a/drivers/net/mctp/mctp-i3c.c b/drivers/net/mctp/mctp-i3c.c
index 4e857dd5df64..5f225999d715 100644
--- a/drivers/net/mctp/mctp-i3c.c
+++ b/drivers/net/mctp/mctp-i3c.c
@@ -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);

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

* Re: [PATCH v2] mctp i3c: Fix locking in an error path
  2026-10-29 18:00 [PATCH v2] mctp i3c: Fix locking in an error path Bart Van Assche
@ 2026-11-02  4:03 ` Matt Johnston
  0 siblings, 0 replies; 2+ messages in thread
From: Matt Johnston @ 2026-11-02  4:03 UTC (permalink / raw)
  To: Bart Van Assche, Jeremy Kerr
  Cc: Leo Yang, Paolo Abeni, netdev, linux-kernel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Nathan Chancellor,
	Leo Yang

On Thu, 2026-10-29 at 11:00 -0700, Bart Van Assche 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 <Leo-Yang@quantatw.com>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Jeremy Kerr <jk@codeconstruct.com.au>
> Cc: Matt Johnston <matt@codeconstruct.com.au>
> Cc: netdev@vger.kernel.org
> Fixes: 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> 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(-)
> 
> diff --git a/drivers/net/mctp/mctp-i3c.c b/drivers/net/mctp/mctp-i3c.c
> index 4e857dd5df64..5f225999d715 100644
> --- a/drivers/net/mctp/mctp-i3c.c
> +++ b/drivers/net/mctp/mctp-i3c.c
> @@ -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.

Acked-by: Matt Johnston <matt@codeconstruct.com.au>


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

end of thread, other threads:[~2026-11-02  4:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 18:00 [PATCH v2] mctp i3c: Fix locking in an error path Bart Van Assche
2026-11-02  4:03 ` Matt Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®