mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
To: "Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"David E Box" <david.e.box@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 01/20] platform/x86/intel/tpmi: Use static strings for the feature device names
Date: Wed, 30 Sep 2026 10:28:58 -0700	[thread overview]
Message-ID: <20260930172918.743656-2-sathyanarayanan.kuppuswamy@linux.intel.com> (raw)
In-Reply-To: <20260930172918.743656-1-sathyanarayanan.kuppuswamy@linux.intel.com>

tpmi_create_device() builds the auxiliary device name in an on-stack
buffer and hands it to intel_vsec_add_aux(), which stores the pointer in
auxdev->name without copying the string. The auxiliary device outlives
tpmi_create_device(), so auxdev->name is left pointing into a stack frame
that has already been torn down.

Nothing dereferences auxdev->name after intel_vsec_add_aux() returns
today: auxiliary_device_init() only checks it for NULL and both
dev_set_name() calls copy into dev->kobj.name, while driver matching and
the modalias use dev_name() instead. So this is a latent problem rather
than a live one, but the auxiliary bus expects the name to outlive the
device, and the other intel_vsec_add_aux() caller already passes a string
literal.

Convert intel_tpmi_name() into a lookup of a static array of string
literals that already include the "tpmi-" prefix, and pass its return
value straight to intel_vsec_add_aux(). Using a static array instead of
a switch statement makes the lifetime of the returned strings obvious:
they are valid for as long as the module is loaded. The snprintf() along
with its on-stack buffer and length define are no longer needed.

The resulting device names are unchanged, so the feature drivers keep
matching on "intel_vsec.tpmi-<feature>" as before.

No functional change intended.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/platform/x86/intel/vsec_tpmi.c | 41 +++++++++++++-------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/intel/vsec_tpmi.c
index 0153dd57838e..9b2bd0c8cbe2 100644
--- a/drivers/platform/x86/intel/vsec_tpmi.c
+++ b/drivers/platform/x86/intel/vsec_tpmi.c
@@ -47,6 +47,7 @@
  */
 
 #include <linux/align.h>
+#include <linux/array_size.h>
 #include <linux/auxiliary_bus.h>
 #include <linux/bitfield.h>
 #include <linux/debugfs.h>
@@ -579,33 +580,31 @@ static void tpmi_set_control_base(struct auxiliary_device *auxdev,
 	tpmi_info->tpmi_control_mem = mem;
 }
 
+/*
+ * The TPMI IDs are sparse, so the unused entries are left NULL and are
+ * rejected by the caller like any other unsupported feature.
+ */
+static const char * const intel_tpmi_names[] = {
+	[TPMI_ID_RAPL]		= "tpmi-rapl",
+	[TPMI_ID_PEM]		= "tpmi-pem",
+	[TPMI_ID_UNCORE]	= "tpmi-uncore",
+	[TPMI_ID_SST]		= "tpmi-sst",
+	[TPMI_ID_PLR]		= "tpmi-plr",
+};
+
 static const char *intel_tpmi_name(enum intel_tpmi_id id)
 {
-	switch (id) {
-	case TPMI_ID_RAPL:
-		return "rapl";
-	case TPMI_ID_PEM:
-		return "pem";
-	case TPMI_ID_UNCORE:
-		return "uncore";
-	case TPMI_ID_SST:
-		return "sst";
-	case TPMI_ID_PLR:
-		return "plr";
-	default:
+	if (id >= ARRAY_SIZE(intel_tpmi_names))
 		return NULL;
-	}
-}
 
