From patchwork Wed Oct 19 08:22:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp214756wrs; Wed, 19 Oct 2022 02:13:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xrhTnJSkvHR1ZU3ayjlLhgI2Zyx5+KmeHJhScnjU330CJAvmApiDtu16XAxU7ErvsZ0On X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr6470721edi.121.1666170821332; Wed, 19 Oct 2022 02:13:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170821; cv=none; d=google.com; s=arc-20160816; b=Y5m9/tx4muSZdzQdaOB08XElDjvgnOAlwfxLyzbdmpCRmX+4xVutx9dggtLQbjPywH mXhIdhHCHcMmOI4orlFD7wDB2kP7bwRuKPfh9Zj2nbozWk89NsLzgMmPfLeWbTW9/hqf GXy0qx32fxDIWlTBaDmIFVtHw/cnGEvMNJbPx0yeyzWH6PrlvOtxEs4PIJgavqHyNIFz I1kBn2nfHYok3oNAutczGxbYoQj+ElvrEX4MaLIHJPD9nmYqTcCwzeXRDzh33zuwQOvc kH4WMmkke+ABKIftIfOwoTe2egJ2X2VL2xwYxH8imT/BKL54bbbY5EHtLL1k50LisFR2 mEWw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a170906500500b0078255525a6fsi12614837ejj.671.2022.10.19.02.13.17; Wed, 19 Oct 2022 02:13:41 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747106734964012936?= X-GMAIL-MSGID: =?utf-8?q?1747106734964012936?= 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)