From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Derek J . Clark" <derekjohn.clark@gmail.com>
Cc: "Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Nitin Joshi" <nitjoshi@gmail.com>,
"platform-driver-x86@vger.kernel.org"
<platform-driver-x86@vger.kernel.org>,
ibm-acpi-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] platform/x86: thinkpad_acpi: use __free(kfree) for automatic cleanup
Date: Wed, 12 Aug 2026 15:02:10 -0400 [thread overview]
Message-ID: <d20cb764-a9ea-4443-93d4-486d7310dd4f@app.fastmail.com> (raw)
In-Reply-To: <20260806061925.625482-3-dmitry.torokhov@gmail.com>
Thanks Dmitry,
On Thu, Aug 6, 2026, at 2:19 AM, Dmitry Torokhov wrote:
> Use __free(kfree) for local pointer allocations in dispatch_proc_write(),
> tpacpi_brightness_get_ecnvram(), and auxmac_init().
>
> This ensures automatic memory cleanup when exiting function scope and
> removes explicit kfree() calls on exit paths.
>
> Assisted-by: Antigravity:gemini-3.6-flash
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 40 +++++++--------------
> 1 file changed, 13 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 0d0d6fe7eecd..200e20f90a4b 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -885,7 +885,6 @@ static ssize_t dispatch_proc_write(struct file
> *file,
> size_t count, loff_t *pos)
> {
> struct ibm_struct *ibm = pde_data(file_inode(file));
> - char *kernbuf;
> int ret;
>
> if (!ibm || !ibm->write)
> @@ -893,16 +892,15 @@ static ssize_t dispatch_proc_write(struct file *file,
> if (count > PAGE_SIZE - 1)
> return -EINVAL;
>
> - kernbuf = memdup_user_nul(userbuf, count);
> + char *kernbuf __free(kfree) = memdup_user_nul(userbuf, count);
> if (IS_ERR(kernbuf))
> return PTR_ERR(kernbuf);
> - ret = ibm->write(kernbuf);
> - if (ret == 0)
> - ret = count;
>
> - kfree(kernbuf);
> + ret = ibm->write(kernbuf);
> + if (ret)
> + return ret;
>
> - return ret;
> + return count;
> }
>
> static const struct proc_ops dispatch_proc_ops = {
> @@ -6628,26 +6626,21 @@ static const struct backlight_ops ibm_backlight_data = {
> static int __init tpacpi_evaluate_bcl(struct acpi_device *adev, void *not_used)
> {
> struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
> - union acpi_object *obj;
> acpi_status status;
> - int rc;
>
> status = acpi_evaluate_object(adev->handle, "_BCL", NULL, &buffer);
> if (ACPI_FAILURE(status))
> return 0;
>
> - obj = buffer.pointer;
> + union acpi_object *obj __free(kfree) = buffer.pointer;
> if (!obj || obj->type != ACPI_TYPE_PACKAGE) {
> acpi_handle_info(adev->handle,
> "Unknown _BCL data, please report this to %s\n",
> TPACPI_MAIL);
> - rc = 0;
> - } else {
> - rc = obj->package.count;
> + return 0;
> }
> - kfree(obj);
>
> - return rc;
> + return obj->package.count;
> }
>
> /*
> @@ -10989,24 +10982,23 @@ static int auxmac_init(struct ibm_init_struct *iibm)
> {
> acpi_status status;
> struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
> - union acpi_object *obj;
>
> - status = acpi_evaluate_object(NULL, "\\MACA", NULL, &buffer);
> + strscpy(auxmac, "unavailable", sizeof(auxmac));
>
> + status = acpi_evaluate_object(NULL, "\\MACA", NULL, &buffer);
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> - obj = buffer.pointer;
> -
> + union acpi_object *obj __free(kfree) = buffer.pointer;
> if (obj->type != ACPI_TYPE_STRING || obj->string.length != AUXMAC_STRLEN) {
> pr_info("Invalid buffer for MAC address pass-through.\n");
> - goto auxmacinvalid;
> + return 0;
> }
>
> if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' ||
> obj->string.pointer[AUXMAC_END_MARKER] != '#') {
> pr_info("Invalid header for MAC address pass-through.\n");
> - goto auxmacinvalid;
> + return 0;
> }
>
> if (strncmp(obj->string.pointer + AUXMAC_START, "XXXXXXXXXXXX",
> AUXMAC_LEN) != 0)
> @@ -11014,13 +11006,7 @@ static int auxmac_init(struct ibm_init_struct
> *iibm)
> else
> strscpy(auxmac, "disabled", sizeof(auxmac));
>
> -free:
> - kfree(obj);
> return 0;
> -
> -auxmacinvalid:
> - strscpy(auxmac, "unavailable", sizeof(auxmac));
> - goto free;
> }
>
> static struct ibm_struct auxmac_data = {
> --
> 2.55.0.679.g6767b8d81c-goog
Another kernel implementation I didn't know about.
It all looks good to me, and gives some nice clean-up. Thanks
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
next prev parent reply other threads:[~2026-08-12 19:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 6:19 [PATCH 1/3] platform/x86: thinkpad_acpi: convert mutex_lock() to guard(mutex) Dmitry Torokhov
2026-08-06 6:19 ` [PATCH 2/3] platform/x86: thinkpad_acpi: convert conditional mutex locks to ACQUIRE_ERR() Dmitry Torokhov
2026-08-12 18:53 ` Mark Pearson
2026-08-06 6:19 ` [PATCH 3/3] platform/x86: thinkpad_acpi: use __free(kfree) for automatic cleanup Dmitry Torokhov
2026-08-12 19:02 ` Mark Pearson [this message]
2026-08-12 18:29 ` [PATCH 1/3] platform/x86: thinkpad_acpi: convert mutex_lock() to guard(mutex) Mark Pearson
2026-08-12 19:55 ` [ibm-acpi-devel] " Mark Pearson
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=d20cb764-a9ea-4443-93d4-486d7310dd4f@app.fastmail.com \
--to=mpearson-lenovo@squebb.ca \
--cc=derekjohn.clark@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=hansg@kernel.org \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nitjoshi@gmail.com \
--cc=platform-driver-x86@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
all inboxes | Powered by JetHome®