Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2598022ybi; Thu, 4 Jul 2019 14:53:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXoPCs4JGvKpjnXDjurs1xTSgd+nK6/yTvm2nQkvd7osDjdSfBBobPqJCM6oAyELRL4QKw X-Received: by 2002:a17:90a:9289:: with SMTP id n9mr199309pjo.35.1562277198424; Thu, 04 Jul 2019 14:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562277198; cv=none; d=google.com; s=arc-20160816; b=blNx+G/ymBW0SfNq9pXamfS0Ms57hCzqOzU49KxVwEALlY/dHOipQ1FaYBANeyhkZ1 iM4+5tU4ID/6fHTcCY6DluyNR4VuoaFPZuDGzNdC2Zfk2NotFp9JtADkI+MamJzonNrm iMc/K9Qc6XUtf0GybZ7Akn04WtESARffZOnr/W0Otz91K3OoFh8lF21dDmBtq6sMGtTQ U1QVNj3VQ8d3pPRhoPMttOHDyHTWSlGBNU3jFDEVvIxrjbn/upeow5wnuJyIA5UJYvsc BNnGVFYGa4O8CMe4fJmtZryeu6AlUQhb9PTBd2ZFANasgqkUdDFp881fzMjuBVhPglub QZyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=J5dPnDAPBmP/tM3oNFl3Flqbnxl9DAbnY6d65OzlCvo=; b=WZKRa8NC7+kQsbyUedcO/2niXeaMt9vXNSK20xCQ2r1cquv2cr/4tsp2ke9PehvHJK i+4Sp8EvMxAD2eEqD7zn3hTB2EWCo0LV8lRAT7BtChTtYzSHVZFc1n3AMFOQVX3TmrhS YYzezR5VaOc/ENy6qD4DXPWa7ITXHcJT4YcPb8wX9vO2VzwqLLHJyKTP8Fj6G9Xq1Gjh mficCp7JQx1Nm78YK4c1KK+pQOssWXItqi7m1xNqe16PBRQbptXRdO/tV/hA7cotODxR 6YXzsGn5b4gkaFws0ns59hnEQykiWT4IHsq3hzXP5fmHBwgBYSmqMabnClMOElq0mS4s iWLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Gsi9+IiX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si6025690pga.320.2019.07.04.14.53.03; Thu, 04 Jul 2019 14:53:18 -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=@gmail.com header.s=20161025 header.b=Gsi9+IiX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727546AbfGDVRf (ORCPT + 99 others); Thu, 4 Jul 2019 17:17:35 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:35925 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbfGDVRf (ORCPT ); Thu, 4 Jul 2019 17:17:35 -0400 Received: by mail-io1-f67.google.com with SMTP id h6so15125700ioh.3 for ; Thu, 04 Jul 2019 14:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J5dPnDAPBmP/tM3oNFl3Flqbnxl9DAbnY6d65OzlCvo=; b=Gsi9+IiXPXqbpEbRKWtBGjqiJl9m0d/8ymXKcotU8ncCURfv40xEbz2dquZFw4or66 eIf/FYjcWJ/OdLG8r0pYQ6ol+nJ8onV7P+isl3lNeKOoJK+koxGBAfhUodRaCD15DV72 UDkaiZj6DeW8QLkJ9ELFAj1pDGsER3j6m7qCIQwUu/wBGznuarnpo8dX0UbaxEJ6XYfG nKVki5CAbgWkAHqs8Jow0JR+eeeQvoIuudtcafCdIFeEfK5P1FGVJADh2roLiMHnij8s iP+0csz198iwegCn04NbD+j+VcmFCDpDQ7Jauvcjc/rx+Q59DzgxwesL2oOL33n8CfXX aIEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J5dPnDAPBmP/tM3oNFl3Flqbnxl9DAbnY6d65OzlCvo=; b=sH1aAZ7MTYaBSKu1b9l8LG9edHbXwJsxUoZeqUpSFGp09Tsn1yQv+tQ7W30HS9Lqd4 BJu4/jJpvcGn85mYt3Kl3Uh1Kkur8FhHNxwNPl8JFCRyfQQ1DE42/DaN6/Yil1FD294Y vL/h+CReQcP6Sjm8IMjcn1CNq11ZKU42qRYLgr2qzmJGtIoF7cWNRnRDaQtH6527alSJ 7/mZO+mPGPjbC7BjMAOhlF6/kHAMa5GldPoUGLuQgGVaBGYNGglAyWjr/ucfuAzqeSiN FGIEP4MgE0v2w8s8Btv3AWx9p7SWb6mv6IV9SfMzrNIZQ61a10r6OJ6g49zzvI9Rte6b 6dyg== X-Gm-Message-State: APjAAAWGdRWMnkNXuYQxfHjG32l3SNrf7QfoGR7+zBy9+wPLoqz2DcR3 V0uORDHrzyOnFPuZQEm8q9kIsOYtImjojhsVU1M= X-Received: by 2002:a5e:8508:: with SMTP id i8mr444389ioj.108.1562275054349; Thu, 04 Jul 2019 14:17:34 -0700 (PDT) MIME-Version: 1.0 References: <20190704084617.3602-1-gregkh@linuxfoundation.org> <20190704084617.3602-2-gregkh@linuxfoundation.org> <20190704093200.GM13424@localhost> <20190704104311.GA16681@kroah.com> <20190704121143.GA5007@kroah.com> In-Reply-To: <20190704121143.GA5007@kroah.com> From: Dmitry Torokhov Date: Thu, 4 Jul 2019 14:17:22 -0700 Message-ID: Subject: Re: [PATCH 01/12 v2] Platform: add a dev_groups pointer to struct platform_driver To: Greg Kroah-Hartman Cc: Johan Hovold , lkml , Richard Gong , Romain Izard , "Rafael J. Wysocki" , Andy Shevchenko , Mans Rullgard , Bartosz Golaszewski , Randy Dunlap Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, On Thu, Jul 4, 2019 at 5:15 AM 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. Why is this limited to platform bus? Drivers for other buses also often want to augment list of their attributes during probe(). I'd move it to generic probe handling. > > Cc: Richard Gong > Cc: Romain Izard > Cc: "Rafael J. Wysocki" > Cc: Andy Shevchenko > Cc: Mans Rullgard > Cc: Bartosz Golaszewski > Cc: Randy Dunlap > Cc: Johan Hovold > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman > --- > v2: addressed Johan's comments by reordering when we remove the files > from the device, and clean up on an error in a nicer way. Ended up > making the patch smaller overall, always nice. > > drivers/base/platform.c | 16 +++++++++++++++- > include/linux/platform_device.h | 1 + > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index 713903290385..74428a1e03f3 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -614,8 +614,20 @@ 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) { > + if (drv->remove) > + drv->remove(dev); > dev_pm_domain_detach(_dev, true); > + return ret; > + } > + kobject_uevent(&_dev->kobj, KOBJ_CHANGE); We already emit KOBJ_BIND when we finish binding device to a driver, regardless of the bus. I know we still need to teach systemd to handle it properly, but I think it is better than sprinkling KOBJ_CHANGE around. Thanks. -- Dmitry