From: Andre Przywara <andre.przywara@arm.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Yangtao Li <tiny.windzz@gmail.com>, Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
kernel test robot <lkp@intel.com>,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: sun50i: Fix build warning around snprint()
Date: Mon, 22 Apr 2024 23:39:58 +0100 [thread overview]
Message-ID: <20240422233958.0e2d992c@minigeek.lan> (raw)
In-Reply-To: <285de20a187f3e4baeb28f639b5bf55e914a3821.1713756666.git.viresh.kumar@linaro.org>
On Mon, 22 Apr 2024 09:01:09 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:
Hi,
> The Sun50i driver generates a warning with W=1:
>
> warning: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 2 [-Wformat-truncation=]
>
> Fix it by allocating a big enough array to print an integer.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202404191715.LDwMm2gP-lkp@intel.com/
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
For the records: as it stands right now, "speed" will always be smaller
than 10 at the moment, but it's indeed better to play safe here.
So the fix makes sense to me and fixes the issue:
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Tested-by: Andre Przywara <andre.przywara@arm.com>
Cheers,
Andre
> ---
> drivers/cpufreq/sun50i-cpufreq-nvmem.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> index 30e5c337611c..cd50cea16a87 100644
> --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> @@ -19,8 +19,6 @@
> #include <linux/pm_opp.h>
> #include <linux/slab.h>
>
> -#define MAX_NAME_LEN 7
> -
> #define NVMEM_MASK 0x7
> #define NVMEM_SHIFT 5
>
> @@ -208,7 +206,7 @@ static int sun50i_cpufreq_get_efuse(void)
> static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
> {
> int *opp_tokens;
> - char name[MAX_NAME_LEN];
> + char name[] = "speedXXXXXXXXXXX"; /* Integers can take 11 chars max */
> unsigned int cpu, supported_hw;
> struct dev_pm_opp_config config = {};
> int speed;
> @@ -235,7 +233,7 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
> config.supported_hw_count = 1;
> }
>
> - snprintf(name, MAX_NAME_LEN, "speed%d", speed);
> + snprintf(name, sizeof(name), "speed%d", speed);
> config.prop_name = name;
>
> for_each_possible_cpu(cpu) {
next prev parent reply other threads:[~2024-04-22 22:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 3:31 [PATCH] cpufreq: sun50i: Fix build warning around snprint() Viresh Kumar
2024-04-22 6:27 ` Chen-Yu Tsai
2024-04-22 22:39 ` Andre Przywara [this message]
2024-04-23 1:38 ` Julian Calaby
2024-04-23 6:12 ` Viresh Kumar
2024-04-23 6:28 ` Julian Calaby
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=20240422233958.0e2d992c@minigeek.lan \
--to=andre.przywara@arm.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=lkp@intel.com \
--cc=rafael@kernel.org \
--cc=samuel@sholland.org \
--cc=tiny.windzz@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=wens@csie.org \
/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