From: Jianglei Nie <niejianglei2021@163.com>
To: yashi@spacecubics.com, wg@grandegger.com, mkl@pengutronix.de,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, mailhol.vincent@wanadoo.fr,
stefan.maetje@esd.eu, socketcan@hartkopp.net, hbh25y@gmail.com
Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jianglei Nie <niejianglei2021@163.com>
Subject: [PATCH] can: mcba_usb: fix potential resource leak in mcba_usb_xmit_cmd()
Date: Sun, 20 Nov 2022 18:14:14 +0800 [thread overview]
Message-ID: <20221120101414.6071-1-niejianglei2021@163.com> (raw)
mcba_usb_xmit_cmd() gets free ctx by mcba_usb_get_free_ctx(). When
mcba_usb_xmit() fails, the ctx should be freed with mcba_usb_free_ctx()
like mcba_usb_start_xmit() does in label "xmit_failed" to avoid potential
resource leak.
Fix it by calling mcba_usb_free_ctx() when mcba_usb_xmit() fails.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
drivers/net/can/usb/mcba_usb.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c
index 218b098b261d..471f6be6e030 100644
--- a/drivers/net/can/usb/mcba_usb.c
+++ b/drivers/net/can/usb/mcba_usb.c
@@ -380,9 +380,11 @@ static void mcba_usb_xmit_cmd(struct mcba_priv *priv,
}
err = mcba_usb_xmit(priv, usb_msg, ctx);
- if (err)
+ if (err) {
+ mcba_usb_free_ctx(ctx);
netdev_err(priv->netdev, "Failed to send cmd (%d)",
usb_msg->cmd_id);
+ }
}
static void mcba_usb_xmit_change_bitrate(struct mcba_priv *priv, u16 bitrate)
--
2.25.1
next reply other threads:[~2022-11-20 10:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-20 10:14 Jianglei Nie [this message]
2022-11-24 14:45 ` [PATCH] can: mcba_usb: fix potential resource leak in mcba_usb_xmit_cmd() Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221120101414.6071-1-niejianglei2021@163.com \
--to=niejianglei2021@163.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hbh25y@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=socketcan@hartkopp.net \
--cc=stefan.maetje@esd.eu \
--cc=wg@grandegger.com \
--cc=yashi@spacecubics.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).