public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers core: bus: Remove unnecessary NULL assignments in the bus_register() function
@ 2024-11-29  3:01 Yaxiong Tian
  2025-01-10 14:31 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yaxiong Tian @ 2024-11-29  3:01 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel, Yaxiong Tian

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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers core: bus: Remove unnecessary NULL assignments in the bus_register() function
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-01-10 14:31 UTC (permalink / raw)
  To: Yaxiong Tian; +Cc: rafael, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-10 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox