[PATCH] cpufreq: sun50i: Fix build warning around snprint()

Julian Calaby julian.calaby at gmail.com
Mon Apr 22 18:38:24 PDT 2024


Hi Viresh,

On Mon, Apr 22, 2024 at 1:31 PM Viresh Kumar <viresh.kumar at linaro.org> wrote:
>
> 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 at intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202404191715.LDwMm2gP-lkp@intel.com/
> Signed-off-by: Viresh Kumar <viresh.kumar at linaro.org>

This'll absolutely fix the issue here, so:

Reviewed-by: Julian Calaby <julian.calaby at gmail.com>

However:

> ---
>  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
> @@ -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 */

Would it make sense to just set a static length for the string here,
say 17-20 characters and add a comment explaining the number, say: /*
"speed" + 11 chars for the int */

The string constant, while it'll probably be optimised away, seems
weird and wasteful.

Thanks,

-- 
Julian Calaby

Email: julian.calaby at gmail.com
Profile: http://www.google.com/profiles/julian.calaby/



More information about the linux-arm-kernel mailing list