From patchwork Tue Jan 4 13:38:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12703482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B8D1C433F5 for ; Tue, 4 Jan 2022 13:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233713AbiADNio (ORCPT ); Tue, 4 Jan 2022 08:38:44 -0500 Received: from mga07.intel.com ([134.134.136.100]:25811 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233663AbiADNij (ORCPT ); Tue, 4 Jan 2022 08:38:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641303519; x=1672839519; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iKpVHqbLjmy+GnZIzKt6LP0hTcWqlU2qKV4ybnoaZ5Y=; b=B3vBSms37MREx8C/cBFTA2e9CdmrVL10xiFtdNFbY3Rmd35Wqz8pO0A4 V8xnf0Aq+z8t18MhuQEfKPYmfz2OJGm6d5lp1s1HHoyTiOKsvMRxmFA3o ZFlbt5tfpp9KzQBEJAKv9NVw0uJYw6Qrra3UbTu9CD4sICnAjkU1OGyO1 r1c3xMBh9QL1VJdZHs+ZadkPHNVsP/5ERaYR5Ex0ksEFv2AXStV38dkNY 3eO7uL3SG8TU9xbSmat9tJEg1ux5076yiLXd3uPiOAFgLtM0pVnPKxrsL 3aKQDw/fGH89dJuvrZ7cNVcs1LgVgz2nbYHsXvrW0j/ZxbFoL/0P5w8Ou Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="305576180" X-IronPort-AV: E=Sophos;i="5.88,261,1635231600"; d="scan'208";a="305576180" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2022 05:38:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,261,1635231600"; d="scan'208";a="590678804" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 04 Jan 2022 05:38:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id D87DC18E; Tue, 4 Jan 2022 15:38:45 +0200 (EET) From: Andy Shevchenko To: Miquel Raynal , Srinivas Kandagatla , Greg Kroah-Hartman , Mika Westerberg , Andy Shevchenko , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: Richard Weinberger , Vignesh Raghavendra , Andreas Noever , Michael Jamet , Yehezkel Bernat , Alexander Usyskin Subject: [PATCH v1 2/5] nvmem: core: Use devm_add_action_or_reset() Date: Tue, 4 Jan 2022 15:38:40 +0200 Message-Id: <20220104133843.44272-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104133843.44272-1-andriy.shevchenko@linux.intel.com> References: <20220104133843.44272-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Slightly simplify the devm_nvmem_register() by using the devm_add_action_or_reset(). Signed-off-by: Andy Shevchenko --- drivers/nvmem/core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index fbf7dec775fb..6946d14876dc 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -907,9 +907,9 @@ void nvmem_unregister(struct nvmem_device *nvmem) } EXPORT_SYMBOL_GPL(nvmem_unregister); -static void devm_nvmem_release(struct device *dev, void *res) +static void devm_nvmem_unregister(void *nvmem) { - nvmem_unregister(*(struct nvmem_device **)res); + nvmem_unregister(nvmem); } /** @@ -926,20 +926,16 @@ static void devm_nvmem_release(struct device *dev, void *res) struct nvmem_device *devm_nvmem_register(struct device *dev, const struct nvmem_config *config) { - struct nvmem_device **ptr, *nvmem; - - ptr = devres_alloc(devm_nvmem_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return ERR_PTR(-ENOMEM); + struct nvmem_device *nvmem; + int ret; nvmem = nvmem_register(config); + if (IS_ERR(nvmem)) + return nvmem; - if (!IS_ERR(nvmem)) { - *ptr = nvmem; - devres_add(dev, ptr); - } else { - devres_free(ptr); - } + ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem); + if (ret) + return ERR_PTR(ret); return nvmem; }