Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1045201pxp; Thu, 17 Mar 2022 01:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDylK7TwkuJjCvfGmIMKn4286tlDt+zIuszzXu5YnyiBFqaVdKgnxKRog2WFX7S49nWrkf X-Received: by 2002:a17:907:a40f:b0:6d7:9f56:b511 with SMTP id sg15-20020a170907a40f00b006d79f56b511mr3195212ejc.674.1647505221738; Thu, 17 Mar 2022 01:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647505221; cv=none; d=google.com; s=arc-20160816; b=j7b9A5wRw/2ybIjepwiNFPxuFSnFtsAJA+i41OsiUXyc9fLYsFMNUF/Wq9Meo3K0De fHLi7rdMYUk+LSEpsH4SL34IbL9tOj/ihce1wFcycnBQD+GrkEL686XrV0PKwh342ryX bFAxws75el7HCZgJcMgReN/oMMYDdwFMa5bZoCSnCZjF/081idVmBFVP2uBbp38+b99A No1xI4zVsTVHYA47fnV5QMxyTeaFy03BRZ96JxAW8xtT++anAOH2unWSSzbEAJJsgb41 6b2oscU1Mkn240N7brSu5fEFUsyvouggYxkB7pfPVFG40JNWSDsCUesg+2k70kT1WiAj OMDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=k9RDWJ+80DyaCaBtM35AlSHs9reYvuqq3nPe0cHy090=; b=Kd7kCWPKk2VCP/rntxP3VK6nbN2k4+MklWAZixJl+RTOnWv8RQRdEmnjQNpjiZal5h pwuuJ9CKI62IGVCvZ+scY8T4agNBdGbaXum65v1+R2cJvyLjYm+gLzVLSAzH4pJOq1tp VSo1BJYZoY7XxD8uOZyLSfDjO0Qs14+nN7ZagLNlHE+tjKVw6rJotEQOxi8WxAda+mdW KcbcdKqPIc3RWOxTXnDn+92kZ5sf9Cy3Tfwcs88HGxH8yKRJEfGkpvVYwAHrYQa9q2QE 31WpFCcvnp/Pz9zlrgLWrzhGbv7WwrsjIH5mGMP2d3+rmfNuvMj/1LZg0mSQOz77jxya IZPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PEN4IKfB; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne7-20020a1709077b8700b006da82529b9bsi2739877ejc.963.2022.03.17.01.19.56; Thu, 17 Mar 2022 01:20:21 -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=@kernel.org header.s=k20201202 header.b=PEN4IKfB; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbiCQHfU (ORCPT + 99 others); Thu, 17 Mar 2022 03:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230310AbiCQHfT (ORCPT ); Thu, 17 Mar 2022 03:35:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2963D99EF5; Thu, 17 Mar 2022 00:34:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id C7E9FB81DBB; Thu, 17 Mar 2022 07:34:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D938FC340EC; Thu, 17 Mar 2022 07:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647502441; bh=Wc1sRQU3uR0mSmWJBBzRcK0/llPMJJOfk/1hcqIXzP0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PEN4IKfBRDjB60E9+Brs4yqItI8jiftoePia8kIWx7rX0cye4EcmpXs0vCtNXpSyK a/0XxVFR24GHu4P1xkwAFnctI6CYibMjw/49t/3TpRKxdBzveddzwhPDnMSGvU/8xM UkqvQJ/QSwYKzU0o0pPENQsypkF1pNprm8UH58RzxUNo/7Ctm/k/ZbyTfwfo3fRbnp 9XJS1e21KcxUwnDWfuj4JTak8QBgM62W3d5eBrPNftYDSGtRqrMSkS0CE89oMt6hPE GbMH6CCW+plBK4smtX6B1DVybJr+RqrQy9oQI62tDdV2YKqFR3U1d0sG562pV5IdAR hAoecqZNh0POw== Date: Thu, 17 Mar 2022 09:33:11 +0200 From: Jarkko Sakkinen To: "Guozihua (Scott)" Cc: Jason Gunthorpe , linux-integrity@vger.kernel.org, wangweiyang2@huawei.com, xiujianfeng@huawei.com, weiyongjun1@huawei.com, peterhuewe@gmx.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tpm: Fix memory leak in tpmm_chip_alloc Message-ID: References: <20220307104827.40843-1-guozihua@huawei.com> <20220314163705.GA64706@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-8.6 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,T_SCC_BODY_TEXT_LINE 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 On Tue, Mar 15, 2022 at 09:55:07AM +0800, Guozihua (Scott) wrote: > > > 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? Please test: git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git And use tag tpmdd-next-v5.18-v2 If issues persists, let us know or send a fix. BR, Jarkko