Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3714572rwb; Tue, 16 Aug 2022 07:39:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6zJz2vCs3M7ZwRw1k05DnFE7fX1Npjou420PtwBEpP321XROXeXZdzPs5iW8Gnzi2aJf2C X-Received: by 2002:a17:90b:350d:b0:1f4:f6a5:a281 with SMTP id ls13-20020a17090b350d00b001f4f6a5a281mr23205998pjb.99.1660660784795; Tue, 16 Aug 2022 07:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660660784; cv=none; d=google.com; s=arc-20160816; b=mJP1rSQyOEFNXa2YdlE3ri4HdR95gXiMeQqLFfHC+SZKONKobq/VLekbAzqNliog0I i5clhtBeW6hPxN/6tzJ52w2xxg79c1s//TyHgiQSWvhWCfGPrpHU8WCToxXPbh/+nJNE Gnz2mviM+6fwz7cliazwd5pZUeBWn9OKVWq3NdxPyRZLUbetrOPEnOc3s9OuszOrRxMn zUdpVNzFVekcAV4t/3wPbg3OImk22yRefNfyYoyZkre+VhTrAUPqDIQWmnMOeDY8jgu+ 1yvyMoGTef4s8jlCoqexOEsHn+UwTcE9hadLXQrTo/bGpj4uDv3jYl8kCWtJbru0GExh 2bFw== 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; bh=MhXJZxdhMICDxJwL8ucWpskrXPerE3z5Yiz2v3086Jc=; b=fXXXAiBK0FfOph51hui0tLHMxswjFzarvSY42B0TusB6jSYv1MvQuRtwwVJO/wPXOl V/d3YAoI4qQflgr4V5ZxzxCFLSc3aS1/GwACnAgjardRl3R0HCcaxcp7l+gBosiCTGE/ X1U5e2MuVlrYT690PPiGTnbVwypn+e+ZhymOGalrVA1aOOhRHxMBmexC1HxWy++aKJGM RmvpNDPdigVToXLXEmbxNXO9BtIgrcl5LfR8gHLzqxmBPIKlW8oJhb+xk9cKcGzw93xL 5NuzdAlw3JKE3qIz9ihYN5UffjLWWoUZfsg8cED3Tu325mj9I9HlD5xeVEHNrHJ5Ct6w roGQ== 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 w190-20020a6382c7000000b004089d1b3912si13237209pgd.204.2022.08.16.07.39.33; Tue, 16 Aug 2022 07:39:44 -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 S233712AbiHPNuA (ORCPT + 99 others); Tue, 16 Aug 2022 09:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiHPNt6 (ORCPT ); Tue, 16 Aug 2022 09:49:58 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A708A97513 for ; Tue, 16 Aug 2022 06:49:39 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M6XVd1v1gzkWNx; Tue, 16 Aug 2022 21:46:17 +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; Tue, 16 Aug 2022 21:49:36 +0800 From: Gaosheng Cui To: , , CC: , Subject: [PATCH -next 2/2] nvmem: core: add error handling for dev_set_name Date: Tue, 16 Aug 2022 21:49:35 +0800 Message-ID: <20220816134935.263825-3-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220816134935.263825-1-cuigaosheng1@huawei.com> References: <20220816134935.263825-1-cuigaosheng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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,T_SCC_BODY_TEXT_LINE 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