All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yujie Liu <yujie.liu@intel.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: lkp <lkp@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"oe-kbuild-all@lists.linux.dev" <oe-kbuild-all@lists.linux.dev>
Subject: Re: drivers/opp/debugfs.c:48:54: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 8
Date: Tue, 5 Mar 2024 13:37:52 +0800	[thread overview]
Message-ID: <ZeavsDQNBA/txKyb@yujie-X299> (raw)
In-Reply-To: <20240304112102.wih3u5ny3iero47n@vireshk-i7>

On Mon, Mar 04, 2024 at 04:51:02PM +0530, Viresh Kumar wrote:
> On 04-03-24, 16:30, Yujie Liu wrote:
> > This fixes the warning for "supply-%d". Seems there are other remaining
> > warnings as shown below. Would you like to take a look as well?
> 
> How about this instead to fix all warnings (drop the earlier change
> please) ?

We see the following errors after applying the new diff:

  CC      drivers/opp/debugfs.o
drivers/opp/debugfs.c: In function 'opp_debug_create_one':
drivers/opp/debugfs.c:92:57: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
   92 |                 snprintf(name, sizeof(name), "rate_hz_%d", i);
      |                                                         ^
In function 'opp_debug_create_clks',
    inlined from 'opp_debug_create_one' at drivers/opp/debugfs.c:164:2:
drivers/opp/debugfs.c:92:17: note: 'snprintf' output between 10 and 20 bytes into a destination of size 19
   92 |                 snprintf(name, sizeof(name), "rate_hz_%d", i);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/opp/debugfs.c: In function 'opp_debug_create_one':
drivers/opp/debugfs.c:107:56: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
  107 |                 snprintf(name, sizeof(name), "supply-%d", i);
      |                                                        ^
In function 'opp_debug_create_supplies',
    inlined from 'opp_debug_create_one' at drivers/opp/debugfs.c:165:2:
drivers/opp/debugfs.c:107:17: note: 'snprintf' output between 9 and 19 bytes into a destination of size 18
  107 |                 snprintf(name, sizeof(name), "supply-%d", i);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


An integer has positive and negative limits, and the range is from
-2147483648 to 2147483647 in decimal, so it seems that an integer can
have 11 digits at most.

> 
> diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
> index ec030b19164a..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);
>  }
> @@ -56,11 +58,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 +80,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 +102,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);
> 
> -- 
> viresh

  reply	other threads:[~2024-03-05  5:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14  5:43 drivers/opp/debugfs.c:48:54: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 8 kernel test robot
2024-02-14  5:58 ` Viresh Kumar
2024-02-21  6:01   ` Liu, Yujie
2024-03-04  6:54     ` Viresh Kumar
2024-03-04  8:30       ` Yujie Liu
2024-03-04 11:21         ` Viresh Kumar
2024-03-05  5:37           ` Yujie Liu [this message]
2024-03-05  6:10             ` Viresh Kumar
  -- strict thread matches above, loose matches on Subject: below --
2023-12-16 22:23 kernel test robot
2023-12-18  6:10 ` Viresh Kumar
2023-11-06 10:41 kernel test robot
2023-11-08  6:13 ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeavsDQNBA/txKyb@yujie-X299 \
    --to=yujie.liu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.