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 B9B9A19E992 for ; Tue, 12 Nov 2024 11:45:32 +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=1731411932; cv=none; b=ayjzdiFeGK+h1xQaaGIj8eaW2sQU09HRArby82PnGuCpEi55UE2fQo/yCTG3QuxjjYpfxutoyUxf5sW4AvHfSncvETFviU+12HByCsdMoAp8Htq4WkiPo+GbETgYkRW0MZhdij+psMe1qhDjOMiPviaoRa9Nr0h9O2e0XX2Rgqg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731411932; c=relaxed/simple; bh=7LI280z4fmODV2SHNnr/yWCyaQ36kuShQQJYP5jJPDY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iLexefG94En1H0JCXqan9x/xunN6YvUtOUmh2gtFuCNKdxEHzfLHu65goZA6B9hPHzMdBY4AlsR6YxbV5nEyNxThgW+P4/7XwJnxAGy16BmoVtoq9RZYrkqRfC2bIdQ+SJp4VMZfDkVIBJ34jHD+v7htvNSETv8oVXrVoQ9+0Qw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=O0pUXGRL; 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="O0pUXGRL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94087C4CECD; Tue, 12 Nov 2024 11:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731411932; bh=7LI280z4fmODV2SHNnr/yWCyaQ36kuShQQJYP5jJPDY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=O0pUXGRLhCM8PDVlopg/DMcLkRuFJEcBROtqMnyk8L9zXmUCuDrVys+qBiboT00ZV uaBGdTM0baEX8qXDeZ5bbT6Gy2hK0ArFAYczse+SLpJPwiaM8rk0zdoLyWNzymBifx yaF6SBO2dmMvIVYQRudiFwUkoaz3L/HpLczvx+as= Date: Tue, 12 Nov 2024 12:45:29 +0100 From: Greg Kroah-Hartman To: Zijun Hu Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Zijun Hu Subject: Re: [PATCH 3/3] driver core: class: Delete a redundant check in APIs class_(for_each|find)_device() Message-ID: <2024111230-diabetic-stubbed-102b@gregkh> References: <20241105-class_fix-v1-0-80866f9994a5@quicinc.com> <20241105-class_fix-v1-3-80866f9994a5@quicinc.com> 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: <20241105-class_fix-v1-3-80866f9994a5@quicinc.com> On Tue, Nov 05, 2024 at 08:20:24AM +0800, Zijun Hu wrote: > From: Zijun Hu > > 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 > --- > 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