mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Armin Wolf <W_Armin@gmx.de>
Cc: markpearson@lenovo.com, jorge.lopez2@hp.com,
	Hans de Goede <hdegoede@redhat.com>,
	markgross@kernel.org, platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] platform/x86: hp-bioscfg: Fix reference leak
Date: Mon, 25 Sep 2023 16:38:30 +0300 (EEST)	[thread overview]
Message-ID: <eaabc245-bf5a-b4a0-f319-1e1c4f02d7a@linux.intel.com> (raw)
In-Reply-To: <20230925132844.72479-3-W_Armin@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 2824 bytes --]

On Mon, 25 Sep 2023, Armin Wolf wrote:

> If a duplicate attribute is found using kset_find_obj(), a reference
> to that attribute is returned which needs to be disposed accordingly
> using kobject_put(). Use kobject_put() to dispose the duplicate
> attribute in such a case.
> As a side note, a very similar bug was fixed in
> commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"),
> so it seems that the bug was copied from that driver.
> 
> Compile-tested only.
> 
> Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Changes in v3:
> - no changes
> Changes in v2:
> - add patch
> ---
>  drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> index 8c4f9e12f018..0c83e66f8d0b 100644
> --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> @@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
>  					  const char *guid, int min_elements,
>  					  int instance_id)
>  {
> -	struct kobject *attr_name_kobj;
> +	struct kobject *attr_name_kobj, *duplicate;
>  	union acpi_object *elements;
>  	struct kset *temp_kset;
> 
> @@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
>  	}
> 
>  	/* All duplicate attributes found are ignored */
> -	if (kset_find_obj(temp_kset, str_value)) {
> +	duplicate = kset_find_obj(temp_kset, str_value);
> +	if (duplicate) {
>  		pr_debug("Duplicate attribute name found - %s\n", str_value);
> +		/* kset_find_obj() returns a reference */
> +		kobject_put(duplicate);
>  		goto pack_attr_exit;
>  	}
> 
> @@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
>  					 const char *guid, int min_elements,
>  					 int instance_id)
>  {
> -	struct kobject *attr_name_kobj;
> +	struct kobject *attr_name_kobj, *duplicate;
>  	struct kset *temp_kset;
>  	char str[MAX_BUFF_SIZE];
> 
> @@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
>  		temp_kset = bioscfg_drv.main_dir_kset;
> 
>  	/* All duplicate attributes found are ignored */
> -	if (kset_find_obj(temp_kset, str)) {
> +	duplicate = kset_find_obj(temp_kset, str);
> +	if (duplicate) {
>  		pr_debug("Duplicate attribute name found - %s\n", str);
> +		/*kset_find_obj() returns a reference */

Thanks. Whitespace is missing here.

Other than that, 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

> +		kobject_put(duplicate);
>  		goto buff_attr_exit;
>  	}
> 
> --
> 2.39.2
> 

-- 
 i.

      reply	other threads:[~2023-09-25 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25 13:28 [PATCH v3 0/2] platform/x86: Fix reference leaks Armin Wolf
2023-09-25 13:28 ` [PATCH v3 1/2] platform/x86: think-lmi: Fix reference leak Armin Wolf
2023-09-25 13:28 ` [PATCH v3 2/2] platform/x86: hp-bioscfg: " Armin Wolf
2023-09-25 13:38   ` Ilpo Järvinen [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=eaabc245-bf5a-b4a0-f319-1e1c4f02d7a@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=W_Armin@gmx.de \
    --cc=hdegoede@redhat.com \
    --cc=jorge.lopez2@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=markpearson@lenovo.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®