mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-input@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Jiri Kosina <jikos@kernel.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Qasim Ijaz <qasdev00@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] HID: thrustmaster: Use scope-based resource management in thrustmaster_interrupts()
Date: Mon, 28 Apr 2025 21:23:53 +0200	[thread overview]
Message-ID: <d431f727-894a-48e3-bca6-3f2aa971d7be@web.de> (raw)

From: Markus Elfring <elfring@users.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@users.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


                 reply	other threads:[~2025-04-28 19:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=d431f727-894a-48e3-bca6-3f2aa971d7be@web.de \
    --to=markus.elfring@web.de \
    --cc=alexandre.torgue@foss.st.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=qasdev00@gmail.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

all inboxes | Powered by JetHome®