public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Len Baker <len.baker@gmx.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Len Baker <len.baker@gmx.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Kees Cook <keescook@chromium.org>,
	linux-hardening@vger.kernel.org,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy()
Date: Tue, 10 Aug 2021 17:43:03 +0200	[thread overview]
Message-ID: <20210810154303.GA2508@titan> (raw)
In-Reply-To: <CAHp75VeAf_GYcF--=wXJmJZPr1YHn_gLFAFGHwsMCDX7Mxs5zw@mail.gmail.com>

Hi Andy, David and Jonathan

First of all thanks you very much for your code snippets ;)
More below.

On Tue, Aug 10, 2021 at 03:11:01PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 10, 2021 at 3:06 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Mon, Aug 9, 2021 at 7:14 PM Len Baker <len.baker@gmx.com> wrote:
>
>
>
> > Even if we leave the logic as is, this might be better
> >
> > if (orient[0] == '-')
> >    str = devm_kstrdup(dev, orient + 1, GFP_KERNEL);
>
> > else if (orient[0] != '0' || orient[1] != '\0')
> >    str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);
> > else
> >    str = devm_kstrdup(dev, orient, GFP_KERNEL);

I think the above snippet is the right one: Is compact and easy
to understand.

>
> Or these two swapped for better reading
>
>  else if (orient[0] == '0' **&& orient[1] == '\0')
>     str = devm_kstrdup(dev, orient, GFP_KERNEL);
> else
>     str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);
>
> And with a comment added that we negate the result according to the
> rules: 1) drop leading '-' (minus); 2) leave 0 as is; add leading '-'
> (minus).
>
> > if (!str)
> >    return -ENOMEM;

Also, I think that it is better to leave the logic as is and don't
try to use always the +/- sign.

Again thanks to all for the feedback.

Regards,
Len

  reply	other threads:[~2021-08-10 15:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-07 15:22 [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy() Len Baker
2021-08-08 16:25 ` Jonathan Cameron
2021-08-08 19:00   ` Andy Shevchenko
2021-08-09  9:21     ` Jonathan Cameron
2021-08-09 16:14       ` Len Baker
2021-08-10 12:06         ` Andy Shevchenko
2021-08-10 12:11           ` Andy Shevchenko
2021-08-10 15:43             ` Len Baker [this message]
2021-08-10  8:30       ` David Laight

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=20210810154303.GA2508@titan \
    --to=len.baker@gmx.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=keescook@chromium.org \
    --cc=lars@metafoo.de \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox