From: Benjamin Tissoires <bentiss@kernel.org>
To: "Jiri Kosina" <jikos@kernel.org>,
"Filipe Laíns" <lains@riseup.net>,
"Bastien Nocera" <hadess@hadess.net>,
"Ping Cheng" <ping.cheng@wacom.com>,
"Jason Gerecke" <jason.gerecke@wacom.com>,
"Viresh Kumar" <vireshk@kernel.org>,
"Johan Hovold" <johan@kernel.org>,
"Alex Elder" <elder@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Lee Jones" <lee@kernel.org>
Cc: Icenowy Zheng <uwu@icenowy.me>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
linux-usb@vger.kernel.org,
Benjamin Tissoires <bentiss@kernel.org>
Subject: [PATCH v3 3/4] HID: multitouch: use __free(kfree) to clean up temporary buffers
Date: Mon, 04 May 2026 10:47:24 +0200 [thread overview]
Message-ID: <20260504-wip-fix-core-v3-3-ce1f11f4968f@kernel.org> (raw)
In-Reply-To: <20260504-wip-fix-core-v3-0-ce1f11f4968f@kernel.org>
This simplifies error handling and protects against memory leaks.
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
---
drivers/hid/hid-multitouch.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index eeab0b6e32cc..b19463e545d6 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -507,7 +507,6 @@ static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
{
int ret;
u32 size = hid_report_len(report);
- u8 *buf;
/*
* Do not fetch the feature report if the device has been explicitly
@@ -516,7 +515,7 @@ static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
return;
- buf = hid_alloc_report_buf(report, GFP_KERNEL);
+ u8 *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL);
if (!buf)
return;
@@ -529,7 +528,7 @@ static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
/* The report ID in the request and the response should match */
if (report->id != buf[0]) {
hid_err(hdev, "Returned feature report did not match the request\n");
- goto free;
+ return;
}
ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
@@ -537,9 +536,6 @@ static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
if (ret)
dev_warn(&hdev->dev, "failed to report feature\n");
}
-
-free:
- kfree(buf);
}
static void mt_feature_mapping(struct hid_device *hdev,
@@ -1658,7 +1654,6 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
struct mt_class *cls = &td->mtclass;
struct hid_report *report = field->report;
unsigned int index = usage->usage_index;
- char *buf;
u32 report_len;
int max;
@@ -1673,17 +1668,18 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
return false;
if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
- report_len = hid_report_len(report);
- buf = hid_alloc_report_buf(report, GFP_KERNEL);
+ char *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL);
+
if (!buf) {
hid_err(hdev,
"failed to allocate buffer for report\n");
return false;
}
+
+ report_len = hid_report_len(report);
hid_hw_raw_request(hdev, report->id, buf, report_len,
HID_FEATURE_REPORT,
HID_REQ_GET_REPORT);
- kfree(buf);
}
field->value[index] = td->inputmode_value;
--
2.54.0
next prev parent reply other threads:[~2026-05-04 8:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 8:47 [PATCH v3 0/4] HID: Proper fix for OOM in hid-core Benjamin Tissoires
2026-05-04 8:47 ` [PATCH v3 1/4] HID: pass the buffer size to hid_report_raw_event Benjamin Tissoires
2026-05-04 9:31 ` Johan Hovold
2026-05-04 12:21 ` Greg Kroah-Hartman
2026-05-04 8:47 ` [PATCH v3 2/4] HID: core: introduce hid_safe_input_report() Benjamin Tissoires
2026-05-04 8:47 ` Benjamin Tissoires [this message]
2026-05-04 8:47 ` [PATCH v3 4/4] HID: wacom: use __free(kfree) to clean up temporary buffers Benjamin Tissoires
2026-05-04 23:15 ` Dmitry Torokhov
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=20260504-wip-fix-core-v3-3-ce1f11f4968f@kernel.org \
--to=bentiss@kernel.org \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=hadess@hadess.net \
--cc=jason.gerecke@wacom.com \
--cc=jikos@kernel.org \
--cc=johan@kernel.org \
--cc=lains@riseup.net \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-usb@vger.kernel.org \
--cc=ping.cheng@wacom.com \
--cc=uwu@icenowy.me \
--cc=vireshk@kernel.org \
/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