Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1477454pxb; Sun, 17 Jan 2021 10:16:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzf4ArXPyzC2ttoHt8c8vPWRKzui5rUQ7EnuDo0Bxa/DDzDvWXLwRxGoDnVSSiEjjqkqvM X-Received: by 2002:a05:6402:1249:: with SMTP id l9mr11348762edw.375.1610907397138; Sun, 17 Jan 2021 10:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610907397; cv=none; d=google.com; s=arc-20160816; b=vO9E8SWcWHsgTAHa9sLQm6/8T6jmPq54ykQRsqQHd/v9lldm9U2T+EgHmBFfExnYUb rU+4N3knWYZLUzf/8dkm1zoZUXiHoaLJq5tHKClC+Lssrd4/WWsaWg83WtPS8s55te4q EPyJN+vgz6/J+Om7iKbWvJM8aKXAwM2UNYBzcyTxlW6tOmSvMpoB6TabbbvICASfa60H aUD/jVPfUU3USwrrbcjLRVxtNJCORaITobgjw6IKJ4P9jthbeqZpNMK+NyThsB43EMGr Zeo7MM2JDfIif63I+V9lSScNxMgddoznptPm3gFb9XIGg+vrLh0P9gioHW2uwgbTHDu2 LbsA== 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=xClWGV83WK62DjQ4ppUW+vViWFu7N3KmfK7xWxUVYCQ=; b=eipmBiIsIBP/gf2t4th3CYvNIi+ST5+OFKHURIA6nBLSOGdrCfZ1j57v5+Jji5Wu2i 6ZnLjhDDsaFMY3BqKDMhHTqF6tfOwGDYA4qGKBiaz2lR9iQzS652lw03XiOjC5V+6QDs ZZ3JTd+ULf+KLZNxzgVpfuHraHA/FO09Jaw5PZdUNMwK7u0wwYOsYZzhZQvSolcGyheL 7swfzljTqmzbOK+2qljY9U7jZC0iMj2EtyTS3y2hVDMz9mdNc4/ktSD6G0UsN3kzPwyI Xrh3+9gsvZiebOp8wdEc37ieRwVuuvkBNW5ASQ8CqfhCZiB4Av6ckRQOVzOb/o8FpO5T S44A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nc1boJvq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si5610272edw.381.2021.01.17.10.16.13; Sun, 17 Jan 2021 10:16:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nc1boJvq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729321AbhAQSJK (ORCPT + 99 others); Sun, 17 Jan 2021 13:09:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:36464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728217AbhAQSJG (ORCPT ); Sun, 17 Jan 2021 13:09:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEE56207DE; Sun, 17 Jan 2021 18:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610906905; bh=As+JB9THonuWKdBjY+Axcqii9AVA5+fbThIZjXjBzkE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nc1boJvqYIITidkEzqtimmAAnFbxeHqJYyT2cun0WSeGiECJ7tB7nsGbadKLmcN0k zNe2l4I6cxC4co2Yj3LgZUnMX9sbNgiWemuZQnmAhfXIFbdhTMFHWnQg77qzNyUJ3L yhx7BaYEqbrVZTXSWOmQCjNq2kvbHvfXPIcetnCCPIusJuFC6TOaBl6RLXTd1HbI9c +ExZ/S4cCBrhA/PdO58lo+ZL/Rs2GV1iqH+Phi47Ahx7UYMwKVoUjJu4lmNLcBNA+D Q5rYiE4niwMyzpseK/Mm4Q4lS1CvnO0MzU+IfhTRZPy/IQ+rklYqrs/lN17Lhn0O/s dRvI662utpgPw== Date: Sun, 17 Jan 2021 20:08:20 +0200 From: Jarkko Sakkinen To: Lino Sanfilippo Cc: peterhuewe@gmx.de, jgg@ziepe.ca, stefanb@linux.vnet.ibm.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: Re: [PATCH 1/4] tpm: in case of error properly cleanup in tpmm_chip_alloc Message-ID: References: <1610760161-21982-1-git-send-email-LinoSanfilippo@gmx.de> <1610760161-21982-2-git-send-email-LinoSanfilippo@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1610760161-21982-2-git-send-email-LinoSanfilippo@gmx.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 16, 2021 at 02:22:38AM +0100, Lino Sanfilippo wrote: > From: Lino Sanfilippo > > In tpmm_chip_alloc() a resource management action handler is installed to > release the chip->dev in case of error. This will result in the chip being > freed if it was the last reference. If the installation of the handler was > not successful an error is returned to the caller. > However in this case the chip->dev reference is not put and thus the chip > is never freed. Fix this by releasing the reference "by hand" in case that > the action handler installation failed. > > Signed-off-by: Lino Sanfilippo > --- > drivers/char/tpm/tpm-chip.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index ddaeceb..e242d2e 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -423,11 +423,15 @@ struct tpm_chip *tpmm_chip_alloc(struct device *pdev, > (void (*)(void *)) put_device, > &chip->dev); > if (rc) > - return ERR_PTR(rc); > + goto put_dev; > > dev_set_drvdata(pdev, chip); > > return chip; > + > +put_dev: > + put_device(&chip->dev); > + return ERR_PTR(rc); > } > EXPORT_SYMBOL_GPL(tpmm_chip_alloc); > > -- > 2.7.4 > NAK [*] https://elixir.bootlin.com/linux/v5.11-rc3/source/include/linux/device.h#L257 /Jarkko