From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79C133195FB for ; Thu, 23 Apr 2026 17:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776965547; cv=none; b=XuaLMxv5aebfch8+SjupfkJ+eBLzZvRHIZSuLqzChvII+P1EtTBUjS0m46/h/RyUi+E+1pmPGldZf65H5tkFSh7Z35uRuRSZD3XcKkgBxPSEGoWS7XN6QjmFIBZmMyzytn4hx068zhwJSKUG0NE37rYDAwFraRKqlZa4eQ+KVXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776965547; c=relaxed/simple; bh=+Wh9eb+A8Yt7HINMKgqBsRte1iTr1zfqo7kXXSP+mWk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D/d2dUkHoQxo4aQqMEkngiE1zB5GPm0ARMGcbg0O7ewSjBffRh9TbCfowqMlV6rUme0TXKGiP33oiUC805hEElU6su2b8GXOQa1JYJDvuUxYLqQp2FExRk7JPTdwKVo+BnWgK3FSZlFRAhsquvFq189O2Q2mInbCbSDepx+Y9zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m/nVZC7I; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/nVZC7I" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2d868d014a5so6780391eec.1 for ; Thu, 23 Apr 2026 10:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776965546; x=1777570346; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=roTEmQN+Ir7L0cfKfGP/6yejCPhHvoS90pxDwlZRW90=; b=m/nVZC7IShZpa5uODo5abqAwO7vJiNoBYq7i3bqPlGdF/RWewqfPlwMF4FeckOYisP qbYXlncUov01FbXzwC3i86CwQrVKLGi2K2tdw90Jz3O25uHYvlErUwBbyMLNsyHtrMz2 RHoyteJff6aTpaNMpAHL8EG0qwqqLcTe7nK5gi7AX9gdBeh5rY0h3ekWM0YB+S/fwWfo buB3NXxhGpAByv8GkEX6f9d4EES67V/S9WrwhTXXLT7xIAeRWoIxQYnWbPWSH3rSSxmu JqGZBeIEG2ubM2yBFzRTfyXf+WQgD5d0KN9adh7ce8W2HyvRYvmXexNSRG54fcjFo5XL KmqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776965546; x=1777570346; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=roTEmQN+Ir7L0cfKfGP/6yejCPhHvoS90pxDwlZRW90=; b=NgB+lKCJhT9WcHY4kTUIfnnJ7dlmL7Oz/2bfkvT3ZWP2mTexo7ehO/4N3HVRVjIM0t jeDR2Wtyryln1J48AlPNQOBPIbnQTIFymJb1tbC7cQCZczoAMDblXDIEAzcFD5L7NjTp GSgC1AryPGISxx//UxrDfNQeCdbms6PFTAGhmgI/MvsKKELX4uZrKdRtIboQTNFuOGa7 K29MDyJGucNAns2KOZi7L3728bi1HuPolohGB6VcdRt6RGyPmDZc5Q0fZ6fRI16h5sTN UH7rQFZexti565yECqXYgmHSvaycbbCH1sIlz+OFGLaNqi2LdkDgtpB1w4NqN0SlfBAT +6oA== X-Forwarded-Encrypted: i=1; AFNElJ/hTdxgM0VwuI+655rDxepY/16MN6vH5A2WXC8ED5uEZM2tin1n4L8cK/WqTC9WeQ6jSneWcGj0B4FH2N4=@vger.kernel.org X-Gm-Message-State: AOJu0YxIfiGn7clggbe77NaGLWjqxOAZ/m4Fc1SBqbGjMVg/35ZPIYK1 PmdQueCGrZwimvRrzF8yjYEjpBrsjdfp6VyqAsn3mEzrznRrmRUkLwQb X-Gm-Gg: AeBDievennUF21y5bUcqx5+B+LD8YG7H2svcpUAYOaMsMNQ5X0ChoO3ZGzFQJkH2oeu jwFKAlpse4vCb9/VhHNz9hnpjej253mSc/Ul8jv6t2iMiMwk7FgaGi14YZO2zFzOgDAg13Y7F7K gXjSzYP2znigWmBK1XS/PflCFwJoVc1zzPw639MB049VONenXXrKSAoQN4izg4CbDZfBY5gToVP kKBdjd4McrRx3KSopc58Qbs7ymj0VLQ/URLjdab9Rzxmhz2O6onm2Mv4x6CTfFyba3sTCJKGaw+ BtVGXIrSHcw3R93tpT9a1DNhPfzR70repvEQLtcEcPSgEYo+peVOpan9Y+6jeNtXZMyUambSBTQ fyISj1T2XV9Nqb1UAo5GKLa0iRQL7F7M2VcWvZns/9BCw3QkIYeobCxt2VDPnVsB3kE7iho0Xhy +QLIRsDBIkHSA5xuw4pjf8kT1Mv0VuZ1XNsqDLM37qAqXn4oXuWw7Ct0RkLP6/DregU0/dbNsjH MI= X-Received: by 2002:a05:693c:2c0f:b0:2d3:4252:b127 with SMTP id 5a478bee46e88-2e479017537mr14873358eec.26.1776965545353; Thu, 23 Apr 2026 10:32:25 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:2359:5fa4:9c29:41b1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53d9b056fsm37264351eec.29.2026.04.23.10.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 10:32:24 -0700 (PDT) Date: Thu, 23 Apr 2026 10:32:21 -0700 From: Dmitry Torokhov To: Bartosz Golaszewski Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Brendan Higgins , David Gow , Rae Moar , Andy Shevchenko , brgl@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Subject: Re: [PATCH v2 1/3] driver core: platform: remove software node on release() Message-ID: References: <20260423-swnode-remove-on-dev-unreg-v2-0-0e5213cde2ed@oss.qualcomm.com> <20260423-swnode-remove-on-dev-unreg-v2-1-0e5213cde2ed@oss.qualcomm.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: <20260423-swnode-remove-on-dev-unreg-v2-1-0e5213cde2ed@oss.qualcomm.com> On Thu, Apr 23, 2026 at 02:12:02PM +0200, Bartosz Golaszewski wrote: > If we pass a software node to a newly created device using struct > platform_device_info, it will not be removed when the device is > released. This may happen when a module creating the device is removed > or on failure in platform_device_add(). > > When we try to reuse that software node in a subsequent call to > platform_device_register_full(), it will fails with -EBUSY. Add the > missing call to device_remove_software_node() in release path. > > Make sure that we still function correctly if a software node is used as > the primary firmware node. > > Fixes: 0fc434bc2c45 ("driver core: platform: allow attaching software nodes when creating devices") > Signed-off-by: Bartosz Golaszewski > --- > drivers/base/platform.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index 75b4698d0e582e67adafa78c312d75c72fd654cf..43ea7dcd338dd3ddae57e6d0677e5cb2673f6ed5 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -599,6 +599,7 @@ static void platform_device_release(struct device *dev) > struct platform_object *pa = container_of(dev, struct platform_object, > pdev.dev); > > + device_remove_software_node(dev); > of_node_put(pa->pdev.dev.of_node); > kfree(pa->pdev.dev.platform_data); > kfree(pa->pdev.mfd_cell); > @@ -885,6 +886,16 @@ struct platform_device *platform_device_register_full(const struct platform_devi > goto err; > } > > + /* > + * If the primary firmware node is a software node and there's no > + * secondary firmware node, the primary will be affected by the call > + * to device_remove_software_node() in platform_device_release() and > + * its reference count will be dropped by one. Take another reference > + * here to make it have no effect. > + */ > + if (is_software_node(pdevinfo->fwnode) && !pdevinfo->swnode) > + fwnode_handle_get(pdevinfo->fwnode); It is possible to pass already registered node in pdevinfo->swnode (because device_add_software_node() can handle this just fine). In this case we also need to take an extra reference (or figure out whether we need to drop the reference when removing the device). Thanks. -- Dmitry