From patchwork Wed Aug 2 12:39:20 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: 9876751 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 ABF3760360 for ; Wed, 2 Aug 2017 12:42:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E2142877D for ; Wed, 2 Aug 2017 12:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9004D28786; Wed, 2 Aug 2017 12:42:32 +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 1274E2877D for ; Wed, 2 Aug 2017 12:42:32 +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=dHeI1ZDOtw7RmsiUcXDyugMdpImL0Ql7rCxpE/361R4=; b=lyFB1chBvgcaNw0eHVqM68ntsc XISZykLBVCwLCRasNDTGkI29IIN9WRkdgqfV7AsX+9pvXZ00Z0y42OROerfc+M1t1cBW6x3GE5Ysf dZgKB1T4dn+SNj6lCY9PFohk4CQnVuNQou/FTA0G7ieWPexDBBq6pTYQpov3ye8OKQL581LrwIXd2 QodW7ss6RaqSMZnFzweTrKJpqw3GrTLoRQdxicmxsIn4ift+SlkyPkeZWQHfyhR4D6diet8NxZm78 7MuSsd2i6ADomCguSWiS2W4XdukHgvqUeG4rxOi1nzzWFpyjT3B0Oyz4EqQdu8035xijt7osZv+8J 0OsOD6ig==; 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 1dcsyq-0000gk-RM; Wed, 02 Aug 2017 12:42:28 +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-0005Lc-D7 for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2017 12:40:02 +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 1dcsw0-0004uQ-NR; Wed, 02 Aug 2017 14:39:32 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dcsvu-0004rI-BB; 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 7/9] EDAC: Add devres helpers for edac_mc_alloc/edac_mc_add_mc(_with_groups) Date: Wed, 2 Aug 2017 14:39:20 +0200 Message-Id: <20170802123922.11498-8-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_833224_4E202E35 X-CRM114-Status: GOOD ( 10.64 ) 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_mc.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/edac/edac_mc.h | 26 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 480072139b7a..d3ee2b851329 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -517,6 +517,34 @@ void edac_mc_free(struct mem_ctl_info *mci) } EXPORT_SYMBOL_GPL(edac_mc_free); +/** + * devm_edac_mc_free() - Internal helper to call edac_mc_free from a devres + * action. + */ +static void devm_edac_mc_free(void *mci) +{ + edac_mc_free((struct mem_ctl_info *)mci); +} + +struct mem_ctl_info *devm_edac_mc_alloc(struct device *dev, + unsigned int mc_num, + unsigned int n_layers, + struct edac_mc_layer *layers, + unsigned int sz_pvt) +{ + struct mem_ctl_info *mci; + + mci = edac_mc_alloc(mc_num, n_layers, layers, sz_pvt); + if (!mci) + return mci; + + if (devm_add_action_or_reset(dev, devm_edac_mc_free, mci)) + return NULL; + + return mci; +} +EXPORT_SYMBOL_GPL(devm_edac_mc_alloc); + bool edac_has_mcs(void) { bool ret; @@ -828,6 +856,32 @@ struct mem_ctl_info *edac_mc_del_mc(struct device *dev) } EXPORT_SYMBOL_GPL(edac_mc_del_mc); +/** + * devm_edac_mc_del_mc() - Internal helper to call edac_mc_del_mc from a devres + * action. + */ +static void devm_edac_mc_del_mc(void *dev) +{ + edac_mc_del_mc((struct device *)dev); +} + +int devm_edac_mc_add_mc_with_groups(struct device *dev, + struct mem_ctl_info *mci, + const struct attribute_group **groups) +{ + int ret; + + ret = edac_mc_add_mc_with_groups(mci, groups); + if (ret) + return ret; + + if (devm_add_action_or_reset(dev, devm_edac_mc_del_mc, dev)) + return 1; + + return 0; +} +EXPORT_SYMBOL_GPL(devm_edac_mc_add_mc_with_groups); + static void edac_mc_scrub_block(unsigned long page, unsigned long offset, u32 size) { diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h index 5357800e418d..32f88cc4a65b 100644 --- a/drivers/edac/edac_mc.h +++ b/drivers/edac/edac_mc.h @@ -149,6 +149,32 @@ extern int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, extern void edac_mc_free(struct mem_ctl_info *mci); /** + * devm_edac_mc_alloc() - Helper to call edac_mc_alloc() and register it for + * cleanup with devres. + * + * Returns: + * On success, return a pointer to struct mem_ctl_info pointer; + * %NULL otherwise + */ +struct mem_ctl_info *devm_edac_mc_alloc(struct device *dev, + unsigned int mc_num, + unsigned int n_layers, + struct edac_mc_layer *layers, + unsigned int sz_pvt); + +/** + * devm_edac_mc_add_mc_with_groups() - Helper to call + * edac_mc_add_mc_with_groups() and register it for cleanup with devres. + * + * Returns: + * 0 on Success, or an error code on failure + */ +int devm_edac_mc_add_mc_with_groups(struct device *dev, + struct mem_ctl_info *mci, + const struct attribute_group **groups); +#define devm_edac_mc_add_mc(dev, mci) devm_edac_mc_add_mc_with_groups(dev, mci, NULL) + +/** * edac_has_mcs() - Check if any MCs have been allocated. * * Returns: