From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22AC551DDF3; Wed, 30 Sep 2026 17:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789386; cv=none; b=ElqaN3DeaeB5QIWTfOTQiILt3rZO7/5T5QLtl8Grue0maLg4Mu6cu/KvJRkaSF3Fl4r8YXJ/7oWXjCqLTtBejB/KDEaNgvFDf/8YBbTHnHSez4H+Uw1Mb5octH04Iyo5vYtMwrRzdEfzXZzTiNN/4ElAtjnosqwwQWMOjRDcVWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789386; c=relaxed/simple; bh=LbxluZPA5Z/1RJRGXs5zHvJ1w4Hu8kOnn4bAoMnXREs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dYGyinrgfyXF79BfmT507b2tlst6R+EaD5GZ19TJBTHjTGkmdsPigDOFJKq+jzftr/5uk7PAGhSJAlwJ4SfXtmNx0xJoqBGhUKasaVE0Dov7nAf+Iwh4O+zYVgZwZ4GZ28YEQLoZHwN5yDdj0s1Wd4lRDM8NHqJTwEvTL5vU3IM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UWjQlxd9; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UWjQlxd9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790789384; x=1822325384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LbxluZPA5Z/1RJRGXs5zHvJ1w4Hu8kOnn4bAoMnXREs=; b=UWjQlxd9Q4ST9wZScwiOZWSkfJm2qzSn0Tq83NgSpgLoPC+zpQNLkfye xtev2X+JibB9qr/2tP8BY1K+FG/K2mwBYWxCW11P9ZBnXjArrECzQ1wx4 EfEPoEWBS/egDx/CFr5he0v9IBrSPc4xSzHlo809ALrtQxa8SRPgJLVVV VL8Zz/Pe+lIPpbMFkTw66gfbBLt+fktV0mvVsBVTrEcP0TUmj5e29zDsh RlzAeEvj0ulKkIhh87HNnnFGAnbDbXnrpjvYn7klOICN4bx67Vu/fIxUf Kn4gaKxFdy2j5Hq3O7zfPkBqVhPKA+WK4p7qLbPXCnr+RyXnXRiKKePWO A==; X-CSE-ConnectionGUID: fZAVlXEUR4CmxmPRHfS6Gw== X-CSE-MsgGUID: lKwqImRLSD+UX0IZ9BfI5g== X-IronPort-AV: E=McAfee;i="6800,10657,11921"; a="91632074" X-IronPort-AV: E=Sophos;i="6.27,133,1787036400"; d="scan'208";a="91632074" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2026 10:29:35 -0700 X-CSE-ConnectionGUID: TPI7wx2nS/6FdueA/oxAXQ== X-CSE-MsgGUID: SAFyCmU6RDesTPv6oiarWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,133,1787036400"; d="scan'208";a="278959423" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2026 10:29:34 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/20] platform/x86/intel/tpmi: Turn TPMI_GET_SINGLE_ENTRY_SIZE() into a function Date: Wed, 30 Sep 2026 10:29:09 -0700 Message-ID: <20260930172918.743656-13-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260930172918.743656-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260930172918.743656-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macro computing a feature instance size has a few problems. Its comment says the hardware reports the size in u32 units, but the conversion to bytes is spelled as a shift by 2, so the comment and the code have to be read together to see that they agree. Its body is a single conditional expression wrapped in a statement expression that it never needed. And it evaluates its argument twice. Make it a plain static function, tpmi_get_single_entry_size(), which fixes all three: the conversion becomes a multiply by sizeof(u32), there is nothing left to wrap, and the argument is evaluated once and type checked. No functional change intended. Suggested-by: Andy Shevchenko Suggested-by: Ilpo Järvinen Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x86/intel/tpmi_common.c index 83362d4bb726..7f6cd0fb23d7 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -149,13 +149,18 @@ struct tpmi_feature_state { } __packed; /* - * The size from hardware is in u32 units. This size is from a trusted hardware, - * but better to verify for pre silicon platforms. Set size to 0, when invalid. + * Return the size of a single feature interface instance in bytes. The + * hardware reports it in u32 units. The value comes from trusted hardware, + * but is still worth verifying on pre silicon platforms, so return 0 when + * it is out of range. */ -#define TPMI_GET_SINGLE_ENTRY_SIZE(pfs) \ -({ \ - pfs->pfs_header.entry_size > SZ_1K ? 0 : pfs->pfs_header.entry_size << 2; \ -}) +static u32 tpmi_get_single_entry_size(const struct intel_tpmi_pm_feature *pfs) +{ + if (pfs->pfs_header.entry_size > SZ_1K) + return 0; + + return pfs->pfs_header.entry_size * sizeof(u32); +} /* Used during auxbus device creation */ static DEFINE_IDA(intel_vsec_tpmi_ida); @@ -397,7 +402,7 @@ static int tpmi_mem_dump_show(struct seq_file *s, void *unused) u64 off; u8 *buffer; - size = TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size = tpmi_get_single_entry_size(pfs); if (!size) return -EIO; @@ -445,7 +450,7 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l void __iomem *mem; int ret; - size = TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size = tpmi_get_single_entry_size(pfs); if (!size) return -EIO; @@ -531,7 +536,7 @@ static void tpmi_set_control_base(struct intel_tpmi_info *tpmi_info, void __iomem *mem; u32 size; - size = TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size = tpmi_get_single_entry_size(pfs); if (!size) return; -- 2.43.0