-/* String Length for tpmi-"feature_name(upto 8 bytes)" */
-#define TPMI_FEATURE_NAME_LEN	14
+	return intel_tpmi_names[id];
+}
 
 static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
 			      struct intel_tpmi_pm_feature *pfs,
 			      u64 pfs_start)
 {
 	struct intel_vsec_device *vsec_dev = tpmi_info->vsec_dev;
-	char feature_id_name[TPMI_FEATURE_NAME_LEN];
 	struct intel_vsec_device *feature_vsec_dev;
 	struct tpmi_feature_state feature_state;
 	struct resource *res, *tmp;
@@ -634,8 +633,6 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
 	feature_vsec_dev->num_resources = pfs->pfs_header.num_entries;
 	res = feature_vsec_dev->resource;
 
-	snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name);
-
 	for (i = 0, tmp = res; i < pfs->pfs_header.num_entries; i++, tmp++) {
 		u64 entry_size_bytes = pfs->pfs_header.entry_size * sizeof(u32);
 
@@ -654,9 +651,11 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
 	 * delete is required on error or on module unload.
 	 * feature_vsec_dev and res memory are also freed as part of
 	 * device deletion.
+	 *
+	 * "name" must outlive the auxiliary device, as the auxiliary bus
+	 * stores the pointer rather than a copy of the string.
 	 */
-	return intel_vsec_add_aux(&vsec_dev->auxdev.dev,
-				  feature_vsec_dev, feature_id_name);
+	return intel_vsec_add_aux(&vsec_dev->auxdev.dev, feature_vsec_dev, name);
 }
 
 static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info)
-- 
2.43.0


  reply	other threads:[~2026-09-30 17:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 17:28 [PATCH v3 00/20] Decouple PCI and auxbus details from Intel TPMI driver Kuppuswamy Sathyanarayanan
2026-09-30 17:28 ` Kuppuswamy Sathyanarayanan [this message]
2026-09-30 17:28 ` [PATCH v3 02/20] platform/x86/intel/vsec: Pass a struct device to intel_vsec_set_mapping() Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 03/20] platform/x86/intel/tpmi: Remove unused vsec_dev from intel_tpmi_pm_feature Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 04/20] platform/x86/intel/tpmi: Get tpmi_info directly from the parent device Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 05/20] platform/x86/intel/tpmi: Keep the feature resources in intel_tpmi_info Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 06/20] platform/x86/intel/tpmi: Describe a TPMI instance by its two devices Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 07/20] platform/x86/intel/tpmi: Drop unused arg from tpmi_set_control_base() Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 08/20] platform/x86/intel/tpmi: Do not assume TPMI is enumerated from PCI Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 09/20] platform/x86/intel/tpmi: Split out enumeration independent init and exit Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 10/20] platform/x86/intel/tpmi: Split off the PCI VSEC enumeration Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 11/20] platform/x86/intel/tpmi: Include the headers tpmi_common.c relies on Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 12/20] platform/x86/intel/tpmi: Turn TPMI_GET_SINGLE_ENTRY_SIZE() into a function Kuppuswamy Sathyanarayanan
2026-10-01 18:04   ` Andy Shevchenko
2026-09-30 17:29 ` [PATCH v3 13/20] platform/x86/intel/tpmi: Use guard() for tpmi_dev_lock in the status read Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 14/20] platform/x86/intel/tpmi: Use scope based cleanup in the memory dump Kuppuswamy Sathyanarayanan
2026-10-01 18:06   ` Andy Shevchenko
2026-10-01 18:18     ` Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 15/20] platform/x86/intel/tpmi: Build the TPMI control words in one expression Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 16/20] platform/x86/intel/tpmi: Use DEFINE_SHOW_STORE_ATTRIBUTE() for mem_write Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 17/20] platform/x86/intel/tpmi: Use scnprintf() to build the debugfs names Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 18/20] platform/x86/intel/tpmi: Use DEFINE_RES_MEM() for the feature resources Kuppuswamy Sathyanarayanan
2026-10-01 18:09   ` Andy Shevchenko
2026-09-30 17:29 ` [PATCH v3 19/20] platform/x86/intel/tpmi: Declare the loop counters in their loops Kuppuswamy Sathyanarayanan
2026-10-01 18:12   ` Andy Shevchenko
2026-10-01 21:02     ` Kuppuswamy Sathyanarayanan
2026-09-30 17:29 ` [PATCH v3 20/20] platform/x86/intel/tpmi: Describe the device creation policy on the function Kuppuswamy Sathyanarayanan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930172918.743656-2-sathyanarayanan.kuppuswamy@linux.intel.com \
    --to=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=david.e.box@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®