From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B675210F75 for ; Fri, 10 Jan 2025 14:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736519520; cv=none; b=ZBhNDBINnpM4/e8AkcC6JaFlqXP3vga8v6tvAfT/H6d2FjV1WD8zrSArfRV6Hi0J5E7sW7feawS1fsTtnbFpHsX5vrNi14ZwIXO/yP7tKtVd3b9zDibe7pt3bUrTKn26ykXmLwCCblioKToDKTYwMxQoz52O5Rb5whRKixX5B8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736519520; c=relaxed/simple; bh=5QqMvmCjvxKAHbkd414xep3roRHGvDZjLXsg9da43oA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ucN5x/5moXUCO4ZDs4zpVAzqU/Gj1vVKFFCuFYKIeY1wdWUmVZnLY0EnBSpyvfCRVQaZd5KvxM67TzX8pG5feR2fZSaJznH2O9+DR7/1FxjbNyFWp3dZniTpeoZfUuFX19kPQhZ4vOgve5mechZkR/bGH7xT5UydnKSTTVZ3gN0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FggD0M+1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FggD0M+1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 302ACC4AF09; Fri, 10 Jan 2025 14:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736519519; bh=5QqMvmCjvxKAHbkd414xep3roRHGvDZjLXsg9da43oA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FggD0M+1NQSNc1L/j8ViaB+RJ3R011/Ona/MdQtwCkrF4sqACO02c+TsTs3p9Kf32 g7F8cAqsvh1kKSTPgibt/jPvKcGC3tUXRll9sTmXRSSUKjJkvgiY7OEIgjjnEVJQoK y1vN8FGjYALXGS9CiImHsyQi4vz7sy2YnIY1UVh8= Date: Fri, 10 Jan 2025 15:31:56 +0100 From: Greg KH To: Yaxiong Tian Cc: rafael@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers core: bus: Remove unnecessary NULL assignments in the bus_register() function Message-ID: <2025011012-placate-gracious-8cb4@gregkh> References: <20241129030130.3754-1-tianyaxiong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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