Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1906061ybi; Thu, 4 Jul 2019 01:47:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwqSCjv5iOT/Aafdkwsbct5cE5ZCD7ouC4TP9Yn8TGYT3YNyrvaNtF/ph2heLCSnkW3Jio X-Received: by 2002:a17:90a:601:: with SMTP id j1mr18045426pjj.96.1562230043694; Thu, 04 Jul 2019 01:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562230043; cv=none; d=google.com; s=arc-20160816; b=uuL6HK7zeuaRYQrmQV2F1x596FBhlm6gFBS2tzmyxT5OjrpmLWkqJBYqnetqfRUt6o v7mJBxAY/No4hcHbTF2TFjOG0ariDP0PD6PFhwE/EPA1lYaXDkBrOI4F4H0VHieby1Ei MytF9XgXHFE3atUM+AJunSQ+aIEA9tiNGoM8XNJC5GJ9iOWNpC2mGdIhsrq/WsBK6emi 4yArXzWHVrEvqDilSR0iRRmdSsGZL55HIxJhQApvTpSyRJzxky+gandl8mGnpf6oJy3k pWjzZ5GrKoQU+/dY+BkDPMom9kW+OhaMySax2LmYt5h1W2WO9RNr0j5Wmz5SYFZBnDth u2Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zvGwYJstlVsaiheSC5YjWc35fyYjJd9JBuZl9mJc4Wg=; b=udtnzQKihEkHG3YIgHaShwoXTEzUJuCu1rnBfJnF0SR2qbLO16xma+7nL6oRnDjH5v O0bRMnYC93aP0nnudVRy0X1pOADc4fNeDdqYzGn+FUleoDQMtpjLwkwRE2O/ScK2m5Wd luPlZBoMw4iJ5VisZVjdkCevCVsBY2Y10U0tVfYAxPUSw3ccfW4GMYT1sKcxONHdVVpW lUKlHjtUNk50s6YTL8ITdFNWDacezEvsNuYUfNutssUsY7aSUZSvZx4fOyWAaHdNt12K jL77d0Z2R9J8eGlMxNFw0ISV8L+EPq9Aa6om5ttP+4/H/YyFgtDTJDZRfZVsvob9GwfE ApKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ey4q4tyK; 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 f5si4972725pgq.137.2019.07.04.01.47.08; Thu, 04 Jul 2019 01:47: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=Ey4q4tyK; 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 S1727234AbfGDIqk (ORCPT + 99 others); Thu, 4 Jul 2019 04:46:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:53624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727046AbfGDIqk (ORCPT ); Thu, 4 Jul 2019 04:46:40 -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 ABCE8218A0; Thu, 4 Jul 2019 08:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562229999; bh=1gMIyrG8zz1L+WGLjYc1vTwxG3KfgSDuIVw1K4VZDhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ey4q4tyK5k8N8IQJP5Ft1BVL9Bqo2dA69gHM4fSA1UTtJMRgysawqsaiCACK7GkBd t2z6cFLXdKm/D/tkoa9QzPt+EDnCvhSYEXJKb3GsG8jiSw6ShRHV/p3vByNNDAl5Rq BoJQpokuB7u+hZphY3a5sgR0q2SdB00LNQd6CIQk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Richard Gong , Romain Izard , "Rafael J. Wysocki" , Andy Shevchenko , Mans Rullgard , Bartosz Golaszewski , Randy Dunlap Subject: [PATCH 01/11] Platform: add a dev_groups pointer to struct platform_driver Date: Thu, 4 Jul 2019 10:46:07 +0200 Message-Id: <20190704084617.3602-2-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190704084617.3602-1-gregkh@linuxfoundation.org> References: <20190704084617.3602-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 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); + 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); + return ret; + } + kobject_uevent(&_dev->kobj, KOBJ_CHANGE); } out: @@ -632,19 +657,6 @@ static int platform_drv_probe_fail(struct device *_dev) return -ENXIO; } -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); - dev_pm_domain_detach(_dev, true); - - return ret; -} - static void platform_drv_shutdown(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); 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