All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Yaxiong Tian <tianyaxiong@kylinos.cn>
Cc: rafael@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers core: bus: Remove unnecessary NULL assignments in the bus_register() function
Date: Fri, 10 Jan 2025 15:31:56 +0100	[thread overview]
Message-ID: <2025011012-placate-gracious-8cb4@gregkh> (raw)
In-Reply-To: <20241129030130.3754-1-tianyaxiong@kylinos.cn>

On Fri, Nov 29, 2024 at 11:01:30AM +0800, Yaxiong Tian wrote:
> In bus_register(), Priv is a local pointer variable, so its assignment
> can be ignored and the function can be returned directly. This can reduce
> the NULL checks in the subsequent kfree function.
> 
> Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
> ---
>  drivers/base/bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 657c93c38b0d..c1fd2860e397 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -923,7 +923,7 @@ int bus_register(const struct bus_type *bus)
>  bus_uevent_fail:
>  	kset_unregister(&priv->subsys);
>  	/* Above kset_unregister() will kfree @priv */
> -	priv = NULL;
> +	return retval;
>  out:
>  	kfree(priv);
>  	return retval;

The goal here was to fall down through the out: block, which is why priv
was set to NULL.  So the code is correct as-is, no need to change
anything here as that would just be a preference change from what the
original author wanted with no functional change at all.

thanks,

greg k-h

      reply	other threads:[~2025-01-10 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29  3:01 [PATCH] drivers core: bus: Remove unnecessary NULL assignments in the bus_register() function Yaxiong Tian
2025-01-10 14:31 ` Greg KH [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=2025011012-placate-gracious-8cb4@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=tianyaxiong@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.