From: Lee Jones <lee@kernel.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-leds@vger.kernel.org, kernel-janitors@vger.kernel.org,
Pavel Machek <pavel@ucw.cz>, LKML <linux-kernel@vger.kernel.org>,
cocci@inria.fr
Subject: Re: [PATCH] leds: trigger: oneshot: One function call less in pattern_init() after error detection
Date: Thu, 11 Jan 2024 10:41:09 +0000 [thread overview]
Message-ID: <20240111104109.GB1665043@google.com> (raw)
In-Reply-To: <c73761c5-7150-4f20-9b3e-1da680400250@web.de>
On Tue, 26 Dec 2023, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 26 Dec 2023 22:02:08 +0100
>
> The kfree() function was called in one case by
> the pattern_init() function during error handling
> even if the passed variable contained a null pointer.
It's totally valid to call kfree() on a NULL pointer:
* If @object is NULL, no operation is performed.
Why do we care all that much?
> This issue was detected by using the Coccinelle software.
>
> Thus use another label.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/leds/trigger/ledtrig-oneshot.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c
> index bee3bd452abf..31061ec0afe6 100644
> --- a/drivers/leds/trigger/ledtrig-oneshot.c
> +++ b/drivers/leds/trigger/ledtrig-oneshot.c
> @@ -134,7 +134,7 @@ static void pattern_init(struct led_classdev *led_cdev)
>
> pattern = led_get_default_pattern(led_cdev, &size);
> if (!pattern)
> - goto out_default;
> + goto out_settings;
>
> if (size != 2) {
> dev_warn(led_cdev->dev,
> @@ -151,6 +151,7 @@ static void pattern_init(struct led_classdev *led_cdev)
>
> out_default:
> kfree(pattern);
> +out_settings:
> led_cdev->blink_delay_on = DEFAULT_DELAY;
> led_cdev->blink_delay_off = DEFAULT_DELAY;
> }
> --
> 2.43.0
>
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2024-01-11 10:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-26 21:08 [PATCH] leds: trigger: oneshot: One function call less in pattern_init() after error detection Markus Elfring
2024-01-11 10:41 ` Lee Jones [this message]
2024-01-11 12:03 ` Markus Elfring
2024-01-11 13:05 ` Lee Jones
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=20240111104109.GB1665043@google.com \
--to=lee@kernel.org \
--cc=Markus.Elfring@web.de \
--cc=cocci@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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