From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792514695; b=eCSsr4ZVPsiGEqgrMqwI2UuFucrLlUu1KB53b+dGjz7aaVPbmkcBTh/XpGzKLzjLBG6r dri0or7046XGeLl7We9dHqHyLw469YmIS73eQCAGtrZEy8j0FbK8kfeKTE7OcAOCVV7jA IM0hodVLRD/PC1G+S6bGkgx7PgUceRsXaNOVFVLo319mePcW6DQ2k8SXGi6HAd1nJ8P7U 5D1DVy+Ch8QL/Nkt+jSMjRj0Fooqe28qVGbOaQOWSMMr8b/U/ctIa+SvxfXq8NpIEvx1I VxUN2EjXBor/xfXW7C5OJc3axugCjf4BqitZNRCW3zc+j1GxFP8e9wnVPML5voXRXuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792514695; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=S4w5b49VFjE4E0AFoA0Qcj7jylDcxSilk3hvFC5nqKA=; b=bWl4nd9v3Oe0j9KYgebl/vXr3kHG8clC1hkUSTcmZfyYkFUMHHZJZod9CUY8tEINy8w4 bOcN2ogRrcT/+N61KPBPfBHhxV2cykkOeKXhYTMzmsFPA8BR1NioPN4R14vvTHmLQvKkk MT9hMRkAXu+c12c07MMj+rdZIScyvlVVkgRMHf5rH4Mdi8RikAdXqnZ7a5pfoWl8gulaA nzUyrH43MfjLKXXBMDpApSeXPdjRAsA98cdAGBnpVuNAvrz7KqVQlD9Qtl9wz0oxCSHqs +KJBPB5rpSghbuZ0fZTAK+LtNx0WLCbZwAHKND890Uw+mfce+VDQ+7vqtOfBM7jCv6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VTs9jlmw; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A5CF606A32D for ; Tue, 20 Oct 2026 16:44:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7A5CF606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VTs9jlmw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792514693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S4w5b49VFjE4E0AFoA0Qcj7jylDcxSilk3hvFC5nqKA=; b=VTs9jlmwe4+YcVXpM6c2MwfagFD1mjPfARIV84MnOakXvsXivhlWeNKTRex9K7ZW/5uOTg aji0qe30uHvqX7sgBOTWywp2I96LewwEpJybvFXMx/947EQ0Bcb4yv+pisCzQM06U/DOSW 4z3rkA50Y/xMreefvtIVNNVXixQirQY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-5sh1AwVvPRS44L_W8R8Rlg-1; Tue, 20 Oct 2026 12:44:51 -0400 X-MC-Unique: 5sh1AwVvPRS44L_W8R8Rlg-1 X-Mimecast-MFC-AGG-ID: 5sh1AwVvPRS44L_W8R8Rlg_1792514689 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84BEB1954185; Tue, 20 Oct 2026 16:44:48 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3236930002CD; Tue, 20 Oct 2026 16:44:44 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 1/9] driver core: rely on put_device to free dev->p Date: Tue, 20 Oct 2026 12:44:27 -0400 Message-ID: <20261020164435.80499-2-djeffery@redhat.com> In-Reply-To: <20261020164435.80499-1-djeffery@redhat.com> References: <20261020164435.80499-1-djeffery@redhat.com> X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 From: Tarun Sahu device_add allocate private_data for device and assigns to dev->p. If device_add fails in later steps of the function, it cleans up this dev->p which is not necessary because In the next call, put_device free it anyway (if reference to the device is 0 which will be unless someone concurrently get the reference to this device). This avoids unnecessary races introduced in system. After device is added in device_kset->list by device_add and later steps in the device_add function failures occur, it will free dev->p manually, while in between there might be a user of device_kset->list will take reference to the device just added by device_add. and might try to access dev->p. So relying on put_device to free dev->p prevents such problem. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4c0c373998a1..83263e3fa5d4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2618,6 +2618,7 @@ static void device_release(struct kobject *kobj) struct device *dev = kobj_to_dev(kobj); struct device_private *p = dev->p; + dev->p = NULL; /* * Some platform devices are driven without driver attached * and managed resources may have been acquired. Make sure @@ -3828,8 +3829,6 @@ int device_add(struct device *dev) parent_error: put_device(parent); name_error: - kfree(dev->p); - dev->p = NULL; goto done; } EXPORT_SYMBOL_GPL(device_add); -- 2.55.0