From nobody Tue Feb 10 11:12:43 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 DB2072D73A0 for ; Fri, 16 Jan 2026 19:35:58 +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=1768592160; cv=none; b=WC+GMumWdHnAEkvWzfOGagqqARApcwnzb3xFIOOLJaD6UsnaHmlgnjwKkbX3VH9A5NSif7ZlgQfiioR8XBaXERVWsOxOHl1tRBGVfHqpeWxAm7RHsj76AmDg7HlPM/3PRdOdGls8b9JCA0/S6xK9upKbLIMhLEG5QuFJblZTdfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768592160; c=relaxed/simple; bh=KbWIIEM4ohPRp4DL98wrpV9hcgVfu3ohKMJyFuQCySI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SsHixee0SCTlf5KgLHJZ4NfvBmIW0wucwByMsW2HliF62dOFvN+cihA6s1VPgkNxRbpC3QfsNRx6WqfSVi3l5FVwXTLONRXydtfq7hH6zQ6iqZSmApl9ejrnEVmN/VJDhQvm8Gc5+Jkeu9NFDNYzg5kAa2tI2pRZ88fy+Qd3Kjo= 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-000802-HH; 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-000yK4-1C; 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 62EFD4CEEE0; Fri, 16 Jan 2026 19:35:39 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 16 Jan 2026 20:35:15 +0100 Subject: [PATCH can v2 2/5] can: esd_usb: esd_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-2-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=1867; i=mkl@pengutronix.de; h=from:subject:message-id; bh=KbWIIEM4ohPRp4DL98wrpV9hcgVfu3ohKMJyFuQCySI=; b=owEBbQGS/pANAwAKAQx0Zd/5kJGcAcsmYgBpapMDdXADWUgaw9YvJzE/HGUiZn9aD0PXuzjhj +FnbjWikDiJATMEAAEKAB0WIQSf+wzYr2eoX/wVbPMMdGXf+ZCRnAUCaWqTAwAKCRAMdGXf+ZCR nKv0CACNXLUKTK5r2V9C/Jh9KzpQx79px9NeGVSDQwwitiF2m2cvgmzLC+lHXvX6yNIbJqr5wRg uS9zIH1EDTHvV0nV26lOBfdg9nS4+0M2YCxaisqHQZhujfVm+pAdOcd8sPwlvyDgctrKtjlT0hT MU2LZiHETRa3HeQFwWHo5G6obz+y/AyBeSZHy8tdMspf3AjoLAy0SSLp5y5sKaMHH3RJDF4dZPL BHgmNKjBkQ2a+ckA61my+/f1LzUKX+D+t7pXtCikZM2oaLXcXoIYxyNF0HB0/U/Yf//3J/+N8d+ ZGfdGxqj0RPvOs1YcvfAX/KfKVHhQZzrMpDjD+wztKHsvQ7v 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 esd_usb_open(), the URBs for USB-in transfers are allocated, added to the dev->rx_submitted anchor and submitted. In the complete callback esd_usb_read_bulk_callback(), the URBs are processed and resubmitted. In esd_usb_close() the URBs are freed by calling usb_kill_anchored_urbs(&dev->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 esd_usb_close(). Fix the memory leak by anchoring the URB in the esd_usb_read_bulk_callback() to the dev->rx_submitted anchor. Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde --- drivers/net/can/usb/esd_usb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c index 08da507faef4..8cc924c47042 100644 --- a/drivers/net/can/usb/esd_usb.c +++ b/drivers/net/can/usb/esd_usb.c @@ -541,13 +541,20 @@ static void esd_usb_read_bulk_callback(struct urb *ur= b) urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE, esd_usb_read_bulk_callback, dev); =20 + usb_anchor_urb(urb, &dev->rx_submitted); + err =3D usb_submit_urb(urb, GFP_ATOMIC); + if (!err) + return; + + usb_unanchor_urb(urb); + if (err =3D=3D -ENODEV) { for (i =3D 0; i < dev->net_count; i++) { if (dev->nets[i]) netif_device_detach(dev->nets[i]->netdev); } - } else if (err) { + } else { dev_err(dev->udev->dev.parent, "failed resubmitting read bulk urb: %pe\n", ERR_PTR(err)); } --=20 2.51.0