Skip to content

Commit d2059d3

Browse files
committed
cpufreq: sun50i: Fix build warning around snprint()
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 <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Viresh Kumar <[email protected]> Acked-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Andre Przywara <[email protected]> Tested-by: Andre Przywara <[email protected]> Reviewed-by: Julian Calaby <[email protected]>
1 parent 09d0aaa commit d2059d3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/cpufreq/sun50i-cpufreq-nvmem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <linux/pm_opp.h>
2020
#include <linux/slab.h>
2121

22-
#define MAX_NAME_LEN 7
23-
2422
#define NVMEM_MASK 0x7
2523
#define NVMEM_SHIFT 5
2624

@@ -208,7 +206,7 @@ static int sun50i_cpufreq_get_efuse(void)
208206
static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
209207
{
210208
int *opp_tokens;
211-
char name[MAX_NAME_LEN];
209+
char name[] = "speedXXXXXXXXXXX"; /* Integers can take 11 chars max */
212210
unsigned int cpu, supported_hw;
213211
struct dev_pm_opp_config config = {};
214212
int speed;
@@ -235,7 +233,7 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
235233
config.supported_hw_count = 1;
236234
}
237235

238-
snprintf(name, MAX_NAME_LEN, "speed%d", speed);
236+
snprintf(name, sizeof(name), "speed%d", speed);
239237
config.prop_name = name;
240238

241239
for_each_possible_cpu(cpu) {

0 commit comments

Comments
 (0)