From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB0D5C433FE for ; Tue, 15 Mar 2022 01:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344328AbiCOB43 (ORCPT ); Mon, 14 Mar 2022 21:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232835AbiCOB41 (ORCPT ); Mon, 14 Mar 2022 21:56:27 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228F35F5D; Mon, 14 Mar 2022 18:55:17 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KHbyz2H8Gz921M; Tue, 15 Mar 2022 09:53:15 +0800 (CST) Received: from [10.67.110.173] (10.67.110.173) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 15 Mar 2022 09:55:07 +0800 Message-ID: Date: Tue, 15 Mar 2022 09:55:07 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] tpm: Fix memory leak in tpmm_chip_alloc Content-Language: en-US To: Jason Gunthorpe CC: , , , , , , References: <20220307104827.40843-1-guozihua@huawei.com> <20220314163705.GA64706@ziepe.ca> From: "Guozihua (Scott)" In-Reply-To: <20220314163705.GA64706@ziepe.ca> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.110.173] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500024.china.huawei.com (7.185.36.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/3/15 0:37, Jason Gunthorpe wrote: > On Mon, Mar 07, 2022 at 06:48:27PM +0800, GUO Zihua wrote: >> Fix a memory leak in tpmm_chip_alloc. devm_add_action_or_reset would >> call put_device on error, while tpm->devs is left untouched. Call >> put_device on tpm->devs as well if devm_add_action_or_reset returns an >> error. >> >> Fixes: fdc915f7f719 ("tpm: expose spaces via a device link /dev/tpmrm") >> Signed-off-by: GUO Zihua >> drivers/char/tpm/tpm-chip.c | 13 +++++++++---- >> 1 file changed, 9 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >> index b009e7479b70..0a92334e8c40 100644 >> +++ b/drivers/char/tpm/tpm-chip.c >> @@ -308,6 +308,12 @@ static int tpm_class_shutdown(struct device *dev) >> return 0; >> } >> >> +static void tpm_chip_free(struct tpm_chip *chip) >> +{ >> + put_device(&chip->devs); >> + put_device(&chip->dev); >> +} >> + >> /** >> * tpm_chip_alloc() - allocate a new struct tpm_chip instance >> * @pdev: device to which the chip is associated >> @@ -396,8 +402,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, >> return chip; >> >> out: >> - put_device(&chip->devs); >> - put_device(&chip->dev); >> + tpm_chip_free(chip); >> return ERR_PTR(rc); >> } >> EXPORT_SYMBOL_GPL(tpm_chip_alloc); >> @@ -420,8 +425,8 @@ struct tpm_chip *tpmm_chip_alloc(struct device *pdev, >> return chip; >> >> rc = devm_add_action_or_reset(pdev, >> - (void (*)(void *)) put_device, >> - &chip->dev); >> + (void (*)(void *)) tpm_chip_free, >> + chip); >> if (rc) > > This looks like the same issue as was adressed by the recent discussion.. > > Jason > . Hi Jason, Would you mind refer me to the discussion? -- Best GUO Zihua