From patchwork Fri Jun 9 08:31: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: 9777509 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 03C3B6034B for ; Fri, 9 Jun 2017 08:41:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E772728558 for ; Fri, 9 Jun 2017 08:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC169285E6; Fri, 9 Jun 2017 08: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 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 7D97328558 for ; Fri, 9 Jun 2017 08:41:37 +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=X/FnSEkT6GAiSMP3BieSTMT8kW RsLr+ZK6yMUvgYZB9VMa9ZQzsTTRFZe1NPUb68dP4bTFgc08ibtUeBXuToRiPfInWpMCNzeg6n/GY dbqOoTmfVZB/ukaJbxw3E9uyycA5gnDy8Lb1L6qy8SasyWVzQXTEgIiapHs0O/q1zx6Wx0LFEF1cy U7fP2WmgXkjIeSwPc4G5GwskDZYxA+2NEtod/ZJI9ph3MVTb4W2lCnLEW4X6xHs+wccV+oQj0JHmi ww0OUOSTB7BuPUQ6abSxuVtnGOep1H4wWJrvmEWpiqyhKDVMqVBL5E1NnT/Mg0Sq9fczNk5cbJhvn k6Feo6LA==; 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 1dJFU8-0006bT-Dt; Fri, 09 Jun 2017 08:41:36 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dJFTx-0006KQ-FQ for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Jun 2017 08:41:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2tfGU+Gk1IIZtJocuZeOwOgfRVHsM++VYHEPvsBlqY8=; b=kulnrOSRSURIAN8FXWFzbSayq lKeMxzUh2cBCnxk30VB46vKIEhQYbgdnITiIe6V62ZRE5b3Ap3YZaHHAOkYitji32SgeCNm1A2UFB 56TOD4YfEix/v7GAiTphvmqBMkRaSAkphVHs9eYBWMqQnQq1CaBta4bhamsHNWhl+44B8bTDlDfN9 e4vR9a/GWRq2PZntIDVBIfAFoU2I9zYM3CtCPVhmsFefmsaTBn5mJdfvVOUn+nbA0Hbhw4gjxX0gO ysHCu4IStXetNr63tx94vwPWlc0fGoveMMf1Nk1je0G/VnId/TAPlJVrnQCPtx0oLnC2tSMlZLpj/ hv5DxCB8Q==; Received: from metis.ext.4.pengutronix.de ([92.198.50.35]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dJFMx-0001J9-SH for linux-arm-kernel@lists.infradead.org; Fri, 09 Jun 2017 08:34:15 +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 1dJFKg-0001cc-H9; Fri, 09 Jun 2017 10:31:50 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dJFKe-00022K-DY; Fri, 09 Jun 2017 10:31:48 +0200 From: Jan Luebbe To: Chris Packham , linux-arm-kernel@lists.infradead.org, linux-edac@vger.kernel.org Subject: [RFC PATCH 5/7] EDAC: Add devres helpers for edac_device_alloc_ctl_info/edac_device_add_device Date: Fri, 9 Jun 2017 10:31:21 +0200 Message-Id: <20170609083123.6539-6-jlu@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170609083123.6539-1-jlu@pengutronix.de> References: <20170609083123.6539-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-20170609_093412_035193_48A1A95E X-CRM114-Status: GOOD ( 14.04 ) 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: 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 *