From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F1A11CF9B for ; Mon, 22 Apr 2024 22:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713825617; cv=none; b=MxTfLUF4cYkWO8w7ZuQZEb8E4XIN4b8VZ4epAV9ZLmxRFosaYYWIWs/SGmibbUb11HO3PgXN7X88mp3bKb9nrqwR6KnRItChPsfNtCL0rU0YpAgRVUDitO4FDpalRNGxHHLyBEUAnQAwGS1edDanu3EiKvanPVERgZZpK0D1VAc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713825617; c=relaxed/simple; bh=YYWQ72Ji1mlYlNcfWfkUgczygjka+1APIsmWDrb2QZ0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hLk5afU3x1szjsvz29ZSVsmeCR3ja5kuJcBxUHlbbdyVT70FHaG8xvDodcS/mwhMl9xI1OoqJHALTm6gi0TVETV15NN/c3gBzFLn1DDLg+/69QuP5riYgd3cpU9jFnYiITBMH+BaXtaiY/YSQj8+2CSqGqqhf8lvxqP5QNWwPac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F569339; Mon, 22 Apr 2024 15:40:42 -0700 (PDT) Received: from minigeek.lan (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6ABA13F7BD; Mon, 22 Apr 2024 15:40:12 -0700 (PDT) Date: Mon, 22 Apr 2024 23:39:58 +0100 From: Andre Przywara To: Viresh Kumar Cc: "Rafael J. Wysocki" , Yangtao Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-pm@vger.kernel.org, Vincent Guittot , kernel test robot , 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() Message-ID: <20240422233958.0e2d992c@minigeek.lan> In-Reply-To: <285de20a187f3e4baeb28f639b5bf55e914a3821.1713756666.git.viresh.kumar@linaro.org> References: <285de20a187f3e4baeb28f639b5bf55e914a3821.1713756666.git.viresh.kumar@linaro.org> Organization: Arm Ltd. X-Mailer: Claws Mail 4.2.0 (GTK 3.24.31; x86_64-slackware-linux-gnu) Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 22 Apr 2024 09:01:09 +0530 Viresh Kumar 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 > Closes: https://lore.kernel.org/oe-kbuild-all/202404191715.LDwMm2gP-lkp@intel.com/ > Signed-off-by: Viresh Kumar 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 Tested-by: Andre Przywara 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 > #include > > -#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) {