From patchwork Fri Jun 30 14:51:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_L=C3=BCbbe?= X-Patchwork-Id: 9819813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 95008603F2 for ; Fri, 30 Jun 2017 14:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 749E4285EB for ; Fri, 30 Jun 2017 14:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6930228670; Fri, 30 Jun 2017 14:54:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DB3BE285EB for ; Fri, 30 Jun 2017 14:54:08 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4ugEYRzRx6ByvAPZOSU33WO1UdnfWMSKgGB56rp1MC0=; b=HS34v3jZymCe9H60Q42sovaU9x N5HK/6zMLvb08o1P5s2fymGUvTZ41YAHiunGLFLm7WUo4m2RiycbbzQEc+oHmZIZUWaf1mZdvpgE8 W22swoesUQHA6vG3hLy6C84cCWYla42Wkq6YeZ8kiqdsaOGaJV7WnkREqKsBjjFret4Lg8NXqYwXd 6asfV91XXv+ehtaSGGgTfHbKWX0AN+x1T90vZ/JfUkARass5DqLgNhtumr/DIthmjy+CrxP3z759Q kxUR5KB0ZWr9YelZ1BL8UkGtgLd8McWcLEk/Ikq2GD3o7jLnhRpqrKTAQ0oWs2JgamKnBKKvsfz/Z U0Nco6Qg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQxJ7-00066E-JZ; Fri, 30 Jun 2017 14:54:05 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dQxH6-0003wZ-UV for linux-arm-kernel@lists.infradead.org; Fri, 30 Jun 2017 14:52:11 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dQxGg-000885-2s; Fri, 30 Jun 2017 16:51:34 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dQxGe-0003Mi-AU; Fri, 30 Jun 2017 16:51:32 +0200 From: Jan Luebbe To: Chris Packham , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org Subject: [PATCH 7/8] EDAC: Add devres helpers for edac_device_alloc_ctl_info/edac_device_add_device Date: Fri, 30 Jun 2017 16:51:05 +0200 Message-Id: <20170630145106.29820-8-jlu@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170630145106.29820-1-jlu@pengutronix.de> References: <20170630145106.29820-1-jlu@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170630_075202_571749_448C098C X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Gregory CLEMENT , Jan Luebbe , kernel@pengutronix.de MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP These helpers simplify error handling in the _probe functions and automate deallocation in the _remove functions. Signed-off-by: Jan Luebbe --- drivers/edac/edac_device.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/edac/edac_device.h | 29 +++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c index 65cf2b9355c4..bfc4144840cf 100644 --- a/drivers/edac/edac_device.c +++ b/drivers/edac/edac_device.c @@ -232,6 +232,41 @@ void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info) } EXPORT_SYMBOL_GPL(edac_device_free_ctl_info); +/** + * devm_edac_device_free_ctl_info() - Internal helper to call + * edac_device_free_ctl_info from a devres action + */ +static void devm_edac_device_free_ctl_info(void *ctl_info) +{ + edac_device_free_ctl_info((struct edac_device_ctl_info *)ctl_info); +} + +struct edac_device_ctl_info *devm_edac_device_alloc_ctl_info( + struct device *dev, + unsigned sz_private, + char *edac_device_name, unsigned nr_instances, + char *edac_block_name, unsigned nr_blocks, + unsigned offset_value, + struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib, + int device_index) +{ + struct edac_device_ctl_info *ctl_info; + ctl_info = edac_device_alloc_ctl_info(sz_private, + edac_device_name, nr_instances, + edac_block_name, nr_blocks, + offset_value, + attrib_spec, nr_attrib, + device_index); + if (!ctl_info) + return ctl_info; + + if (devm_add_action_or_reset(dev, devm_edac_device_free_ctl_info, ctl_info)) + return NULL; + + return ctl_info; +} +EXPORT_SYMBOL_GPL(devm_edac_device_alloc_ctl_info); + /* * find_edac_device_by_dev * scans the edac_device list for a specific 'struct device *' @@ -539,6 +574,30 @@ struct edac_device_ctl_info *edac_device_del_device(struct device *dev) } EXPORT_SYMBOL_GPL(edac_device_del_device); +/** + * devm_edac_device_del_device() - Internal helper to call + * edac_device_del_device from a devres action + */ +static void devm_edac_device_del_device(void *dev) +{ + edac_device_del_device((struct device *)dev); +} + +int devm_edac_device_add_device(struct device *dev, + struct edac_device_ctl_info *edac_dev) +{ + int ret; + + ret = edac_device_add_device(edac_dev); + if (ret) + return ret; + + if (devm_add_action_or_reset(dev, devm_edac_device_del_device, dev)) + return 1; + + return 0; +} + static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev) { return edac_dev->log_ce; diff --git a/drivers/edac/edac_device.h b/drivers/edac/edac_device.h index 1aaba74ae411..73f7b98e8ec0 100644 --- a/drivers/edac/edac_device.h +++ b/drivers/edac/edac_device.h @@ -258,6 +258,24 @@ extern struct edac_device_ctl_info *edac_device_alloc_ctl_info( extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info); /** + * devm_edac_device_alloc_ctl_info: Allocate a new managed edac device + * control info structure + * + * This function takes the same arguments as edac_device_alloc_ctl_info in + * addition to the owning device. The structure is freed by devres using + * edac_device_free_ctl_info. + */ +extern struct edac_device_ctl_info *devm_edac_device_alloc_ctl_info( + struct device *dev, + unsigned sizeof_private, + char *edac_device_name, unsigned nr_instances, + char *edac_block_name, unsigned nr_blocks, + unsigned offset_value, + struct edac_dev_sysfs_block_attribute *block_attributes, + unsigned nr_attribs, + int device_index); + +/** * edac_device_add_device: Insert the 'edac_dev' structure into the * edac_device global list and create sysfs entries associated with * edac_device structure. @@ -286,6 +304,17 @@ extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev); extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev); /** + * devm_edac_device_add_device: + * Helper to call edac_device_add_device and register it for cleanup with + * devres. + * + * Returns: + * 0 on Success, or an error code on failure + */ +extern int devm_edac_device_add_device(struct device *dev, + struct edac_device_ctl_info *edac_dev); + +/** * edac_device_handle_ue(): * perform a common output and handling of an 'edac_dev' UE event *