mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Armin Wolf" <W_Armin@gmx.de>,
	"Mark Pearson" <markpearson@lenovo.com>,
	"Mirsad Goran Todorovac" <mirsad.todorovac@alu.unizg.hr>
Cc: "Hans de Goede" <hdegoede@redhat.com>,
	"markgross@kernel.org" <markgross@kernel.org>,
	"Thomas Weißschuh" <thomas@t-8ch.de>,
	"Greg KH" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: think-lmi: Fix memory leak when showing current settings
Date: Fri, 31 Mar 2023 15:14:13 -0400	[thread overview]
Message-ID: <2233a8da-aaad-4265-b583-f3db27f75667@app.fastmail.com> (raw)
In-Reply-To: <20230331180912.38392-1-W_Armin@gmx.de>

Hi Armin

On Fri, Mar 31, 2023, at 2:09 PM, Armin Wolf wrote:
> When retriving a item string with tlmi_setting(), the result has to be
> freed using kfree(). In current_value_show() however, malformed
> item strings are not freed, causing a memory leak.
> Fix this by eliminating the early return responsible for this.
>
> Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
> Link: 
> https://lore.kernel.org/platform-driver-x86/01e920bc-5882-ba0c-dd15-868bf0eca0b8@alu.unizg.hr/T/#t
> Fixes: a40cd7ef22fb ("platform/x86: think-lmi: Add WMI interface 
> support on Lenovo platforms")
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Changes in v2:
> - Add Reported-by: and Link: tags
> ---
>  drivers/platform/x86/think-lmi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/think-lmi.c 
> b/drivers/platform/x86/think-lmi.c
> index cc66f7cbccf2..8cafb9d4016c 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -930,10 +930,12 @@ static ssize_t current_value_show(struct kobject 
> *kobj, struct kobj_attribute *a
>  	/* validate and split from `item,value` -> `value` */
>  	value = strpbrk(item, ",");
>  	if (!value || value == item || !strlen(value + 1))
> -		return -EINVAL;
> +		ret = -EINVAL;
> +	else
> +		ret = sysfs_emit(buf, "%s\n", value + 1);
>
> -	ret = sysfs_emit(buf, "%s\n", value + 1);
>  	kfree(item);
> +
>  	return ret;
>  }
>
> --
> 2.30.2

Thanks for doing this - it was on my todo list but you beat me to it.

As a minor note - the Fixes tag should, I think, be
Fixes: 0fdf10e5fc96 ("platform/x86: think-lmi: Split current_value to reflect only the value")

As that's when I believe I introduced the issue.

Mark

  reply	other threads:[~2023-03-31 19:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 18:09 Armin Wolf
2023-03-31 19:14 ` Mark Pearson [this message]
2023-03-31 21:20   ` Armin Wolf
2023-03-31 19:34 ` Mirsad Goran Todorovac
2023-03-31 21:26   ` Armin Wolf
2023-03-31 20:23 ` Mirsad Goran Todorovac
2023-03-31 21:30   ` Armin Wolf
2023-04-01  2:54     ` Mirsad Goran Todorovac

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=2233a8da-aaad-4265-b583-f3db27f75667@app.fastmail.com \
    --to=mpearson-lenovo@squebb.ca \
    --cc=W_Armin@gmx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=markpearson@lenovo.com \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=thomas@t-8ch.de \
    /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®