From patchwork Mon Feb 27 14:06:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 61967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2440964wrd; Mon, 27 Feb 2023 06:12:53 -0800 (PST) X-Google-Smtp-Source: AK7set+iV7qOX5pLzRuD29RWCTtlobmCBTWqQd6yKqBu7KgkSI2Ur1dEbtiOA6JVA4vcYbmdXlv6 X-Received: by 2002:a05:6402:1655:b0:4ac:b4b1:53fe with SMTP id s21-20020a056402165500b004acb4b153femr25498295edx.20.1677507173535; Mon, 27 Feb 2023 06:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677507173; cv=none; d=google.com; s=arc-20160816; b=NVUgmwtY5+e4BstqgFK2GW9vz3CmcfrooWkiwh6nt3vUgKHQZ4irlEQ764qciWjvTx by5/9ofkx7WBs4XFfu7ksGO0TVeVMj6CWfTVsj+BT0AyQTyWmlUwBk7wsE0eR9HgSoCv tO3jjeEBRHJaXhnVwaX/qDuZgTsZwlxKoXbdPRH3JQukeMCTjNNcBvMTGgrJSnxUErIl IncM9P1qPP1pwdaVILpd6WVRjw5ipS094Lka6zsrRJthxG4rQPaaCSXO+5WDFcI41ukU 4dPqOjHS4izXtPWP5H1yVmBBJ1R+k1R6te06eg2twL9Iqfd20MTxspMzfvgPDHSXniJe YJ7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=34ajj8Kul/R+j+e/zK5RNYV+ZwYVG0z2zp/2mXWs7l8=; b=KdMX1+DJ3w7JoFmC/RvmefFFTJbx0hD1KWK9lg/3JHXzEoc24iz3dHTqMnUm+4KDCo Y8NaBpzJkRYYA8hAgbMmXTApKy4ZCBq/LBD2e24AFcLXukbkBm9KDoicPPH18WXAJ16x hFQqC6CttB3FOQcF90saUd+etYXU43CKNDLn+1zgsm6n6JOSNxzlblO1HZNwiT60kaRZ x3I00xthuRrw9caZmcqPxLng0w/TpPoCs2YaiXlMLwADN6xyfYm3v6KJ/toTgrxtF2AM a9wSwe7U1zkRMd5ROpmFbCZM1i3Kc00tDanZOHqdmDB7++cpBEOxVs51ApI7TC3/dqe2 Q34w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HpODl6NT; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020a50fa96000000b004acdca43498si7861143edr.564.2023.02.27.06.12.30; Mon, 27 Feb 2023 06:12:53 -0800 (PST) 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=@intel.com header.s=Intel header.b=HpODl6NT; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjB0OIa (ORCPT + 99 others); Mon, 27 Feb 2023 09:08:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbjB0OI0 (ORCPT ); Mon, 27 Feb 2023 09:08:26 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E22AFF38; Mon, 27 Feb 2023 06:08:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677506902; x=1709042902; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iQdGRiKPZjZMBQPADUzT+Bwwba26L0M/zf5vmcYHm2E=; b=HpODl6NT6+VuPohEDyY5+jqOejfERjLYD3gZSmoLwuMcEwyBA0svvjhj 9ZV32HsJgbJ/nK56MjbA3i3nrnPS7kI9cRENcTe1sl49Dhq1jyF+ju4Ie CmdrXUuXxXwQ3z8GKMlrGnY+minpdqi9zbWA3RKF9S256Or5mHH/jnYN2 cilSYrhcmt0E28M1gxyplFwIzxcyb4nKphCQ8b5UmKI/UJT0IbehUXeZr QMu4C69h80XYGnKl84SuZlaSbz5TKS2WB7c24py5JGGibB+hWTCv5D/AW BZDEB+ZdqGVYxt/2db9wdaSJIdMt7SYcr/Mze9bn8nd/euKbzJ+n3Cx7i w==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="396416703" X-IronPort-AV: E=Sophos;i="5.98,332,1673942400"; d="scan'208";a="396416703" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 06:06:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="919366160" X-IronPort-AV: E=Sophos;i="5.98,332,1673942400"; d="scan'208";a="919366160" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga006.fm.intel.com with ESMTP; 27 Feb 2023 06:06:17 -0800 From: Srinivas Pandruvada To: hdegoede@redhat.com, markgross@kernel.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada , Dan Carpenter Subject: [PATCH] platform/x86/intel/tpmi: Fix double free reported by Smatch Date: Mon, 27 Feb 2023 06:06:14 -0800 Message-Id: <20230227140614.2913474-1-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758993762224976396?= X-GMAIL-MSGID: =?utf-8?q?1758993762224976396?= Fix warning: drivers/platform/x86/intel/tpmi.c:253 tpmi_create_device() warn: 'feature_vsec_dev' was already freed. If there is some error, feature_vsec_dev memory is freed as part of resource managed call intel_vsec_add_aux(). So, additional kfree() call is not required. Reordered res allocation and feature_vsec_dev, so that on error only res is freed. Reported-by: Dan Carpenter Link: https://lore.kernel.org/platform-driver-x86/Y%2FxYR7WGiPayZu%2FR@kili/T/#u Fixes: 47731fd2865f ("platform/x86/intel: Intel TPMI enumeration driver") Signed-off-by: Srinivas Pandruvada --- drivers/platform/x86/intel/tpmi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi.c b/drivers/platform/x86/intel/tpmi.c index c60733261c89..c999732b0f1e 100644 --- a/drivers/platform/x86/intel/tpmi.c +++ b/drivers/platform/x86/intel/tpmi.c @@ -209,14 +209,14 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, if (!name) return -EOPNOTSUPP; - feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL); - if (!feature_vsec_dev) + res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL); + if (!res) return -ENOMEM; - res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL); - if (!res) { + feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL); + if (!feature_vsec_dev) { ret = -ENOMEM; - goto free_vsec; + goto free_res; } snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name); @@ -239,6 +239,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, /* * intel_vsec_add_aux() is resource managed, no explicit * delete is required on error or on module unload. + * feature_vsec_dev memory is also freed as part of device + * delete. */ ret = intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev, feature_vsec_dev, feature_id_name); @@ -249,8 +251,6 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, free_res: kfree(res); -free_vsec: - kfree(feature_vsec_dev); return ret; }