Linux Power Management development
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Markus Elfring <Markus.Elfring@web.de>,
	linux-pm@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Zhang Rui <rui.zhang@intel.com>
Subject: Re: [PATCH] thermal/lib: Fix memory leak on error in thermal_genl_auto()
Date: Thu, 24 Oct 2024 14:27:18 +0100	[thread overview]
Message-ID: <f6ad24c8-0065-4d73-98f1-dc4246ca70ea@arm.com> (raw)
In-Reply-To: <CAJZ5v0jWGdzakj8ob2otAO6auwGBvVsewujG-d9b1Z5nnO7Vkw@mail.gmail.com>



On 10/24/24 14:18, Rafael J. Wysocki wrote:
> On Thu, Oct 24, 2024 at 2:57 PM Daniel Lezcano
> <daniel.lezcano@linaro.org> wrote:
>>
>> On 24/10/2024 14:02, Markus Elfring wrote:
>>>> The function thermal_genl_auto() does not free the allocated message
>>>> in the error path. Fix that by putting a out label and jump to it
>>>> which will free the message instead of directly returning an error.
>>>
>>> Would you like to add any tags (like “Fixes” and “Cc”) accordingly?
>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc4#n145
>>>
>>>
>>> …
>>>> +++ b/tools/lib/thermal/commands.c
>>>> @@ -375,27 +375,30 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cm
>>>>                                        struct cmd_param *param,
>>>>                                        int cmd, int flags, void *arg)
>>>>    {
>>>> +    thermal_error_t ret = THERMAL_ERROR;
>>>>       struct nl_msg *msg;
>>>>       void *hdr;
>>>>
>>>>       msg = nlmsg_alloc();
>>>>       if (!msg)
>>>> -            return THERMAL_ERROR;
>>>> +            goto out;
>>> …
>>>
>>> Is it really reasonable to pass a null pointer (from a failed function call)
>>> to a subsequent nlmsg_free() call?
>>
>> You are right, I should return here :S
> 
> Do you want to respin it?
> 
> Alternatively, I can fix it up when applying the patch.

The nlmskg_free() function should handle that similar to kfree().
Under the hood there is a check in skb_unref():
if (unlikely(!skb))

AFAIK the kfree() is used similar way and NULL is part of generic
case sometimes, not handles with extra code.

Up to you. You can keep my review tag in both cases.

  reply	other threads:[~2024-10-24 13:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 10:59 [PATCH] thermal/lib: Fix memory leak on error in thermal_genl_auto() Daniel Lezcano
2024-10-24 11:01 ` Daniel Lezcano
2024-10-24 11:07 ` Lukasz Luba
2024-10-24 12:02 ` Markus Elfring
2024-10-24 12:57   ` Daniel Lezcano
2024-10-24 13:18     ` Rafael J. Wysocki
2024-10-24 13:27       ` Lukasz Luba [this message]
2024-10-24 14:21       ` Daniel Lezcano
2024-10-24 15:19         ` Markus Elfring
2024-10-24 16:54           ` Daniel Lezcano

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=f6ad24c8-0065-4d73-98f1-dc4246ca70ea@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=Markus.Elfring@web.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /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