From patchwork Tue Jul 21 13:50:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6836251 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 688EFC05AC for ; Tue, 21 Jul 2015 13:55:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2B16206A4 for ; Tue, 21 Jul 2015 13:55:04 +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 1294520693 for ; Tue, 21 Jul 2015 13:55:03 +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 1ZHXyR-0004vY-Ah; Tue, 21 Jul 2015 13:52:47 +0000 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXxu-0004gu-4N for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2015 13:52:15 +0000 Received: by wgmn9 with SMTP id n9so157190933wgm.0 for ; Tue, 21 Jul 2015 06:51:52 -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=n33yvnWpijrN7t2ImavylEHM8zBOFJmE03JJQ71el+Q=; b=rvMtzQ0yhxSGCnAXv/jjVCpEjyuovC3CQG1qcGyLHDMlB1y4cjzSLqQTzSNvTbi7V+ sS1iOU4/di7SOHRGwVkXLoACHZPZYbAy8y/Mcx0ItLpqadJIkv46ws46JcIOh3TvlOYF UE4dypomK/yKWgwaNxiKmcvQeJ1DqIOohEVxuN5LCenFfjT6UKyaFxfp1R0PsFhsuc6m 8AH6ROj/VyapK5OPhhIFT+VVTR4g3YG9ONt/Ed4a9MVgnUNPq5Y0TQhS/11OWyZFG/iQ nHxrz4Lx638nYeRBXK38ZRT93lRackvb3NUgwTk7GhH49XRlvNjQrnPekmqGVjYkRDYe R8pg== X-Received: by 10.194.58.167 with SMTP id s7mr67948092wjq.38.1437486712463; Tue, 21 Jul 2015 06:51:52 -0700 (PDT) Received: from cizrna.lan ([109.72.12.178]) by smtp.gmail.com with ESMTPSA id pf4sm37172056wjb.23.2015.07.21.06.51.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:51:51 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 03/16] Add DEVM_ALLOC() Date: Tue, 21 Jul 2015 15:50:45 +0200 Message-Id: <1437486658-28365-4-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_065214_355552_28F3C9E3 X-CRM114-Status: GOOD ( 12.40 ) 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/devres.c | 30 ++++++++++++++++++++++++++++++ include/linux/device.h | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 0c6252921fd1..5198ccd28123 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -1004,3 +1004,33 @@ int devm_acquire_resources(struct device *dev) return ret; } + +/* + * this must be the called before any of the others, or not at + * all, if dev_set_drvdata() has already been called. + */ +static void devm_resource_alloc_release(struct device *dev, void *res) +{ + dev_set_drvdata(dev, NULL); +} + +int devm_resource_alloc(struct device *dev, + const struct devm_resource *resource) +{ + struct devres *dr; + + if (dev_get_drvdata(dev)) + return -EBUSY; + + dr = alloc_dr(devm_resource_alloc_release, resource->offset, + GFP_KERNEL | __GFP_ZERO); + if (unlikely(!dr)) + return -ENOMEM; + + dev_set_drvdata(dev, dr->data); + set_node_dbginfo(&dr->node, "devm_resource_alloc", resource->offset); + devres_add(dev, dr->data); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_resource_alloc); diff --git a/include/linux/device.h b/include/linux/device.h index a1c3829152a1..c2bbee6b60ad 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -681,6 +681,12 @@ extern void devm_free_pages(struct device *dev, unsigned long addr); extern int devm_acquire_resources(struct device *dev); +extern int devm_resource_alloc(struct device *dev, + const struct devm_resource *resource); + +#define DEVM_ALLOC(_struct) \ + { .initfunc = devm_resource_alloc, .offset = sizeof(struct _struct), } + void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); /* allows to add/remove a custom action to devres stack */