The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	linux-kernel@vger.kernel.org, Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH 3/3] driver core: class: Delete a redundant check in APIs class_(for_each|find)_device()
Date: Tue, 12 Nov 2024 12:45:29 +0100	[thread overview]
Message-ID: <2024111230-diabetic-stubbed-102b@gregkh> (raw)
In-Reply-To: <20241105-class_fix-v1-3-80866f9994a5@quicinc.com>

On Tue, Nov 05, 2024 at 08:20:24AM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Delete redundant check (!@class) in both API class_for_each_device() and
> class_find_device() with below reasons:
> 
> - The check is covered by later check (!@sp).
> - Callers are unlikely to call both APIs with NULL class argument.
> - Make parameter check consistent with all of other class APIs.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/base/class.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/base/class.c b/drivers/base/class.c
> index e81da280af74..120d3aeb52fe 100644
> --- a/drivers/base/class.c
> +++ b/drivers/base/class.c
> @@ -408,8 +408,6 @@ int class_for_each_device(const struct class *class, const struct device *start,
>  	struct device *dev;
>  	int error = 0;
>  
> -	if (!class)
> -		return -EINVAL;
>  	if (!sp) {
>  		WARN(1, "%s called for class '%s' before it was registered",
>  		     __func__, class->name);

Now, if I pass in NULL for class, I get an odd warning, AND the kernel
crashes with the dereference of class->name.

So this is not ok :(

> @@ -456,8 +454,6 @@ struct device *class_find_device(const struct class *class, const struct device
>  	struct class_dev_iter iter;
>  	struct device *dev;
>  
> -	if (!class)
> -		return NULL;
>  	if (!sp) {
>  		WARN(1, "%s called for class '%s' before it was registered",
>  		     __func__, class->name);

Same here, this change is going to break things if people get it wrong,
please leave both of these as-is.

thanks,

greg k-h

  reply	other threads:[~2024-11-12 11:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  0:20 [PATCH 0/3] driver core: class: Fix bug and code improvements for class APIs Zijun Hu
2024-11-05  0:20 ` [PATCH 1/3] driver core: class: Fix wild pointer dereference in API class_dev_iter_next() Zijun Hu
2024-11-12 11:43   ` Greg Kroah-Hartman
2024-11-12 14:46     ` Zijun Hu
2024-11-12 14:57       ` Greg Kroah-Hartman
2024-11-12 15:05         ` Zijun Hu
2024-11-13 12:39         ` Zijun Hu
2024-11-05  0:20 ` [PATCH 2/3] driver core: class: Correct WARN() message in APIs class_(for_each|find)_device() Zijun Hu
2024-11-05  0:20 ` [PATCH 3/3] driver core: class: Delete a redundant check " Zijun Hu
2024-11-12 11:45   ` Greg Kroah-Hartman [this message]
2024-11-12 14:51     ` Zijun Hu

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=2024111230-diabetic-stubbed-102b@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_zijuhu@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=zijun_hu@icloud.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