Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp804541rwi; Wed, 19 Oct 2022 03:13:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7YX7KBu8XbWiuG+SdpqwFLxWejTNwiMxTwcKchxq4lRwnjqMqUw2n69OUHu6zsf+q5Gywl X-Received: by 2002:a17:903:2286:b0:182:2f05:8abb with SMTP id b6-20020a170903228600b001822f058abbmr7459273plh.14.1666174439714; Wed, 19 Oct 2022 03:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666174439; cv=none; d=google.com; s=arc-20160816; b=LVeO1d10tiWNby8JtWiogCWnOAkPNuA9TBB7ZDqi3IwVoUgmRYf7vTKgqCiJ4Edc02 pwSjlwfAK2nihEmvAhp85QuKDWQ4jhqBMS+8a3M7b9zEYUmvnII7tOFiCNAHP4yLYyOU 5/fol8NziMd+6Eyf3n0mh72CVmHNbcY3Z9I6XbosJyKBDsDIIhDVMHkl77JC9Uw7isbj vb9AMMyuxFJTcYChKEJeOOHMUY6PO//RKr+CrzgKnW3lQRHmLOiwQH4sedbb5TECSC6b DjLVLujTr0Z/tz83NLnHh50aLKEBRE1fhhc3nY0I3RPR6Hq2t+3qReKGH4goUneP4lVa 6Cmg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sgHzeYAd7yv+AaNLjROWREAUCgtt9WGGemK+vLNmO3U=; b=rwEVNV8U2LOAgMtogR4QjekhjWJTfF+jo19fh5hxee0ETcNkgk2NPJZLVG1QuCc1y1 mVOpaIvakf+boDHjn/QYekIzD8KdUx6Y21C1w1qNrXf+2s282zVvS/nMeVxU7w+scsDw f5ECPuh4Lz/WA5yX0HYApIZpIPs6jXkwcFRluJ2t6xrQ0R7mW5OU+NvNBSEQ26LlsDec usTk+wFFXvguUtmxwzQgdsyHNEdbQt/XgBFyg/JZ3C0ipB5r3id0E2CyaUZkZ90IoMWg b1HJLcVgVixDhnGzEqRp1zQJxFVSR002SBeQHcwhfHZQybEpBHVzQqfe9OAoZBylMX24 6egg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FYhv6Lmz; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a635447000000b0041a4bf40469si18914299pgm.271.2022.10.19.03.13.47; Wed, 19 Oct 2022 03:13:59 -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=@linuxfoundation.org header.s=korg header.b=FYhv6Lmz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232474AbiJSJMU (ORCPT + 99 others); Wed, 19 Oct 2022 05:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbiJSJJf (ORCPT ); Wed, 19 Oct 2022 05:09:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E66AF18E; Wed, 19 Oct 2022 02:00:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2B180617DE; Wed, 19 Oct 2022 08:40:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ED6EC433D6; Wed, 19 Oct 2022 08:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168832; bh=7VdRluWHI+RLGwVR0BCIqAPVnPkYCKskJthMfKF0DfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FYhv6Lmz3LCUwgsMr6Wo3vzvVZVxt8dy+cRusWyk8cYWG4iua1o//ym6GJrtgpmZ0 s3BHxrQBseYuUD25JiJ7cH5Gi4vHDLIqdL2tUsq+KRArMptkR9o0r1yfSJ7Ti9Eezn pevwEtQ3592gXPhO+kUB0lFhNI+W4RLPj18uAzM4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gaosheng Cui , Srinivas Kandagatla Subject: [PATCH 6.0 067/862] nvmem: core: Fix memleak in nvmem_register() Date: Wed, 19 Oct 2022 10:22:34 +0200 Message-Id: <20221019083252.879949086@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 commit bd1244561fa2a4531ded40dbf09c9599084f8b29 upstream. dev_set_name will alloc memory for nvmem->dev.kobj.name in nvmem_register, when nvmem_validate_keepouts failed, nvmem's memory will be freed and return, but nobody will free memory for nvmem->dev.kobj.name, there will be memleak, so moving nvmem_validate_keepouts() after device_register() and let the device core deal with cleaning name in error cases. Fixes: de0534df9347 ("nvmem: core: fix error handling while validating keepout regions") Cc: stable@vger.kernel.org Signed-off-by: Gaosheng Cui Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20220916120402.38753-1-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -829,21 +829,18 @@ struct nvmem_device *nvmem_register(cons nvmem->dev.groups = nvmem_dev_groups; #endif - if (nvmem->nkeepout) { - rval = nvmem_validate_keepouts(nvmem); - if (rval) { - ida_free(&nvmem_ida, nvmem->id); - kfree(nvmem); - return ERR_PTR(rval); - } - } - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); rval = device_register(&nvmem->dev); if (rval) goto err_put_device; + if (nvmem->nkeepout) { + rval = nvmem_validate_keepouts(nvmem); + if (rval) + goto err_device_del; + } + if (config->compat) { rval = nvmem_sysfs_setup_compat(nvmem, config); if (rval)