From patchwork Tue Mar 10 10:15:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Gonzalez X-Patchwork-Id: 11429065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D5C81800 for ; Tue, 10 Mar 2020 10:19:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 43B37222D9 for ; Tue, 10 Mar 2020 10:19:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VF4Tuh9s" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43B37222D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=free.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:From:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cNvCidIJ4p/wl+C/0GikvpfMfOO73kKEsd7Ovb6ZWjw=; b=VF4Tuh9s5UB4PC p6glcd+vSz0n9S66JSQ3u1d+RCwCcZSXtUBtv1/tML3QHkKExoO6Sw7zQ2Dd/OGO8AzP0QC+0tqG8 vuCUDRnlERuy6j2Jvdcv7+nqqOKyroS5L75n766gD5hOKI1U17JMglXH0/v2aid3IhtF1aPJEWvDD M2AE2VS4RTYp4LgTwD2v54h4ECFbmed5jAwPRw7Y83L6RSqNVsh5ry5FSQY8OBOAOGRMiUMHse83o y12PRxc6p9hyPydr5th1Zm+FoRL9YeIicPJQBVzh8wTwStipqFl8shU1ckbG/OFmAOEXIxf4iAGtw /tIaIm+FsA+HIYP2KeUQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBbzD-0007Qp-3A; Tue, 10 Mar 2020 10:19:43 +0000 Received: from ns.iliad.fr ([212.27.33.1]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBbzA-0007Ok-1X for linux-arm-kernel@lists.infradead.org; Tue, 10 Mar 2020 10:19:41 +0000 Received: from ns.iliad.fr (localhost [127.0.0.1]) by ns.iliad.fr (Postfix) with ESMTP id 3851D20020; Tue, 10 Mar 2020 11:19:33 +0100 (CET) Received: from [192.168.108.51] (freebox.vlq16.iliad.fr [213.36.7.13]) by ns.iliad.fr (Postfix) with ESMTP id 23F5C1FF7A; Tue, 10 Mar 2020 11:19:33 +0100 (CET) Subject: [PATCH v5 1/2] devres: Provide new helper for devm functions From: Marc Gonzalez To: Stephen Boyd , Michael Turquette , Kuninori Morimoto , Russell King , Sudip Mukherjee , Dmitry Torokhov , Guenter Roeck , Bjorn Andersson , Robin Murphy , Geert Uytterhoeven , Arnd Bergmann , Ard Biesheuvel , Greg Kroah-Hartman , Rafael Wysocki , Suzuki Poulose , Mark Rutland References: Message-ID: <0b5c5f40-9118-1b87-6cf4-928107ccd20e@free.fr> Date: Tue, 10 Mar 2020 11:15:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Virus-Scanned: ClamAV using ClamSMTP ; ns.iliad.fr ; Tue Mar 10 11:19:33 2020 +0100 (CET) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200310_031940_246091_73AF7DCC X-CRM114-Status: GOOD ( 13.71 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [212.27.33.1 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [marc.w.gonzalez[at]free.fr] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-clk , Linux ARM , LKML Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Provide a simple wrapper for devres_alloc / devres_add. Signed-off-by: Marc Gonzalez Reviewed-by: Geert Uytterhoeven --- drivers/base/devres.c | 28 ++++++++++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 0bbb328bd17f..b4c18c105f39 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -685,6 +685,34 @@ int devres_release_group(struct device *dev, void *id) } EXPORT_SYMBOL_GPL(devres_release_group); +/** + * devm_add - allocate and register new device resource + * @dev: device to add resource to + * @func: resource release function + * @arg: resource data + * @size: resource data size + * + * Simple wrapper for devres_alloc / devres_add. + * Releases the resource if the allocation failed. + * + * RETURNS: + * 0 on success, -ENOMEM otherwise. + */ +int devm_add(struct device *dev, dr_release_t func, void *arg, size_t size) +{ + void *data = devres_alloc(func, size, GFP_KERNEL); + + if (!data) { + func(dev, arg); + return -ENOMEM; + } + + memcpy(data, arg, size); + devres_add(dev, data); + return 0; +} +EXPORT_SYMBOL_GPL(devm_add); + /* * Custom devres actions allow inserting a simple function call * into the teadown sequence. diff --git a/include/linux/device.h b/include/linux/device.h index 0cd7c647c16c..55be3be9b276 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -247,6 +247,9 @@ void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, resource_size_t *size); +int devm_add(struct device *dev, dr_release_t func, void *arg, size_t size); +#define devm_vadd(dev, func, type, args...) \ + devm_add(dev, func, &(struct type){args}, sizeof(struct type)) /* allows to add/remove a custom action to devres stack */ int devm_add_action(struct device *dev, void (*action)(void *), void *data); void devm_remove_action(struct device *dev, void (*action)(void *), void *data);