From patchwork Wed Aug 2 12:39:21 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: 9876745 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 B694960360 for ; Wed, 2 Aug 2017 12:41:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA9392877C for ; Wed, 2 Aug 2017 12:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F4DE28782; Wed, 2 Aug 2017 12:41:37 +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,RCVD_IN_DNSWL_NONE 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 EDBCC2877C for ; Wed, 2 Aug 2017 12:41:36 +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=K+LQOZBhnKBQ7sz9dfh9Xwm6hELE8s27zCuE08er3uY=; b=uI47eHzr4++do3h8X2Ne1RBIxG OtLP0ss8pyT+BtssBURnGNi46mXDla0qeIMrftivPJKpWda8wa2GGF4jHjGuU+V4AmdQu1HYAFeRo Sxj60KzlYr9crekjc4oOzhpJoZpRIbURdtjTCa7aFk3Ote5HYkPJ7aa0wJleFmYati5aNKAVBfJPI N0C5fZHEtuE9TiXJOnD4XzJiItO118NtXQdTTSRg5OJQMCfFpsxwuk0Kt1++QTuoMPp4Q1qcUZWDD SchZ/5xr1B77e4BNWJwEtZIOsu7y3OSIOoB3agG5YbW6RuS75ARG9pZ+7bElTpuYiK/eafXrqWlDs I8UvKYrQ==; 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 1dcsxw-0008D7-13; Wed, 02 Aug 2017 12:41:32 +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 1dcswL-0005LE-BS for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2017 12:39:58 +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 1dcsvw-0004uR-DQ; Wed, 02 Aug 2017 14:39:28 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dcsvu-0004rr-C5; Wed, 02 Aug 2017 14:39:26 +0200 From: Jan Luebbe To: Chris Packham , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org Subject: [PATCH v2 8/9] EDAC: Add devres helpers for edac_device_alloc_ctl_info/edac_device_add_device Date: Wed, 2 Aug 2017 14:39:21 +0200 Message-Id: <20170802123922.11498-9-jlu@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170802123922.11498-1-jlu@pengutronix.de> References: <20170802123922.11498-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-20170802_053953_751117_64581B68 X-CRM114-Status: GOOD ( 12.72 ) 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/edac/edac_device.h | 29 ++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c index 65cf2b9355c4..d011f42c3507 100644 --- a/drivers/edac/edac_device.c +++ b/drivers/edac/edac_device.c @@ -232,6 +232,42 @@ 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 int sz_private, + char *edac_device_name, unsigned int nr_instances, + char *edac_block_name, unsigned int nr_blocks, + unsigned int offset_value, + struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned int 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 +575,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..711a50b133cd 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 int sizeof_private, + char *edac_device_name, unsigned int nr_instances, + char *edac_block_name, unsigned int nr_blocks, + unsigned int offset_value, + struct edac_dev_sysfs_block_attribute *block_attributes, + unsigned int 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 *