From patchwork Sat Oct 22 07:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1088962wrr; Sat, 22 Oct 2022 00:41:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GyBWN51cQ/pD5tsWzMNeuD6KQzy/sNhc7gTKwkgTiEqYtVchz8E5uLN+IunzX1lw6G6a1 X-Received: by 2002:a17:903:11cf:b0:178:a8f4:d511 with SMTP id q15-20020a17090311cf00b00178a8f4d511mr23350462plh.72.1666424500700; Sat, 22 Oct 2022 00:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424500; cv=none; d=google.com; s=arc-20160816; b=ahfgpbfMoX28KILAqXZBKbjrqo27HhfJmIHCf1hmplnA0GIu6wYg2fiaQwsH/sFHHd 5JZcpSAv3RfHpc4xG0w7v97EQHbXVi9WgoQqvRIxTfTdU9TCuzmF8tvSZgCzBpbYh1TD gPqWbDvn51MOfwV0MKQgaAiCGJ2BMFPNhrvYXjQCWsmEwnGleC76nzSyozICcDvvXXES L8rk4ZaxoCl9YEmkl8A/R46ItJmrLrUJGbyTUmSzrHS72MOoxWbF9o56WJ1qWKVeNhcG SHPxFw2rJVjQJD3zvJV41AGtCrPP2T8Rlap12uAYIgyJKIJHjwYhMB639H3dcsZ0A5EU F45Q== 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=if1KcrLKyOke5bRt0oqAFe9Gcc7PMKzZfxerwl9rtsc2CIcFRTkJ1x1+xDgouWBzna dsjeksH6eFPM0UtEtZM+BMi3KkwIMHchVudtWCNteLd6PwEOlS0HqlsTJ/FOjpogRDP4 KFuBZfA8eeUW9oAEZ+lMTu1CRJMx2vXccxqQitb7ESXFaIBGMYa/KaT10VHRdTLQuQy/ k+dELButXmFZM8XlDJl0yKcJVUyo8Pqwsx9sGhjjW7U5jrGEIApG3t3WnbDmqRn6Av2F enpe8sqOufpzHgyP8zNDEhHXdfmXex1wU62+ywaxzstHtZadhTYOdUmW1YhPA5W+cxH1 uEmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="QvAdd/Ts"; 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 l17-20020a170903245100b0017811e3927bsi31035438pls.622.2022.10.22.00.41.28; Sat, 22 Oct 2022 00:41:40 -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="QvAdd/Ts"; 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 S231176AbiJVHlJ (ORCPT + 99 others); Sat, 22 Oct 2022 03:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbiJVHkW (ORCPT ); Sat, 22 Oct 2022 03:40:22 -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 E38E643E43; Sat, 22 Oct 2022 00:37:53 -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 5B5A560AC7; Sat, 22 Oct 2022 07:36:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6801CC433C1; Sat, 22 Oct 2022 07:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424210; bh=7VdRluWHI+RLGwVR0BCIqAPVnPkYCKskJthMfKF0DfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QvAdd/TscqgDKzOPNT/7+5Oaf2GRXjBPFf57AnfZ3B0OYIZxvgi0qwuz2NT129ZT1 IZFuo21Ib7xMU2WgSpyqSmBM1Ye1bZaDBJCn90Qjob9HakAqEJYz8KdJp5O64//eL+ MIG56QHmkyGfwM0S+OIjVEAVkRp/REqyr68poC+s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gaosheng Cui , Srinivas Kandagatla Subject: [PATCH 5.19 061/717] nvmem: core: Fix memleak in nvmem_register() Date: Sat, 22 Oct 2022 09:19:00 +0200 Message-Id: <20221022072425.874526943@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747372736917808193?= X-GMAIL-MSGID: =?utf-8?q?1747372736917808193?= 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)