From nobody Tue Feb 10 05:41:33 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7F939C643 for ; Fri, 16 Jan 2026 19:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768592159; cv=none; b=rPqnpLOnnjTUG1rXtDxDX3rC45lo1yHTO2SMSeY7KxUKJldznBfrZUJIMdai4KdampCVhATVFMtNyjmKShuLtwAmxdhveiTmHgfvcD7okNxzQ/h/Jyv4vCDrmrtMI5ZBRRsMjc9b5P9naVZUhc2a5VqWpPWx50pdYutW3sAOckY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768592159; c=relaxed/simple; bh=qXFHomxH6ThdcsyxaPXbrxn3x7sls0MHEmxaTfhx8Qg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CO00kYetbk37S1xVSkaylvlICnF4t4sI/rNl3P4RhXeqQkIWosGa2gE8BihD1Ei+vHg/Hfn38qmTILrAUPDL9MRd6bOUtd5+tTmUAP1u9fwfTywKqQMBNcKJ7GHb5utbgzSaYGNZEA0vGA1V3s4ULeQz1t+68ZDoNy92a6q4ZOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vgpbi-000804-HJ; Fri, 16 Jan 2026 20:35:42 +0100 Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgpbg-000yK8-1X; Fri, 16 Jan 2026 20:35:39 +0100 Received: from hardanger.blackshift.org (p54b152ce.dip0.t-ipconnect.de [84.177.82.206]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 82DB54CEEE2; Fri, 16 Jan 2026 19:35:39 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 16 Jan 2026 20:35:17 +0100 Subject: [PATCH can v2 4/5] can: mcba_usb: mcba_usb_read_bulk_callback(): fix URB memory leak Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260116-can_usb-fix-memory-leak-v2-4-4b8cb2915571@pengutronix.de> References: <20260116-can_usb-fix-memory-leak-v2-0-4b8cb2915571@pengutronix.de> In-Reply-To: <20260116-can_usb-fix-memory-leak-v2-0-4b8cb2915571@pengutronix.de> To: Vincent Mailhol , Wolfgang Grandegger , Sebastian Haas , "David S. Miller" , Frank Jungclaus , socketcan@esd.eu, Yasushi SHOJI , Daniel Berglund , Olivier Sobrie , =?utf-8?q?Remigiusz_Ko=C5=82=C5=82=C4=85taj?= , Bernd Krumboeck Cc: kernel@pengutronix.de, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , stable@vger.kernel.org X-Mailer: b4 0.15-dev-47773 X-Developer-Signature: v=1; a=openpgp-sha256; l=1845; i=mkl@pengutronix.de; h=from:subject:message-id; bh=qXFHomxH6ThdcsyxaPXbrxn3x7sls0MHEmxaTfhx8Qg=; b=owEBbQGS/pANAwAKAQx0Zd/5kJGcAcsmYgBpapMHCftZMBpsm3ESnrHH0MdA0TlDQ10hv5vs/ ElSzJ5jvE6JATMEAAEKAB0WIQSf+wzYr2eoX/wVbPMMdGXf+ZCRnAUCaWqTBwAKCRAMdGXf+ZCR nMCxB/0RdQkP6n9H89T6X8F1MT5cpnIgin4Pkrqum/PeTcHw+cu03O8YnDBiKeJNqR9IGF0yyDT i4YP+5ekic9dNcfqOdlpGYuvGvbcZaGl3PjUhkFFPViJbvE0rj8bp2Lyt7PIaNIgPJPA5a4mGXf pVKpgGQQ8F2knWY0SywzhQA5b3BvGszQT4vjUg4uoOZ0030FS8KHCfXdOP52EGV68HOTZcYGW2z sE2HqlkzNQ0636GKuM2lQC/SaDM7c8B+y/5/73IZUOoshkntN0LiRH0+JyRZ9+lHQoSe64N52RI uBbuYAvP3/c6w3e4u8ZYJ2porzp3dZm8YyqMzrsth16vPrrP X-Developer-Key: i=mkl@pengutronix.de; a=openpgp; fpr=C1400BA0B3989E6FBC7D5B5C2B5EE211C58AEA54 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Fix similar memory leak as in commit 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak"). In mcba_usb_probe() -> mcba_usb_start(), the URBs for USB-in transfers are allocated, added to the priv->rx_submitted anchor and submitted. In the complete callback mcba_usb_read_bulk_callback(), the URBs are processed and resubmitted. In mcba_usb_close() -> mcba_urb_unlink() the URBs are freed by calling usb_kill_anchored_urbs(&priv->rx_submitted). However, this does not take into account that the USB framework unanchors the URB before the complete function is called. This means that once an in-URB has been completed, it is no longer anchored and is ultimately not released in usb_kill_anchored_urbs(). Fix the memory leak by anchoring the URB in the mcba_usb_read_bulk_callback()to the priv->rx_submitted anchor. Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Anal= yzer") Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde --- drivers/net/can/usb/mcba_usb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 41c0a1c399bf..04170326dc7e 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -608,11 +608,17 @@ static void mcba_usb_read_bulk_callback(struct urb *u= rb) urb->transfer_buffer, MCBA_USB_RX_BUFF_SIZE, mcba_usb_read_bulk_callback, priv); =20 + usb_anchor_urb(urb, &priv->rx_submitted); + retval =3D usb_submit_urb(urb, GFP_ATOMIC); + if (!retval) + return; + + usb_unanchor_urb(urb); =20 if (retval =3D=3D -ENODEV) netif_device_detach(netdev); - else if (retval) + else netdev_err(netdev, "failed resubmitting read bulk urb: %d\n", retval); } --=20 2.51.0