From: Greg KH <greg@kroah.com>
To: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Jiri Kosina <jkosina@suse.com>
Subject: Re: [PATCH 6.12.y 1/3] HID: input: use __free(kfree) to clean up temporary buffers
Date: Mon, 31 Aug 2026 14:00:16 +0200 [thread overview]
Message-ID: <2026083112-fabric-dairy-c1f9@gregkh> (raw)
In-Reply-To: <20260826171955.2266521-1-sashal@kernel.org>
On Wed, Aug 26, 2026 at 01:19:52PM -0400, Sasha Levin wrote:
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> [ Upstream commit 142068281f5138a9888d488e6911e8d9f7923c15 ]
>
> The __free() cleanup automatically releases given resource when leaving
> the scope, so use it to make the code less cluttered with error
> handling.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Signed-off-by: Jiri Kosina <jkosina@suse.com>
> Stable-dep-of: d07644524b65 ("HID: input: read battery capacity from its actual report offset")
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> drivers/hid/hid-input.c | 15 ++++-----------
> 1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index c1708caa6b6cc..74d04e5c7f0b7 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -419,23 +419,18 @@ static int hidinput_scale_battery_capacity(struct hid_device *dev,
>
> static int hidinput_query_battery_capacity(struct hid_device *dev)
> {
> - u8 *buf;
> int ret;
>
> - buf = kmalloc(4, GFP_KERNEL);
> + u8 *buf __free(kfree) = kmalloc(4, GFP_KERNEL);
> if (!buf)
> return -ENOMEM;
>
> ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 4,
> dev->battery_report_type, HID_REQ_GET_REPORT);
> - if (ret < 2) {
> - kfree(buf);
> + if (ret < 2)
> return -ENODATA;
> - }
>
> - ret = hidinput_scale_battery_capacity(dev, buf[1]);
> - kfree(buf);
> - return ret;
> + return hidinput_scale_battery_capacity(dev, buf[1]);
> }
>
> static int hidinput_get_battery_property(struct power_supply *psy,
> @@ -1818,7 +1813,6 @@ static void hidinput_led_worker(struct work_struct *work)
> struct hid_report *report;
> int ret;
> u32 len;
> - __u8 *buf;
>
> field = hidinput_get_led_field(hid);
> if (!field)
> @@ -1845,7 +1839,7 @@ static void hidinput_led_worker(struct work_struct *work)
>
> /* fall back to generic raw-output-report */
> len = hid_report_len(report);
> - buf = hid_alloc_report_buf(report, GFP_KERNEL);
> + u8 *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL);
> if (!buf)
> return;
>
> @@ -1855,7 +1849,6 @@ static void hidinput_led_worker(struct work_struct *work)
> if (ret == -ENOSYS)
> hid_hw_raw_request(hid, report->id, buf, len, HID_OUTPUT_REPORT,
> HID_REQ_SET_REPORT);
> - kfree(buf);
> }
>
> static int hidinput_input_event(struct input_dev *dev, unsigned int type,
> --
> 2.53.0
>
>
Does not apply :(
prev parent reply other threads:[~2026-08-31 12:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 13:16 FAILED: patch "[PATCH] HID: input: read battery capacity from its actual report" failed to apply to 6.12-stable tree gregkh
2026-08-26 17:19 ` [PATCH 6.12.y 1/3] HID: input: use __free(kfree) to clean up temporary buffers Sasha Levin
2026-08-26 17:19 ` [PATCH 6.12.y 2/3] HID: input: Introduce struct hid_battery and refactor battery code Sasha Levin
2026-08-26 17:19 ` [PATCH 6.12.y 3/3] HID: input: read battery capacity from its actual report offset Sasha Levin
2026-08-31 12:00 ` Greg KH [this message]
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=2026083112-fabric-dairy-c1f9@gregkh \
--to=greg@kroah.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jkosina@suse.com \
--cc=sashal@kernel.org \
--cc=stable@vger.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;
as well as URLs for NNTP newsgroup(s).