Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2101220ybi; Thu, 4 Jul 2019 05:15:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUoCCnLHLrVUKsiE34YmvKXzPAQXAV6vqsnI7d6+sPfP164BU4WgK4ZpyYBi+bsQNMlVEW X-Received: by 2002:a63:2a0f:: with SMTP id q15mr44163600pgq.163.1562242519886; Thu, 04 Jul 2019 05:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562242519; cv=none; d=google.com; s=arc-20160816; b=cBrc0j/IM5l4UmfjrRHAslyNTIuvAKbrBIrlUbWu4VZv0gXWWXbuS9JLXgS9xPupno hq7cabM079JDrHQt+kZ+kOOrk23ahYP/CdDjaxWH/vNYR7i8e42SpRPj/xG4xgPF3stV 2I2IgxispHEK/9ZnNscBz6asigfrjss7Jl16yKM6Bri80Yg8Wyo5oL6tybY9YUqUxyXP VP7IKQNLQ7JHRs1EOV4y4107jK+qwWoBHNxTA0VYODKsmUqL49ovBOnq+EPbDwC/qwgJ 6lH0W3tYQZh8K4Nyl0obqQbwfgX+nfO8155ZAIQqWIKwc2vqBxEowb1X0i2xvr7BbHe1 Bt9Q== 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=e9T/t4YreeioqspyD6aLXo6nt07L3eLOENClaWcogUY=; b=zAYYAW3+aXyjjFy7NF9zorh9Sdi6gg56s15M+na2JQDApiOapoXDpLVLQvLxiSC1vE qm0NMFr6qdj5dGjbOmCh+vJxbcY7TbpeAECuqE7lsZMg0Wv76imlq0u1Q2gGrvNsvSX4 9MduhtcZ+Oa4lbL3vPAkRqwrOe0cxmKEk3Ahg/GEwhl+oX7gICHpuSEDKlNz4CUsMSTS cXELAmXst0CYq6D08yLu0VHw/KC+p0+t5Ir7LC7EI+LHmp3u4tGIOsY+wFXYx6M/+fHQ DbVI+3YaOl1XttNBFTnaZHmIQXMVcybMcj0CJUbH6WUb14Qwtz8C/6DA8EY60cOksmwZ RUtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T42g+aCD; 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 f1si5285487pgo.517.2019.07.04.05.15.04; Thu, 04 Jul 2019 05:15:19 -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=T42g+aCD; 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 S1727684AbfGDMOf (ORCPT + 99 others); Thu, 4 Jul 2019 08:14:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:38568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbfGDMOe (ORCPT ); Thu, 4 Jul 2019 08:14:34 -0400 Received: from localhost (unknown [89.205.128.15]) (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 3D3CE2189E; Thu, 4 Jul 2019 12:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562242474; bh=BS6LHDQQf9/yApkc167DvFPp/dm0Nvl/xbr6rW/uOMk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T42g+aCDmCVC6bfEvGPCpvXwZ1ofsiUI9KeQsI2FzhxjqAtzdZPhda/+PfapxY9/v JrqQHUgMUJn1YU3r6uLtE7RGyGh5uqLlpy3NkPf6pm2PsjiXG7SvTyE8hAAJntIo6+ hlTth0h0LLcT1J8nkxC4ZeRwv4KYeeP7GjPSbnas= Date: Thu, 4 Jul 2019 14:11:43 +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: [PATCH 01/12 v2] Platform: add a dev_groups pointer to struct platform_driver Message-ID: <20190704121143.GA5007@kroah.com> References: <20190704084617.3602-1-gregkh@linuxfoundation.org> <20190704084617.3602-2-gregkh@linuxfoundation.org> <20190704093200.GM13424@localhost> <20190704104311.GA16681@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190704104311.GA16681@kroah.com> 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 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: 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); } out: @@ -638,6 +650,8 @@ static int platform_drv_remove(struct device *_dev) struct platform_device *dev = to_platform_device(_dev); int ret = 0; + if (drv->dev_groups) + device_remove_groups(_dev, drv->dev_groups); if (drv->remove) ret = drv->remove(dev); dev_pm_domain_detach(_dev, true); diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index cc464850b71e..027f1e1d7af8 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -190,6 +190,7 @@ struct platform_driver { int (*resume)(struct platform_device *); struct device_driver driver; const struct platform_device_id *id_table; + const struct attribute_group **dev_groups; bool prevent_deferred_probe; }; -- 2.22.0