* [PATCH 0/2] platform/x86/intel/uncore-freq: String handling improvements
@ 2025-12-30 8:05 Kaushlendra Kumar
2025-12-30 8:05 ` [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf() Kaushlendra Kumar
2025-12-30 8:05 ` [PATCH 2/2] platform/x86/intel/uncore-freq: Replace sprintf() with sysfs_emit() Kaushlendra Kumar
0 siblings, 2 replies; 5+ messages in thread
From: Kaushlendra Kumar @ 2025-12-30 8:05 UTC (permalink / raw)
To: srinivas.pandruvada, hansg, ilpo.jarvinen
Cc: platform-driver-x86, Kaushlendra Kumar
This series replaces unsafe/deprecated string formatting functions in
the Intel uncore frequency driver with their safer alternatives.
Patch 1 replaces sprintf() with sysfs_emit() in sysfs show functions
for proper buffer bounds checking.
Patch 2 replaces sprintf() with snprintf() in device name formatting
to follow kernel best practices.
Kaushlendra Kumar (2):
platform/x86/intel/uncore-freq: Replace sprintf() with snprintf()
platform/x86/intel/uncore-freq: Replace sprintf() with sysfs_emit()
.../uncore-frequency/uncore-frequency-common.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf()
2025-12-30 8:05 [PATCH 0/2] platform/x86/intel/uncore-freq: String handling improvements Kaushlendra Kumar
@ 2025-12-30 8:05 ` Kaushlendra Kumar
2025-12-30 10:48 ` Ilpo Järvinen
2025-12-30 8:05 ` [PATCH 2/2] platform/x86/intel/uncore-freq: Replace sprintf() with sysfs_emit() Kaushlendra Kumar
1 sibling, 1 reply; 5+ messages in thread
From: Kaushlendra Kumar @ 2025-12-30 8:05 UTC (permalink / raw)
To: srinivas.pandruvada, hansg, ilpo.jarvinen
Cc: platform-driver-x86, Kaushlendra Kumar
Replace unbounded sprintf() calls with snprintf() to prevent potential
buffer overflows when formatting device names. While the current format
strings cannot overflow the buffer, using snprintf() follows kernel
best practices for string formatting.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
.../x86/intel/uncore-frequency/uncore-frequency-common.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
index 65897fae17df..c129dd450360 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
@@ -269,9 +269,10 @@ int uncore_freq_add_entry(struct uncore_data *data, int cpu)
goto uncore_unlock;
data->instance_id = ret;
- sprintf(data->name, "uncore%02d", ret);
+ snprintf(data->name, sizeof(data->name), "uncore%02d", ret);
} else {
- sprintf(data->name, "package_%02d_die_%02d", data->package_id, data->die_id);
+ snprintf(data->name, sizeof(data->name), "package_%02d_die_%02d",
+ data->package_id, data->die_id);
}
uncore_read(data, &data->initial_min_freq_khz, UNCORE_INDEX_MIN_FREQ);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] platform/x86/intel/uncore-freq: Replace sprintf() with sysfs_emit()
2025-12-30 8:05 [PATCH 0/2] platform/x86/intel/uncore-freq: String handling improvements Kaushlendra Kumar
2025-12-30 8:05 ` [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf() Kaushlendra Kumar
@ 2025-12-30 8:05 ` Kaushlendra Kumar
1 sibling, 0 replies; 5+ messages in thread
From: Kaushlendra Kumar @ 2025-12-30 8:05 UTC (permalink / raw)
To: srinivas.pandruvada, hansg, ilpo.jarvinen
Cc: platform-driver-x86, Kaushlendra Kumar
Replace sprintf() with sysfs_emit() in sysfs show functions. The
sysfs_emit() function is the preferred way to format sysfs output as
it ensures proper buffer bounds checking and correct return values.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
.../x86/intel/uncore-frequency/uncore-frequency-common.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
index c129dd450360..ff97e3d210ab 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
@@ -26,21 +26,21 @@ static ssize_t show_domain_id(struct kobject *kobj, struct kobj_attribute *attr,
{
struct uncore_data *data = container_of(attr, struct uncore_data, domain_id_kobj_attr);
- return sprintf(buf, "%u\n", data->domain_id);
+ return sysfs_emit(buf, "%u\n", data->domain_id);
}
static ssize_t show_fabric_cluster_id(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct uncore_data *data = container_of(attr, struct uncore_data, fabric_cluster_id_kobj_attr);
- return sprintf(buf, "%u\n", data->cluster_id);
+ return sysfs_emit(buf, "%u\n", data->cluster_id);
}
static ssize_t show_package_id(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct uncore_data *data = container_of(attr, struct uncore_data, package_id_kobj_attr);
- return sprintf(buf, "%u\n", data->package_id);
+ return sysfs_emit(buf, "%u\n", data->package_id);
}
#define MAX_UNCORE_AGENT_TYPES 4
@@ -77,7 +77,7 @@ static ssize_t show_attr(struct uncore_data *data, char *buf, enum uncore_index
if (ret)
return ret;
- return sprintf(buf, "%u\n", value);
+ return sysfs_emit(buf, "%u\n", value);
}
static ssize_t store_attr(struct uncore_data *data, const char *buf, ssize_t count,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf()
2025-12-30 8:05 ` [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf() Kaushlendra Kumar
@ 2025-12-30 10:48 ` Ilpo Järvinen
2025-12-30 12:45 ` Kumar, Kaushlendra
0 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2025-12-30 10:48 UTC (permalink / raw)
To: Kaushlendra Kumar; +Cc: srinivas.pandruvada, Hans de Goede, platform-driver-x86
On Tue, 30 Dec 2025, Kaushlendra Kumar wrote:
> Replace unbounded sprintf() calls with snprintf() to prevent potential
> buffer overflows when formatting device names. While the current format
> strings cannot overflow the buffer, using snprintf() follows kernel
> best practices for string formatting.
>
> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
> ---
> .../x86/intel/uncore-frequency/uncore-frequency-common.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
> index 65897fae17df..c129dd450360 100644
> --- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
> +++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
> @@ -269,9 +269,10 @@ int uncore_freq_add_entry(struct uncore_data *data, int cpu)
> goto uncore_unlock;
>
> data->instance_id = ret;
> - sprintf(data->name, "uncore%02d", ret);
> + snprintf(data->name, sizeof(data->name), "uncore%02d", ret);
> } else {
> - sprintf(data->name, "package_%02d_die_%02d", data->package_id, data->die_id);
> + snprintf(data->name, sizeof(data->name), "package_%02d_die_%02d",
> + data->package_id, data->die_id);
> }
>
> uncore_read(data, &data->initial_min_freq_khz, UNCORE_INDEX_MIN_FREQ);
Hi,
Thanks for the patch. Please use scnprintf() instead. You don't use the
return value so the distinction doesn't make a difference but it would be
useful to eventually only have one of them remaining, which should be
scnprintf() that gives a more sane return value than snprintf().
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf()
2025-12-30 10:48 ` Ilpo Järvinen
@ 2025-12-30 12:45 ` Kumar, Kaushlendra
0 siblings, 0 replies; 5+ messages in thread
From: Kumar, Kaushlendra @ 2025-12-30 12:45 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: srinivas.pandruvada@linux.intel.com, Hans de Goede,
platform-driver-x86@vger.kernel.org
On Tue, 30 Dec 2025, Ilpo Järvinen wrote:
> Hi,
>
> Thanks for the patch. Please use scnprintf() instead. You don't use the
> return value so the distinction doesn't make a difference but it would be
> useful to eventually only have one of them remaining, which should be
> scnprintf() that gives a more sane return value than snprintf().
Hi Ilpo,
Thank you for the review. I'll switch to scnprintf() and send v2.
Thanks,
Kaushlendra
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-30 12:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-30 8:05 [PATCH 0/2] platform/x86/intel/uncore-freq: String handling improvements Kaushlendra Kumar
2025-12-30 8:05 ` [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf() Kaushlendra Kumar
2025-12-30 10:48 ` Ilpo Järvinen
2025-12-30 12:45 ` Kumar, Kaushlendra
2025-12-30 8:05 ` [PATCH 2/2] platform/x86/intel/uncore-freq: Replace sprintf() with sysfs_emit() Kaushlendra Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox