lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <d431f727-894a-48e3-bca6-3f2aa971d7be@web.de>
Date: Mon, 28 Apr 2025 21:23:53 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: linux-input@...r.kernel.org, linux-stm32@...md-mailman.stormreply.com,
 linux-arm-kernel@...ts.infradead.org,
 Alexandre Torgue <alexandre.torgue@...s.st.com>,
 Benjamin Tissoires <bentiss@...nel.org>, Jiri Kosina <jikos@...nel.org>,
 Maxime Coquelin <mcoquelin.stm32@...il.com>, Qasim Ijaz <qasdev00@...il.com>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: [PATCH] HID: thrustmaster: Use scope-based resource management in
 thrustmaster_interrupts()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Mon, 28 Apr 2025 21:12:14 +0200

Scope-based resource management became supported for some
programming interfaces by contributions of Peter Zijlstra on 2023-05-26.
See also the commit 54da6a0924311c7cf5015533991e44fb8eb12773 ("locking:
Introduce __cleanup() based infrastructure").

* Thus use the attribute “__free(kfree)”.

* Omit four kfree() calls accordingly.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/hid/hid-thrustmaster.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/hid/hid-thrustmaster.c b/drivers/hid/hid-thrustmaster.c
index 0bf70664c35e..c4d74c1d5ddd 100644
--- a/drivers/hid/hid-thrustmaster.c
+++ b/drivers/hid/hid-thrustmaster.c
@@ -150,7 +150,7 @@ static const struct usb_ctrlrequest change_request = {
 static void thrustmaster_interrupts(struct hid_device *hdev)
 {
 	int ret, trans, i, b_ep;
-	u8 *send_buf = kmalloc(256, GFP_KERNEL);
+	u8 *send_buf __free(kfree) = kmalloc(256, GFP_KERNEL);
 	struct usb_host_endpoint *ep;
 	struct device *dev = &hdev->dev;
 	struct usb_interface *usbif = to_usb_interface(dev->parent);
@@ -162,7 +162,6 @@ static void thrustmaster_interrupts(struct hid_device *hdev)
 	}
 
 	if (usbif->cur_altsetting->desc.bNumEndpoints < 2) {
-		kfree(send_buf);
 		hid_err(hdev, "Wrong number of endpoints?\n");
 		return;
 	}
@@ -174,7 +173,6 @@ static void thrustmaster_interrupts(struct hid_device *hdev)
 	u8 ep_addr[2] = {b_ep, 0};
 
 	if (!usb_check_int_endpoints(usbif, ep_addr)) {
-		kfree(send_buf);
 		hid_err(hdev, "Unexpected non-int endpoint\n");
 		return;
 	}
@@ -191,12 +189,9 @@ static void thrustmaster_interrupts(struct hid_device *hdev)
 
 		if (ret) {
 			hid_err(hdev, "setup data couldn't be sent\n");
-			kfree(send_buf);
 			return;
 		}
 	}
-
-	kfree(send_buf);
 }
 
 static void thrustmaster_change_handler(struct urb *urb)
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