Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3388014imw; Mon, 18 Jul 2022 07:15:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tihdjVEoXPO3wAILdklRCCIrkxEZjqMCqbDoQGu/Qk/fUtIiAXHOjKmwnscgRAzIG2qve6 X-Received: by 2002:a17:907:d28:b0:72b:5cc9:99c with SMTP id gn40-20020a1709070d2800b0072b5cc9099cmr26106279ejc.228.1658153755043; Mon, 18 Jul 2022 07:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658153755; cv=none; d=google.com; s=arc-20160816; b=uBWDyK6HTEaCT54xvzJhCcEQtj0Rkuai4VYp4oBH1sNpoGvT077Id90Qa1sPc2fJ9v 1LSqxhgu5lmZa6EaRcTVNHUrjL4v8koTIupqFyRBH3vCTYsM4cThqJM/89gZBvPDbjbI B/3qCCrxzx4kB4bTqpwhRE68YkT03FhFc4G8NHkrApe8Se4f6sVrO0VgsN4FMzaHz9Y6 sIKHabH2Ch8XxVcIMs694bQxk7H5DQkT8qXmfuJKUZb7q+clxi6SN+OKbLUyD+GlU6QU o+QHB+Uo0uAlJKYQl5E/8mior74Zrx6HrEoH2X7EUNpxRgXE32CX01bYCF4H9bLTwjfF GvHg== 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 :message-id:date:subject:cc:to:from; bh=MhXJZxdhMICDxJwL8ucWpskrXPerE3z5Yiz2v3086Jc=; b=vS2buoDwGrW4k7nmeQiFWT5896qF0bOfNU1Q2z3aBsAwW4ROM4AAQcOPwvA+jzCu/G dzpbJqjwmgrrwETSjXvswtZMowDc1YDUDf8cb83LJ6uRcrr0l/+aZBIpvmzrLkm9gOv0 ksgavDqnYzQ5Ks89BJfuVlVFx+tCGMwviHGvECeuQ25mkRdD1W64M2PLhZqnr7dB3mkF lj3It2zdELB+6XR1pHLvTkhKRtrgJySlmuxhbWLnCUWvrC4FGI8GtPkPXFvjlwS8Fx9/ V22ClC3lOBr6HNjS0AY7BdehasXL4n3K+s3TvBwpGP4mnlziRH+Gfe4ztO2aoAjmrtTv h38w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a05640203cf00b0043a29189637si12892628edw.93.2022.07.18.07.15.29; Mon, 18 Jul 2022 07:15:55 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234048AbiGRNgR (ORCPT + 99 others); Mon, 18 Jul 2022 09:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233852AbiGRNgQ (ORCPT ); Mon, 18 Jul 2022 09:36:16 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A76ED1A3B1 for ; Mon, 18 Jul 2022 06:36:15 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LmjbH1X5mzjX5R; Mon, 18 Jul 2022 21:33:31 +0800 (CST) Received: from dggphis33418.huawei.com (10.244.148.83) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Jul 2022 21:36:12 +0800 From: Gaosheng Cui To: , , CC: , , Subject: [PATCH -next] nvmem: core: add error handling for dev_set_name Date: Mon, 18 Jul 2022 21:36:12 +0800 Message-ID: <20220718133612.3200045-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 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 --- 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