Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1599490rda; Mon, 23 Oct 2023 19:01:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcLz66AflUy0Stto+9jI/hBYL9o0YYaltd1M/hgOlV9r1Hkw4brPcM7I9/yUjtlh5GO+Bm X-Received: by 2002:a05:6e02:12cd:b0:352:a2f8:999a with SMTP id i13-20020a056e0212cd00b00352a2f8999amr14506901ilm.3.1698112888462; Mon, 23 Oct 2023 19:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698112888; cv=none; d=google.com; s=arc-20160816; b=Ta8VpmVqSmaeW2UKyV5Mn/Kl1v8ZSnxneloosq6e5xfmd4jYKhn0wMEiAvmty4sIhP cLEU5+g7R6Qdt2ImVJXprmERqfyRiNS7dqfVulfHE19W0lNqrIWKxip9J60uC17owQrq Z8gKqEsT0YKR/7fO5BZ7gT83xdyCD099nLgxI4Bf5T4rQbln3nkn293w9pJroge05HIn +BcrbMBa6ZnlYRQAdg/J9AFjC5tFKcrP5VPo/x140Ul7rh42tMYkFSfBVo2gGtVbjX+N ohWzNLLUBu8Qp7FtLvt+MLGgFXUpj1UohQmxYV2HOfTs/5oE8IGFsR/+qJBtGvAcexW9 D62Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:date:to:cc:from:subject:references :in-reply-to:content-transfer-encoding:mime-version:message-id :dkim-signature; bh=AkTpeEjZTpkpmSqXh/nmfVM05hJyiPzVaeWYg+v08jE=; fh=/xWz8nD/2pfqvkolW7mi+RfPly5wZq05v+6zvpWQBUs=; b=jjVCnGiIIZcVATqHwtahQz6epWk2DkO4PQNdpIuOHJ4sd0YINtXBaEJnEFeYOGxqxV H8pNZOvKHZJb46xlFibzmboUT3Ue0L3jkVEWIdcaONDAKIvg6CYdAEkvBHsNUBD+Q4WE TFoZXmhjN6KDgk1MsG0o4bjuBKuazMqGoXi9tSikG3d6wTaCpNoAvJNW0/0NIVPqO8Tg jcBj2xvw9XuSRcTOOmJsLf5Ms7T78dWt0dooFtWQg0n26kUJe04QmcWRWBH9HlqMwmkY iiOUfoJlh6mIIRhxyLwhnq5Xy56QO4q3F/t7u3481wW/JbQMzWwqBVLtTY85o6qmvrBn T6UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QVAPh1uP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id r36-20020a635d24000000b00563d74b6347si7611242pgb.863.2023.10.23.19.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 19:01:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QVAPh1uP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3AB0F809221E; Mon, 23 Oct 2023 19:00:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbjJXCAZ (ORCPT + 99 others); Mon, 23 Oct 2023 22:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbjJXCAY (ORCPT ); Mon, 23 Oct 2023 22:00:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA6C10C3 for ; Mon, 23 Oct 2023 19:00:22 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 377DCC433C8; Tue, 24 Oct 2023 02:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698112822; bh=5Sn3H4oSN3dJtZjA+ZBhX1Pu9c0nxls8h7MoaYAi7n0=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=QVAPh1uPdXfvl0LfK1KAM8xDPpdsB0lWPL47UpoeDyZqaQFMhkYzl8gzGx0GCHfqf gQbGpqiwZfqFXe8rEv/3HJgd9nfgOh1rHoBFIkRAGM6Hq7OWOIhWN/AIztHfJbzkfG jIbQtPU4rHmuwN5082Cys8ml8/FL0ypY7GgbSCpiwA52s+N69eeNjSevvwShE8mZt4 1J0vzY46xCWJFsVlKzXZpOuVra8oSuLZDGjhF/jW2omNlpIzmbtWo6Oj4OqVuUEW6Z xwhgWCrAW2f7OjdFsZ5SontrM8/djBmrCuWhvgnj80tD80TPXcLtrMk+6Ham9U1Vwi 8PRZ/QJ/Z2CSg== Message-ID: <909e5d44d6cd79924d6e62d1b649646f.sboyd@kernel.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20230922025216.3604978-1-make_ruc2021@163.com> References: <20230922025216.3604978-1-make_ruc2021@163.com> Subject: Re: [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe() From: Stephen Boyd Cc: linux-kernel@vger.kernel.org, Ma Ke To: Ma Ke , mchehab+huawei@kernel.org Date: Mon, 23 Oct 2023 19:00:20 -0700 User-Agent: alot/0.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 19:00:28 -0700 (PDT) Quoting Ma Ke (2023-09-21 19:52:16) > spmi_controller_alloc() allocates a memory space for ctrl. When some > errors occur, ctrl should be handled by spmi_controller_put() and set > spmi_controller->controller =3D NULL because spmi_controller->controller > has a dangling pointer to the freed memory. When the failure happens, > the function returns without calling spmi_controller_put() and setting > spmi_controller->controller =3D NULL, which will lead to a memory leak. >=20 > When the failure happens, we can fix it by calling spmi_controller_put() > and setting spmi_controller->controller =3D NULL in all of the places > where we call spmi_controller_put(). >=20 > Signed-off-by: Ma Ke > --- > drivers/spmi/hisi-spmi-controller.c | 1 + > 1 file changed, 1 insertion(+) >=20 > diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi= -controller.c > index 9cbd473487cb..5b3cfa7f5056 100644 > --- a/drivers/spmi/hisi-spmi-controller.c > +++ b/drivers/spmi/hisi-spmi-controller.c > @@ -321,6 +321,7 @@ static int spmi_controller_probe(struct platform_devi= ce *pdev) > =20 > err_put_controller: > spmi_controller_put(ctrl); > + spmi_controller->controller =3D NULL; The controller will most likely be freed after the put call one line above so this will oops. No thanks.