From patchwork Mon Feb 15 01:41:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 8308421 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3AA5DC02AE for ; Mon, 15 Feb 2016 01:41:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C3962051F for ; Mon, 15 Feb 2016 01:41:55 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21426204EB for ; Mon, 15 Feb 2016 01:41:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aV8Ai-00064W-O7; Mon, 15 Feb 2016 01:41:52 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aV8Ag-00064P-Vt for tpmdd-devel@lists.sourceforge.net; Mon, 15 Feb 2016 01:41:50 +0000 X-ACL-Warn: Received: from mga03.intel.com ([134.134.136.65]) by sog-mx-2.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1aV8Ag-0007g6-3K for tpmdd-devel@lists.sourceforge.net; Mon, 15 Feb 2016 01:41:50 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 14 Feb 2016 17:41:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,448,1449561600"; d="scan'208";a="652145999" Received: from mmoreau-mobl.ger.corp.intel.com (HELO localhost) ([10.252.15.20]) by FMSMGA003.fm.intel.com with ESMTP; 14 Feb 2016 17:41:24 -0800 From: Jarkko Sakkinen To: Peter Huewe , Marcel Selhorst , David Howells Date: Mon, 15 Feb 2016 03:41:05 +0200 Message-Id: <1455500466-11266-3-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455500466-11266-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1455500466-11266-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -0.1 (/) X-Headers-End: 1aV8Ag-0007g6-3K Cc: "moderated list:TPM DEVICE DRIVER" , jmorris@namei.org, open list Subject: [tpmdd-devel] [PATCH 2/3] tpm: fix: return rc when devm_add_action() fails X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call put_device() and return error code if devm_add_action() fails. Signed-off-by: Jarkko Sakkinen Reported-by: Jason Gunthorpe Fixes: 8e0ee3c9faed ("tpm: fix the cleanup of struct tpm_chip") --- drivers/char/tpm/tpm-chip.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 2521425..274dd01 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -88,6 +88,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev, const struct tpm_class_ops *ops) { struct tpm_chip *chip; + int rc; chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (chip == NULL) @@ -136,7 +137,11 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev, chip->cdev.owner = chip->pdev->driver->owner; chip->cdev.kobj.parent = &chip->dev.kobj; - devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev); + rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev); + if (rc) { + put_device(&chip->dev); + return ERR_PTR(rc); + } return chip; }