From patchwork Tue Apr 5 11:48:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laxman Dewangan X-Patchwork-Id: 8751061 Return-Path: X-Original-To: patchwork-linux-omap@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 2EFD6C0553 for ; Tue, 5 Apr 2016 12:13:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4248E201B4 for ; Tue, 5 Apr 2016 12:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4DB4E20351 for ; Tue, 5 Apr 2016 12:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758229AbcDEL7u (ORCPT ); Tue, 5 Apr 2016 07:59:50 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:3747 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758224AbcDEL7t (ORCPT ); Tue, 5 Apr 2016 07:59:49 -0400 Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Tue, 05 Apr 2016 04:59:46 -0700 Received: from hqemhub03.nvidia.com ([172.20.150.15]) by hqnvupgp08.nvidia.com (PGP Universal service); Tue, 05 Apr 2016 04:58:20 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 05 Apr 2016 04:58:20 -0700 Received: from ldewanganubuntu-System-Product-Name.nvidia.com (172.20.144.16) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.406.0; Tue, 5 Apr 2016 04:59:47 -0700 From: Laxman Dewangan To: , CC: , , , , , , Laxman Dewangan Subject: [PATCH 01/20] mfd: Add devm_ apis for mfd_add_devices and mfd_release_devices Date: Tue, 5 Apr 2016 17:18:13 +0530 Message-ID: <1459856912-17859-2-git-send-email-ldewangan@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459856912-17859-1-git-send-email-ldewangan@nvidia.com> References: <1459856912-17859-1-git-send-email-ldewangan@nvidia.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Add device managed APIs devm_mfd_add_devices() and devm_mfd_remove_devices() for the APIs mfd_add_devices() and mfd_remove_devices(). This helps in reducing code in error path and sometimes removal of .remove callback for driver unbind. Signed-off-by: Laxman Dewangan --- drivers/mfd/mfd-core.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/core.h | 7 ++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index 409da01..145712e 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -334,6 +334,68 @@ void mfd_remove_devices(struct device *parent) } EXPORT_SYMBOL(mfd_remove_devices); +static void devm_mfd_dev_release(struct device *dev, void *res) +{ + mfd_remove_devices(dev); +} + +/** + * devm_mfd_add_devices - Resource managed version of mfd_add_devices() + * + * This returns the 0 on success otherwise error number in the failure. + * The allocated mfd devices will automatically be released when the + * device is unbound. + */ +int devm_mfd_add_devices(struct device *dev, int id, + const struct mfd_cell *cells, int n_devs, + struct resource *mem_base, + int irq_base, struct irq_domain *domain) +{ + struct device **ptr; + int ret; + + ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = mfd_add_devices(dev, id, cells, n_devs, mem_base, + irq_base, domain); + if (!ret) { + *ptr = dev; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ret; +} +EXPORT_SYMBOL(devm_mfd_add_devices); + +static int devm_mfd_devs_match(struct device *dev, void *res, void *data) +{ + struct device **r = res; + + if (WARN_ON(!r || !*r)) + return 0; + + return *r == data; +} + +/** + * devm_mfd_remove_device - Resource managed version of mfd_remove_devices() + * @dev: Device for which which resource was allocated. + * + * Remove all mfd devices added on the device. + * Normally this function will not need to be called and the resource + * management code will ensure that the resource is freed. + */ +void devm_mfd_remove_devices(struct device *dev) +{ + WARN_ON(devres_release(dev, devm_mfd_dev_release, + devm_mfd_devs_match, dev)); +} +EXPORT_SYMBOL(devm_mfd_remove_devices); + int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones) { struct mfd_cell cell_entry; diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h index bc6f7e0..d658d7f 100644 --- a/include/linux/mfd/core.h +++ b/include/linux/mfd/core.h @@ -131,4 +131,11 @@ static inline int mfd_add_hotplug_devices(struct device *parent, extern void mfd_remove_devices(struct device *parent); +extern int devm_mfd_add_devices(struct device *dev, int id, + const struct mfd_cell *cells, int n_devs, + struct resource *mem_base, + int irq_base, struct irq_domain *irq_domain); + +extern void devm_mfd_remove_devices(struct device *dev); + #endif