linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 09/11] gpiolib: provide a dedicated function for setting lineinfo
Date: Thu, 5 Dec 2019 18:47:50 +0200	[thread overview]
Message-ID: <CAHp75VckYszyD6eU8n4W75pGWrnWzo3GZ4rVg+8iwEs_4xJErA@mail.gmail.com> (raw)
In-Reply-To: <CAMRc=McEsrg_2O3VAwCNLHsd+dupmzNOeC2rc0V6t6vGyGjC9w@mail.gmail.com>

On Thu, Dec 5, 2019 at 3:45 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> czw., 5 gru 2019 o 11:21 Andy Shevchenko <andy.shevchenko@gmail.com> napisał(a):
> > On Thu, Dec 5, 2019 at 11:28 AM Bartosz Golaszewski
> > <bgolaszewski@baylibre.com> wrote:
> > > śr., 4 gru 2019 o 23:30 Andy Shevchenko <andy.shevchenko@gmail.com> napisał(a):
> > > > On Wed, Dec 4, 2019 at 6:02 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> > > > > +       if (desc->name) {
> > > > > +               strncpy(info->name, desc->name, sizeof(info->name));
> > > > > +               info->name[sizeof(info->name) - 1] = '\0';
> > > > > +       } else {
> > > > > +               info->name[0] = '\0';
> > > > > +       }
> > > > > +
> > > > > +       if (desc->label) {
> > > > > +               strncpy(info->consumer, desc->label, sizeof(info->consumer));
> > > > > +               info->consumer[sizeof(info->consumer) - 1] = '\0';
> > > > > +       } else {
> > > > > +               info->consumer[0] = '\0';
> > > > > +       }
> > > >
> > > > I think we have to fix GCC warnings first and then do whatever this patch does.
> > > >
> > >
> > > What GCC warnings are you referring to exactly?
> >
> > stncpy() against partial string without NUL-terminator.
> >
> > So, if desc->label is longer than info->consumer, it will be copied
> > partially. I don't check if the modern GCC clever enough to see the
> > next operation which does the termination.
> >
>
> I'm not sure I get it. What warnings does it produce and in what
> environment?

Some kind of
warning: ‘strncpy’ specified bound 16 equals destination size
[-Wstringop-truncation]

> I don't see any.

Good, I just checked and see none as well. It means GCC understands
that strncpy() is followed by guaranteed NUL-termination.

> If you want it simpler - we can do `snprintf(info->consumer,
> sizeof(info->consumer), desc->label ?: "")`.

It makes sense only in above context.

-- 
With Best Regards,
Andy Shevchenko

      reply	other threads:[~2019-12-05 16:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-04 15:59 [PATCH v2 00/11] gpiolib: add an ioctl() for monitoring line status changes Bartosz Golaszewski
2019-12-04 15:59 ` [PATCH v2 01/11] gpiolib: use 'unsigned int' instead of 'unsigned' in gpio_set_config() Bartosz Golaszewski
2019-12-04 22:18   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 02/11] gpiolib: have a single place of calling set_config() Bartosz Golaszewski
2019-12-04 22:18   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 03/11] gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc() Bartosz Golaszewski
2019-12-04 22:19   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 04/11] gpiolib: use gpiochip_get_desc() in linehandle_create() Bartosz Golaszewski
2019-12-04 22:20   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 05/11] gpiolib: use gpiochip_get_desc() in lineevent_create() Bartosz Golaszewski
2019-12-04 22:20   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 06/11] gpiolib: use gpiochip_get_desc() in gpio_ioctl() Bartosz Golaszewski
2019-12-04 16:25   ` Rainer Sickinger
2019-12-04 22:21   ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 07/11] gpiolib: rework the locking mechanism for lineevent kfifo Bartosz Golaszewski
2019-12-04 22:25   ` Andy Shevchenko
2019-12-05  9:31     ` Bartosz Golaszewski
2019-12-05 10:22       ` Andy Shevchenko
2019-12-04 15:59 ` [PATCH v2 08/11] gpiolib: emit a debug message when adding events to a full kfifo Bartosz Golaszewski
2019-12-04 22:28   ` Andy Shevchenko
2019-12-19 16:22     ` Bartosz Golaszewski
2019-12-04 15:59 ` [PATCH v2 09/11] gpiolib: provide a dedicated function for setting lineinfo Bartosz Golaszewski
2019-12-04 22:30   ` Andy Shevchenko
2019-12-05  9:28     ` Bartosz Golaszewski
2019-12-05 10:20       ` Andy Shevchenko
2019-12-05 13:45         ` Bartosz Golaszewski
2019-12-05 16:47           ` Andy Shevchenko [this message]

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=CAHp75VckYszyD6eU8n4W75pGWrnWzo3GZ4rVg+8iwEs_4xJErA@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).