diff mbox series

[2/2] OPP: debugfs: Fix warning around icc_get_name()

Message ID 0275dc46489419f34765c6ed389c0e9d6245fd31.1709551295.git.viresh.kumar@linaro.org
State Accepted
Commit 28330ceb953e39880ea77da4895bb902a1244860
Headers show
Series [V2,1/2] OPP: debugfs: Fix warning with W=1 builds | expand

Commit Message

Viresh Kumar March 4, 2024, 11:22 a.m. UTC
If the kernel isn't built with interconnect support, icc_get_name()
returns NULL and we get following warning:

drivers/opp/debugfs.c: In function 'bw_name_read':
drivers/opp/debugfs.c:43:42: error: '%.62s' directive argument is null [-Werror=format-overflow=]
         i = scnprintf(buf, sizeof(buf), "%.62s\n", icc_get_name(path));

Fix it.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202402141313.81ltVF5g-lkp@intel.com/
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/debugfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Dhruva Gole March 4, 2024, 11:52 a.m. UTC | #1
Hi,

On 04/03/24 16:52, Viresh Kumar wrote:
> If the kernel isn't built with interconnect support, icc_get_name()
> returns NULL and we get following warning:
> 
> drivers/opp/debugfs.c: In function 'bw_name_read':
> drivers/opp/debugfs.c:43:42: error: '%.62s' directive argument is null [-Werror=format-overflow=]
>           i = scnprintf(buf, sizeof(buf), "%.62s\n", icc_get_name(path));
> 
> Fix it.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202402141313.81ltVF5g-lkp@intel.com/
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---

Do we not need this:

Fixes: 0430b1d5704b0 ("opp: Expose bandwidth information via debugfs")

?

>   drivers/opp/debugfs.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
> index 27c3748347af..a9ebfdf0b6a1 100644
> --- a/drivers/opp/debugfs.c
> +++ b/drivers/opp/debugfs.c
> @@ -37,10 +37,12 @@ static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
>   			    size_t count, loff_t *ppos)
>   {
>   	struct icc_path *path = fp->private_data;
> +	const char *name = icc_get_name(path);
>   	char buf[64];
> -	int i;
> +	int i = 0;
>   
> -	i = scnprintf(buf, sizeof(buf), "%.62s\n", icc_get_name(path));
> +	if (name)
> +		i = scnprintf(buf, sizeof(buf), "%.62s\n", name);

Reviewed-by: Dhruva Gole <d-gole@ti.com>

>   
>   	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
>   }
diff mbox series

Patch

diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
index 27c3748347af..a9ebfdf0b6a1 100644
--- a/drivers/opp/debugfs.c
+++ b/drivers/opp/debugfs.c
@@ -37,10 +37,12 @@  static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
 			    size_t count, loff_t *ppos)
 {
 	struct icc_path *path = fp->private_data;
+	const char *name = icc_get_name(path);
 	char buf[64];
-	int i;
+	int i = 0;
 
-	i = scnprintf(buf, sizeof(buf), "%.62s\n", icc_get_name(path));
+	if (name)
+		i = scnprintf(buf, sizeof(buf), "%.62s\n", name);
 
 	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
 }