X86 platform drivers
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Cc: srinivas.pandruvada@linux.intel.com,
	Hans de Goede <hansg@kernel.org>,
	 platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 1/2] platform/x86/intel/uncore-freq: Replace sprintf() with snprintf()
Date: Tue, 30 Dec 2025 12:48:56 +0200 (EET)	[thread overview]
Message-ID: <f0c3235b-815d-c3f6-feb2-fa38ea2dc456@linux.intel.com> (raw)
In-Reply-To: <20251230080545.224954-2-kaushlendra.kumar@intel.com>

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.


  reply	other threads:[~2025-12-30 10:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=f0c3235b-815d-c3f6-feb2-fa38ea2dc456@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=kaushlendra.kumar@intel.com \
    --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