From patchwork Tue Jul 21 13:50:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6836211 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6DBF4C05AC for ; Tue, 21 Jul 2015 13:54:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 819C1206B0 for ; Tue, 21 Jul 2015 13:54:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A14F206A0 for ; Tue, 21 Jul 2015 13:54:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXyH-0004rs-36; Tue, 21 Jul 2015 13:52:37 +0000 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXxs-0004gq-TL for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2015 13:52:13 +0000 Received: by wgkl9 with SMTP id l9so156895277wgk.1 for ; Tue, 21 Jul 2015 06:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=lEC6n9ml6XpXfgvp4P0lT4FScaH/87JNncO//GUMYQE=; b=IIj7JKZ2wQ+lE8rBpTadsBFWyqWHfJ/Qh0p2AFRozqnWy80/89NRXkTT/+C1uEOSch w5nu99NCzbeVA8+hOGr8j2XWFqgRKT87axWHGok2NEzTsU6kpaLUKtA5YnOSrFBEIYb+ yi+23sjyjN4tss/y1y0xI/QhT3oOAKNUR2Wpqg8f/11TS8Sl7CBSdZ9ujVWwMZo/u3RR PMAIV5xRc5QIM3oWqMJ3hm9G1XbiqArrjNs4QnP+7iHAksDskaQLvgPenPdBqzdrXNDe 0LKuI5MJFDiqIQeUTjFaVd0NvmFCJbpxN2BDimSweSiV4xqu5SITKHwb16zV0B9jGL5C 6j7g== X-Received: by 10.194.187.51 with SMTP id fp19mr63773845wjc.67.1437486711211; Tue, 21 Jul 2015 06:51:51 -0700 (PDT) Received: from cizrna.lan ([109.72.12.178]) by smtp.gmail.com with ESMTPSA id pf4sm37172056wjb.23.2015.07.21.06.51.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:51:50 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 02/16] add devm_acquire_resources() Date: Tue, 21 Jul 2015 15:50:44 +0200 Message-Id: <1437486658-28365-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> References: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150721_065213_115680_4E9EF16D X-CRM114-Status: GOOD ( 14.88 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Tomeu Vizoso , Stephen Warren , "Rafael J. Wysocki" , Mark Brown , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Tomeu Vizoso --- drivers/base/dd.c | 4 ++++ drivers/base/devres.c | 20 ++++++++++++++++++++ include/linux/device.h | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a638bbb1a27a..7f970ac11533 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -304,6 +304,10 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto probe_failed; } + ret = devm_acquire_resources(dev); + if (ret) + goto probe_failed; + if (dev->bus->probe) { ret = dev->bus->probe(dev); if (ret) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index c8a53d1e019f..0c6252921fd1 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -984,3 +984,23 @@ void devm_free_pages(struct device *dev, unsigned long addr) &devres)); } EXPORT_SYMBOL_GPL(devm_free_pages); + +int devm_acquire_resources(struct device *dev) +{ + const struct devm_resource *res; + int ret; + + if (!dev->driver || !dev->driver->resources) + return 0; + + for (res = dev->driver->resources; res->initfunc; res++) { + ret = res->initfunc(dev, res); + if (ret) { + dev_warn(dev, "%pf returned %d for resource '%s'/%d\n", + res->initfunc, ret, res->name, res->index); + break; + } + } + + return ret; +} diff --git a/include/linux/device.h b/include/linux/device.h index a2b4ea70a946..a1c3829152a1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,16 @@ enum probe_type { PROBE_FORCE_SYNCHRONOUS, }; +struct devm_resource { + int (*initfunc)(struct device *dev, + const struct devm_resource *resource); + ptrdiff_t offset; + unsigned int index; + const char *name; + void *arg; + unsigned int flags; +}; + /** * struct device_driver - The basic device driver structure * @name: Name of the device driver. @@ -278,6 +288,8 @@ struct device_driver { const struct dev_pm_ops *pm; + const struct devm_resource *resources; + struct driver_private *p; }; @@ -667,6 +679,8 @@ extern unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order); extern void devm_free_pages(struct device *dev, unsigned long addr); +extern int devm_acquire_resources(struct device *dev); + void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); /* allows to add/remove a custom action to devres stack */