mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds
@ 2024-03-04 11:22 Viresh Kumar
  2024-03-04 11:22 ` [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name() Viresh Kumar
  2024-03-04 11:38 ` [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Dhruva Gole
  0 siblings, 2 replies; 5+ messages in thread
From: Viresh Kumar @ 2024-03-04 11:22 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael J. Wysocki,
	Dhruva Gole, kernel test robot, linux-kernel

We currently get the following warning:

debugfs.c:105:54: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 8 [-Werror=format-truncation=]
                 snprintf(name, sizeof(name), "supply-%d", i);
                                                      ^~
debugfs.c:105:46: note: directive argument in the range [-2147483644, 2147483646]
                 snprintf(name, sizeof(name), "supply-%d", i);
                                              ^~~~~~~~~~~
debugfs.c:105:17: note: 'snprintf' output between 9 and 19 bytes into a destination of size 15
                 snprintf(name, sizeof(name), "supply-%d", i);

Fix this and another potential issues it by allocating larger arrays.
Use the exact string format to allocate the arrays without getting into
these issues again.

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>
---
V2: Use string name while allocating memory for the array to fix potential
issues later on.

 drivers/opp/debugfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
index ec030b19164a..27c3748347af 100644
--- a/drivers/opp/debugfs.c
+++ b/drivers/opp/debugfs.c
@@ -56,11 +56,11 @@ static void opp_debug_create_bw(struct dev_pm_opp *opp,
 				struct dentry *pdentry)
 {
 	struct dentry *d;
-	char name[20];
+	char name[] = "icc-path-XXXXXXXXXX"; /* Integers can take 10 chars max */
 	int i;
 
 	for (i = 0; i < opp_table->path_count; i++) {
-		snprintf(name, sizeof(name), "icc-path-%.1d", i);
+		snprintf(name, sizeof(name), "icc-path-%d", i);
 
 		/* Create per-path directory */
 		d = debugfs_create_dir(name, pdentry);
@@ -78,7 +78,7 @@ static void opp_debug_create_clks(struct dev_pm_opp *opp,
 				  struct opp_table *opp_table,
 				  struct dentry *pdentry)
 {
-	char name[12];
+	char name[] = "rate_hz_XXXXXXXXXX"; /* Integers can take 10 chars max */
 	int i;
 
 	if (opp_table->clk_count == 1) {
@@ -100,7 +100,7 @@ static void opp_debug_create_supplies(struct dev_pm_opp *opp,
 	int i;
 
 	for (i = 0; i < opp_table->regulator_count; i++) {
-		char name[15];
+		char name[] = "supply-XXXXXXXXXX"; /* Integers can take 10 chars max */
 
 		snprintf(name, sizeof(name), "supply-%d", i);
 
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name()
  2024-03-04 11:22 [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Viresh Kumar
@ 2024-03-04 11:22 ` Viresh Kumar
  2024-03-04 11:52   ` Dhruva Gole
  2024-03-04 11:38 ` [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Dhruva Gole
  1 sibling, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2024-03-04 11:22 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael J. Wysocki,
	Dhruva Gole, kernel test robot, linux-kernel

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(-)

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);
 }
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds
  2024-03-04 11:22 [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Viresh Kumar
  2024-03-04 11:22 ` [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name() Viresh Kumar
@ 2024-03-04 11:38 ` Dhruva Gole
  2024-03-05  6:09   ` Viresh Kumar
  1 sibling, 1 reply; 5+ messages in thread
From: Dhruva Gole @ 2024-03-04 11:38 UTC (permalink / raw)
  To: Viresh Kumar, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: linux-pm, Vincent Guittot, Rafael J. Wysocki, kernel test robot,
	linux-kernel, Dhruva Gole

Hi,

On 04/03/24 16:52, Viresh Kumar wrote:
> We currently get the following warning:
> 
> debugfs.c:105:54: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 8 [-Werror=format-truncation=]
>                   snprintf(name, sizeof(name), "supply-%d", i);
>                                                        ^~
> debugfs.c:105:46: note: directive argument in the range [-2147483644, 2147483646]
>                   snprintf(name, sizeof(name), "supply-%d", i);
>                                                ^~~~~~~~~~~
> debugfs.c:105:17: note: 'snprintf' output between 9 and 19 bytes into a destination of size 15
>                   snprintf(name, sizeof(name), "supply-%d", i);
> 
> Fix this and another potential issues it by allocating larger arrays.

Just to keep in mind while applying maybe: s/another/other

> Use the exact string format to allocate the arrays without getting into
> these issues again.
> 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>
> ---
> V2: Use string name while allocating memory for the array to fix potential
> issues later on.
> 
>   drivers/opp/debugfs.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
> index ec030b19164a..27c3748347af 100644
> --- a/drivers/opp/debugfs.c
> +++ b/drivers/opp/debugfs.c
> @@ -56,11 +56,11 @@ static void opp_debug_create_bw(struct dev_pm_opp *opp,
>   				struct dentry *pdentry)
>   {
>   	struct dentry *d;
> -	char name[20];
> +	char name[] = "icc-path-XXXXXXXXXX"; /* Integers can take 10 chars max */

LGTM!

>   	int i;
>   
>   	for (i = 0; i < opp_table->path_count; i++) {
> -		snprintf(name, sizeof(name), "icc-path-%.1d", i);
> +		snprintf(name, sizeof(name), "icc-path-%d", i);
>   
>   		/* Create per-path directory */
>   		d = debugfs_create_dir(name, pdentry);
> @@ -78,7 +78,7 @@ static void opp_debug_create_clks(struct dev_pm_opp *opp,
>   				  struct opp_table *opp_table,
>   				  struct dentry *pdentry)
>   {
> -	char name[12];
> +	char name[] = "rate_hz_XXXXXXXXXX"; /* Integers can take 10 chars max */
>   	int i;
>   
>   	if (opp_table->clk_count == 1) {
> @@ -100,7 +100,7 @@ static void opp_debug_create_supplies(struct dev_pm_opp *opp,
>   	int i;
>   
>   	for (i = 0; i < opp_table->regulator_count; i++) {
> -		char name[15];
> +		char name[] = "supply-XXXXXXXXXX"; /* Integers can take 10 chars max */

Feels like a better solution to me than the previous revision, thanks!


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

>   
>   		snprintf(name, sizeof(name), "supply-%d", i);
>   

-- 
Thanks and Regards,
Dhruva Gole

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name()
  2024-03-04 11:22 ` [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name() Viresh Kumar
@ 2024-03-04 11:52   ` Dhruva Gole
  0 siblings, 0 replies; 5+ messages in thread
From: Dhruva Gole @ 2024-03-04 11:52 UTC (permalink / raw)
  To: Viresh Kumar, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: linux-pm, Vincent Guittot, Rafael J. Wysocki, kernel test robot,
	linux-kernel

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);
>   }

-- 
Thanks and Regards,
Dhruva Gole

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds
  2024-03-04 11:38 ` [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Dhruva Gole
@ 2024-03-05  6:09   ` Viresh Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2024-03-05  6:09 UTC (permalink / raw)
  To: Dhruva Gole
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
	Vincent Guittot, Rafael J. Wysocki, kernel test robot,
	linux-kernel

On 04-03-24, 17:08, Dhruva Gole wrote:
> Hi,
> 
> On 04/03/24 16:52, Viresh Kumar wrote:
> > We currently get the following warning:
> > 
> > debugfs.c:105:54: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 8 [-Werror=format-truncation=]
> >                   snprintf(name, sizeof(name), "supply-%d", i);
> >                                                        ^~
> > debugfs.c:105:46: note: directive argument in the range [-2147483644, 2147483646]
> >                   snprintf(name, sizeof(name), "supply-%d", i);
> >                                                ^~~~~~~~~~~
> > debugfs.c:105:17: note: 'snprintf' output between 9 and 19 bytes into a destination of size 15
> >                   snprintf(name, sizeof(name), "supply-%d", i);
> > 
> > Fix this and another potential issues it by allocating larger arrays.
> 
> Just to keep in mind while applying maybe: s/another/other
> 
> > Use the exact string format to allocate the arrays without getting into
> > these issues again.
> > 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>
> > ---
> > V2: Use string name while allocating memory for the array to fix potential
> > issues later on.
> > 
> >   drivers/opp/debugfs.c | 8 ++++----
> >   1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
> > index ec030b19164a..27c3748347af 100644
> > --- a/drivers/opp/debugfs.c
> > +++ b/drivers/opp/debugfs.c
> > @@ -56,11 +56,11 @@ static void opp_debug_create_bw(struct dev_pm_opp *opp,
> >   				struct dentry *pdentry)
> >   {
> >   	struct dentry *d;
> > -	char name[20];
> > +	char name[] = "icc-path-XXXXXXXXXX"; /* Integers can take 10 chars max */

Integers can take 11 chars max, I forgot the negative symbol. Added
space for another byte and pushed the changes.

> Feels like a better solution to me than the previous revision, thanks!
> 
> 
> Reviewed-by: Dhruva Gole <d-gole@ti.com>

Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-05  6:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-04 11:22 [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Viresh Kumar
2024-03-04 11:22 ` [PATCH 2/2] OPP: debugfs: Fix warning around icc_get_name() Viresh Kumar
2024-03-04 11:52   ` Dhruva Gole
2024-03-04 11:38 ` [PATCH V2 1/2] OPP: debugfs: Fix warning with W=1 builds Dhruva Gole
2024-03-05  6:09   ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®