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 2A8DF1917ED for ; Sat, 15 Nov 2025 20:16:47 +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=1763237810; cv=none; b=XggyAbYKe1V76nXmG4CX6HfGj6ydwfh6mwwlx9vp/3apolGjcUdjrdAvQdldym05iCyldXjJVoStfS20fYtyWxh6MeXRd0dLBBCFAX9wxanB6PEorGh+G800+/dfltTasdLGslRD/7XX1PSto0VnQT4eO85AJTmSNzUhcL+34Fg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763237810; c=relaxed/simple; bh=V56i0y8WDPz8m4MYT202NXOQG2gTnuug0QHth8GCw0w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eddg2qBxfGavl0RLcIIAfvoQaGdc1CDcUEJdqvH20kH2vcPoH6VMGydY0zrPGefum1n2lLnY1O2zocLko/dKsKx/C5Vy/ItMPtmm7slADZgwkiUpadx2TCoXCXy7d5fnW6p+4EkpaKUz5+xAj3S+JH5GOJIXjYnM77xid9brGvk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0H8X7mNN; 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="0H8X7mNN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C0B2C4CEF7; Sat, 15 Nov 2025 20:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1763237807; bh=V56i0y8WDPz8m4MYT202NXOQG2gTnuug0QHth8GCw0w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0H8X7mNNc7HYPWpjC8oP0pvg77wppJEK5IYFc2+oQBgqdH4VBM8Bl0nMnQBLFzBBL 5RS9/HE0uB8OzdlkUSQy2YxxJtNsIWPD9iHLH+5qGjOAM68cO+OAq1Q/4+ELG9Pqms Vek7ownswas2fjESc7LjUZU2SNugJvko1wF7jcH8= Date: Sat, 15 Nov 2025 15:16:43 -0500 From: Greg KH To: Zhengqiao Xia Cc: rafael@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] device_core: check null pointer Message-ID: <2025111523-preface-scoreless-b478@gregkh> References: <20251114141821.416835-1-xiazhengqiao@huaqin.corp-partner.google.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: <20251114141821.416835-1-xiazhengqiao@huaqin.corp-partner.google.com> On Fri, Nov 14, 2025 at 10:18:21PM +0800, Zhengqiao Xia wrote: > Add null pointer check to avoid null pointer. > When the USB device's interface is disabled, 'device_add' will not > be called, and 'dev->p' will be NULL. Wait, how does that happen? Shouldn't we prevent that? > When you use 'usbdev_ioctl' to > call this USB interface at this point,'__device_attach' will be invoked. > Then a null pointer will be generated. > > Signed-off-by: Zhengqiao Xia Not a valid email address :( > --- > drivers/base/dd.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > index 3328101e0e106..cfdeb420fd12a 100644 > --- a/drivers/base/dd.c > +++ b/drivers/base/dd.c > @@ -1033,7 +1033,7 @@ static int __device_attach(struct device *dev, bool allow_async) > bool async = false; > > device_lock(dev); > - if (dev->p->dead) { > + if (dev->p && dev->p->dead) { If dev->p is NULL here, something else went wrong with the caller, please, let's fix the root problem here instead. What suddenly changed to cause this to happen? thanks, greg k-h