Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1948202ybi; Thu, 4 Jul 2019 02:34:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrO1cGq7e9Cmo47IHXqmpo/Xa9/ewd4XDVv5Ij+pd/1n+UQuSCxebW5GUNoY25WYfoeEtY X-Received: by 2002:a17:902:f082:: with SMTP id go2mr50539410plb.25.1562232858591; Thu, 04 Jul 2019 02:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562232858; cv=none; d=google.com; s=arc-20160816; b=bbp92eb/3kbBQqpsbECYIi9wwqQ63WIJFaI6BWnyALSYhcNHf6Phy+Ltkl6nN7JBg3 mZe/mlIOL2kfBhunobIcQ6lIKXWXGLvbpvdvFenD6crQA5V7pCytLDvu0VqbWZhGVgCz WtA7Z960C9MPrKEZ89VbLk4tOF7CLgEO96v+eh6zRzCrkSYu++MD6cVF8qqKj3CI+dlt 7MZHqWmz4XrEVbGwKben+8YFTMp5X9giTYNzZdE4Wp2eEllHPIVQCDBTNbrqu2qAMKox rNr90RTDWyAgcqQKk5W5hPtxrANLzLyU3KZ2MTnmJgTIDh4HHf90INPZrYtKvfCgAxvg b1Ng== 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; bh=Q6XWgf4aZOiZ9nBImvtuRI/cSLt8i5bschesBs6VcKI=; b=sJC58Y+yHOAx8jIyeoW+YWfmqpjs8Jd0WN7orVTpYuH7yuFniE7pY7wF9zSzADWxZQ 0Ov11teh6RDx4UQug1yOibR48mF9loqg0UW25YohJ6LFWR6or5USOC/f//zRqFZ5kQGX czVDfgqIJV26eH4X7MLh5qWDyuv6pT1YM314Ouat0M6YeFD4Ror7Kez7oY4h7YWeS0DL 926CQFAm7Aq0f52FtZ0SxdGoprQ3XWGUmw29ci1yC2SXQp8rzKz+SGRfIVdrRSsNybdo M8ZD8tsZSUi3keXdUNQQBTPfyA6wpzd5PuV4v7iahtOh5UNBbPj7V9/06v0LlSywHdWW VECA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fr1si4367936pjb.57.2019.07.04.02.34.03; Thu, 04 Jul 2019 02:34: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727320AbfGDJcI (ORCPT + 99 others); Thu, 4 Jul 2019 05:32:08 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37544 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727169AbfGDJcH (ORCPT ); Thu, 4 Jul 2019 05:32:07 -0400 Received: by mail-lf1-f68.google.com with SMTP id c9so2028599lfh.4 for ; Thu, 04 Jul 2019 02:32:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Q6XWgf4aZOiZ9nBImvtuRI/cSLt8i5bschesBs6VcKI=; b=tcrQ0AuB+flmyrISxJTDmemDr35ZE6wJfrq6afGOphARkd55Hh9+Ilc2ZZl9TTsF6A WuxIX9/f9I13/LiDLVR01Uz9W075jTvugbUylUABOAHGlrlIa5SkWQJ4ScoAODRgeCdF nY+0YvFvQZGGKf35P33FzjvlTB3lVtdX1R+VjEtdask2ucUXN9X8p1/ohzFSafPvL0ic p4WLvnBjzZT1yoHHjSVLCWBAWrVfGn6pE3W3Ghm6LB4iFsQEB06e2WvfvP/U8KtL8Hvd BVx7PVxBGAuIerx5Iam3uNB5mHnWbgn+AOKvvaOkQx2iZxWhivjZsrbuvhdO8cZelB6L k9pA== X-Gm-Message-State: APjAAAXapZoaELaHm8dH4suLgvV2H+++dOSp1+3bCIgEkOjkd2wdKEAW EkbYUf6utdS+ZU5hI9CaxEEjbOZNyyA= X-Received: by 2002:ac2:42ca:: with SMTP id n10mr8312091lfl.121.1562232725886; Thu, 04 Jul 2019 02:32:05 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id h11sm800946lfm.14.2019.07.04.02.32.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jul 2019 02:32:05 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92) (envelope-from ) id 1hiy5w-0006vk-Fs; Thu, 04 Jul 2019 11:32:00 +0200 Date: Thu, 4 Jul 2019 11:32:00 +0200 From: Johan Hovold To: Greg Kroah-Hartman 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: <20190704093200.GM13424@localhost> References: <20190704084617.3602-1-gregkh@linuxfoundation.org> <20190704084617.3602-2-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190704084617.3602-2-gregkh@linuxfoundation.org> 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 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. > + 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. > + return ret; > + } > + kobject_uevent(&_dev->kobj, KOBJ_CHANGE); > } Johan