Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2090429rwn; Fri, 16 Sep 2022 05:40:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vVS9HDW00MHkyOGtkhj20jgagdhRNtpDjq0YCprjZG7tXrsf55k1y7p/oKBm1fbLFv3Fq X-Received: by 2002:a17:902:e547:b0:178:7cf4:90e9 with SMTP id n7-20020a170902e54700b001787cf490e9mr4502535plf.158.1663332033785; Fri, 16 Sep 2022 05:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663332033; cv=none; d=google.com; s=arc-20160816; b=uMCN3HSnsnwgUSHviMNihO5Yo0Dm0AP799fpqswm3Ifokl8bNxlOtmFrS6AoiP5Ok4 Mr6deYETwX840jNXPCMK8fSJUbRvudoDmijArqf7Nh8eKL6vOX2J8WWfA07uTmh6GhJo XdN7Aju5Ff3psIjqEInHGoN5D4OPXTEeXoMZnOnESRGhNLdiLgztWsuEJym6WG8lUZvo +yANzk8FTy7l4fMnA8u+ky4HME6A5sViTLQIIb5YkgPSzJw8GBUVN5hdx4IFmBcxrHvl ZCF79Unqpjb5MstidW5+S9b1BPpeQFc2zFxwPCrNwCKPzRsrE2yyNeeF+zYYOxya7EXj NRXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a3ltSV10gjE+B1vHCJrys5NABOlxdayq5iZ4NHV92/Q=; b=hOdJQhGa08zLzBEm/OaQbV57MwlZU8Wfu/QrXFa0YD5lvuvSKFgaF+JuvemFa26jg5 VlcCL6rqB5qTFCM99n6V9SPnGMdWr2a+TRyI+F6RoLU2yvgQftUAkIjO8TSzxp3vjFOe mNJbBFBniY4UBjiUHqPsauYTpE46zO6v38wb5QFF1BqvTrn4ainif2M8AxQYekKqFHkM DpdAxkXB0BF4BxsM7cLPbchJpwQzLkblmDzDLAmTDW51UmG5It4RWlALtWF58AVaWC82 jUBiqoaKkXP3PlinfavnEH+VCPGZoZ0LS54PBaepXVuRZNC2BF+F8qsq0l3l0N71+bV6 lP/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="slESl/j8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a170902eb9000b00174f4e61be8si19060491plg.409.2022.09.16.05.40.21; Fri, 16 Sep 2022 05:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="slESl/j8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbiIPMVd (ORCPT + 99 others); Fri, 16 Sep 2022 08:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbiIPMVT (ORCPT ); Fri, 16 Sep 2022 08:21:19 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D9CB029E for ; Fri, 16 Sep 2022 05:21:11 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id ay7-20020a05600c1e0700b003b49861bf48so969082wmb.0 for ; Fri, 16 Sep 2022 05:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=a3ltSV10gjE+B1vHCJrys5NABOlxdayq5iZ4NHV92/Q=; b=slESl/j88QOOc87v/2bAejq41J/Y/cCR6TJPJVKaLq6RgQSJk+kXudHtWADPyzc8VZ EUsKR3SUURy/mr/nqL01GHhy9UCOEhPwRMlpywY6KQL4LfRh6ye97sxxDYBkbkPI5NqI SOvPbgpg7om0f43POKh8/cWUbIa4FteaTnVcjwaf8/1pNYU8ETGD5DLsYSB5RadQ0q9q xCE8amHEhrqJ9ahaqJEl6l7KNxQKHTTvouYfq2FbAtQm6N17dAT8ioItygG6P270Xlk7 HZ6SHbykvPukAU/a1LvVIyQW0MD92yPIRy1oDcszNWHgyj7hoPjkgFaMyE1YmJBS8ns0 yELg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=a3ltSV10gjE+B1vHCJrys5NABOlxdayq5iZ4NHV92/Q=; b=1U3i/tMPAHUKAUuZYvLUdXFvuTHR/0qT7IvzpRdGh6+XN8HuzC6WTVXe89Zu5YC0Wp JjaMwfdbt0j807SIp5kplnp5kBVJcaeRT4UDqHskcB2Mv4JJFhQtxpGUlhHfg0YnAPGq D2snoeF+klTPnDr2dTlC9fjBMp3mZr093mgtOrbfrj/2Ds4HajqVkRAXtxBQ2/YK+Xly Y/ZEi/V54EgIexMDZ/bZDJ9J4iQDyn93EX73SmN0oiBXh8AllPGodEJ1btzietXRceGr Iu3gfenAJ8GRpFEjmEQEFWnQqnqvsgL1MXmdBcYN+h4sGqX2JK3pJ3rUVk/nwoDFr0cY Izxg== X-Gm-Message-State: ACrzQf2LPj8W2fTIAvY0t0bD1+hU7JgryY9KUaZaUEbjCNrAE6+Fmg3J vJ1lUi85IYB9kzRBfERG8jFlbA== X-Received: by 2002:a05:600c:3b8c:b0:3b4:8ad1:d894 with SMTP id n12-20020a05600c3b8c00b003b48ad1d894mr3163089wms.113.1663330869457; Fri, 16 Sep 2022 05:21:09 -0700 (PDT) Received: from srini-hackbase.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id u11-20020adfdb8b000000b0022add371ed2sm1540015wri.55.2022.09.16.05.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 05:21:08 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Gaosheng Cui , Srinivas Kandagatla Subject: [PATCH 03/13] nvmem: core: add error handling for dev_set_name Date: Fri, 16 Sep 2022 13:20:50 +0100 Message-Id: <20220916122100.170016-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220916122100.170016-1-srinivas.kandagatla@linaro.org> References: <20220916122100.170016-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gaosheng Cui The type of return value of dev_set_name is int, which may return wrong result, so we add error handling for it to reclaim memory of nvmem resource, and return early when an error occurs. Signed-off-by: Gaosheng Cui Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 2164efd12ba9..321d7d63e068 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -810,18 +810,24 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) switch (config->id) { case NVMEM_DEVID_NONE: - dev_set_name(&nvmem->dev, "%s", config->name); + rval = dev_set_name(&nvmem->dev, "%s", config->name); break; case NVMEM_DEVID_AUTO: - dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); + rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); break; default: - dev_set_name(&nvmem->dev, "%s%d", + rval = dev_set_name(&nvmem->dev, "%s%d", config->name ? : "nvmem", config->name ? config->id : nvmem->id); break; } + if (rval) { + ida_free(&nvmem_ida, nvmem->id); + kfree(nvmem); + return ERR_PTR(rval); + } + nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write; -- 2.25.1