Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2014112ybi; Thu, 4 Jul 2019 03:45:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFpBSKXOA+yqHcYMKaRa5SAmZ94HjSvOcmphYMspsIwkx1Z4cA8Ye4iT9+/naQDumFIQlL X-Received: by 2002:a63:d04e:: with SMTP id s14mr17087284pgi.189.1562237123373; Thu, 04 Jul 2019 03:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562237123; cv=none; d=google.com; s=arc-20160816; b=juS/AcxLSkAXHY2DPsZuQ7YrN/jBnq5WS7vR1M6oaonp+CaAijwRXVl9O036SwCxbU 4i03J1no8ZN8kC4jDiT+5hKzetxr3lXOSNM6PnulyiNf4HzKV1k23Eu6Wc5MzhlneKoQ aDDX9MPMPhT/enEVD8doy9uAyD7zIv8R8TFrzHeG62t3hiT+IccGDBSu7lr5TzhTHkYh kOQIRUQxAn6Mpcaxh+UfgDmOuUMI0F3ZQx7Vnwq01fWJmcZoHVvwtVGq9wVqXH9b4oUP whFtWeDTgrZd/QjdRFbMHML2tcGFdQRg7t4Z8ue4QYcY0LY8BWoSJmYp1tbcFOOQC5Vr ux/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=05Kvi4kcBGDYW9OnOWjV69deAbPesDXZcIDb4sKwhk4=; b=qi93hMtI+PhEWu1ilO2IIQgUW2Yw4blzJmzIUX7CWD0PPj0pc4jS3XREL+xYc0Q/NS u09XUHh4OxgS5PF8nzPY7CQyryDbojfk0igzSaHySocbobLSx6srrPdmnKO9xLWAfyRN 5am+p+OFyTh0DfsTHVYf5II+REdkV3Qn7arKFtCMEJ27mfScVy7RB+fKsrGj46vxUYYR Bow1zJRzApTZP3n0RbRdgSPB9nuK+eun0Xrsax19h5R1StTgbrNN8SKsTDfJIsyvo0ls eu7JN8wAUD3nu9LGkL3dkEB39fNBYsO299tpTG7jinCL/15AlAFER4LxJFJSyrM6gh/p 1p+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0nvDXObC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si5149850pgi.165.2019.07.04.03.45.08; Thu, 04 Jul 2019 03:45:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0nvDXObC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727542AbfGDKnQ (ORCPT + 99 others); Thu, 4 Jul 2019 06:43:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:35446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727385AbfGDKnP (ORCPT ); Thu, 4 Jul 2019 06:43:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DA4F218A3; Thu, 4 Jul 2019 10:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562236995; bh=GO5rZwACuqGJZLDo2ucr74UTZmdv8Bqm4fA6Yt770mw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0nvDXObCXpiy0YByYsTXgPkhBa2nJpAojxuoTqc8YKs7Tdb/KfqWxTSN9JWEPZkC2 JGSqqe7Tv+BGBQZVVpCgXVzG9SOu6HVSNR7qFDFNMuaNRlOJKN9SurghIVPofkSuu0 lfx6V1CG0YWaOybnG88fHy3OqtKCti8nWzOKX5rM= Date: Thu, 4 Jul 2019 12:43:11 +0200 From: Greg Kroah-Hartman To: Johan Hovold Cc: linux-kernel@vger.kernel.org, Richard Gong , Romain Izard , "Rafael J. Wysocki" , Andy Shevchenko , Mans Rullgard , Bartosz Golaszewski , Randy Dunlap Subject: Re: [PATCH 01/11] Platform: add a dev_groups pointer to struct platform_driver Message-ID: <20190704104311.GA16681@kroah.com> References: <20190704084617.3602-1-gregkh@linuxfoundation.org> <20190704084617.3602-2-gregkh@linuxfoundation.org> <20190704093200.GM13424@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190704093200.GM13424@localhost> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 04, 2019 at 11:32:00AM +0200, Johan Hovold wrote: > On Thu, Jul 04, 2019 at 10:46:07AM +0200, Greg Kroah-Hartman wrote: > > Platform drivers like to add sysfs groups to their device, but right now > > they have to do it "by hand". The driver core should handle this for > > them, but there is no way to get to the bus-default attribute groups as > > all platform devices are "special and unique" one-off drivers/devices. > > > > To combat this, add a dev_groups pointer to platform_driver which allows > > a platform driver to set up a list of default attributes that will be > > properly created and removed by the platform driver core when a probe() > > function is successful and removed right before the device is unbound. > > > > Cc: Richard Gong > > Cc: Romain Izard > > Cc: "Rafael J. Wysocki" > > Cc: Andy Shevchenko > > Cc: Mans Rullgard > > Cc: Bartosz Golaszewski > > Cc: Randy Dunlap > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Greg Kroah-Hartman > > --- > > drivers/base/platform.c | 40 +++++++++++++++++++++------------ > > include/linux/platform_device.h | 1 + > > 2 files changed, 27 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > > index 713903290385..d81fcd435b52 100644 > > --- a/drivers/base/platform.c > > +++ b/drivers/base/platform.c > > @@ -598,6 +598,21 @@ struct platform_device *platform_device_register_full( > > } > > EXPORT_SYMBOL_GPL(platform_device_register_full); > > > > +static int platform_drv_remove(struct device *_dev) > > +{ > > + struct platform_driver *drv = to_platform_driver(_dev->driver); > > + struct platform_device *dev = to_platform_device(_dev); > > + int ret = 0; > > + > > + if (drv->remove) > > + ret = drv->remove(dev); > > + if (drv->dev_groups) > > + device_remove_groups(_dev, drv->dev_groups); > > Shouldn't you remove the groups before calling driver remove(), which > could be releasing resources used by the attribute implementations? > > This would also be the reverse of how what you do at probe. Good point, probably doesn't really matter, but I'll reverse it. > > + dev_pm_domain_detach(_dev, true); > > + > > + return ret; > > +} > > + > > static int platform_drv_probe(struct device *_dev) > > { > > struct platform_driver *drv = to_platform_driver(_dev->driver); > > @@ -614,8 +629,18 @@ static int platform_drv_probe(struct device *_dev) > > > > if (drv->probe) { > > ret = drv->probe(dev); > > - if (ret) > > + if (ret) { > > dev_pm_domain_detach(_dev, true); > > + goto out; > > + } > > + } > > + if (drv->dev_groups) { > > + ret = device_add_groups(_dev, drv->dev_groups); > > + if (ret) { > > + platform_drv_remove(_dev); > > This would lead to device_remove_groups() being called for the never > added attribute groups. Looks like that may trigger a warning in the > sysfs code judging from a quick look. Hm, let me look at this some more...