From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Kent Gibson <warthog618@gmail.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v2] gpio: consumer: new virtual driver
Date: Thu, 10 Aug 2023 17:53:23 +0300 [thread overview]
Message-ID: <ZNT546dM+7QX98pA@smile.fi.intel.com> (raw)
In-Reply-To: <CAMRc=Mf_BmhZLN1J2m4SnpmPJzZtYPcfdR54EfG9gR5Px_Ss-Q@mail.gmail.com>
On Wed, Aug 09, 2023 at 09:29:14AM +0200, Bartosz Golaszewski wrote:
> On Tue, Aug 8, 2023 at 8:11 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Tue, Aug 08, 2023 at 04:56:05PM +0200, Bartosz Golaszewski wrote:
...
> > But again, why not
> >
> > timer_data->val ^= 1;
>
> This is not ok in my book. If I need to think for more than a second
> about what it does, then it's worse. I put clarity over brevity.
Yes, this will require bit ops to check.
...
> > This can be avoided by
> >
> > key = kstrndup(skip_spaces(page), count, GFP_KERNEL);
> >
> > no?
> >
>
> No, because we also want to remove the trailing spaces and newlines.
> But if you have a different suggestion with existing helpers, let me
> know. I didn't find any.
kstrto*() are newline friendly. The rest as you noted can be covered with
sysfs_streq() / sysfs_match_string().
...
> > > + ret = kstrtoint(page, 0, &offset);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + /* Use -1 to indicate lookup by name. */
> >
> > This comment is unclear as offset can be -1 given by the user.
> > What does above mean in that context?
>
> I added this to the documentation. Negative number means: lookup by
> line name, positive or zero - lookup offset in chip.
Then add a link to the documentation from here? Because reading this comment
and the code is confusing.
> > > + if (offset > (U16_MAX - 1))
> >
> > And how does it related to this -1 if related at all?
>
> GPIOLIB interprets U16_MAX as "lookup by line name". So we can allow
> max (U16_MAX - 1). I will add a comment.
>
> > > + return -EINVAL;
...
> > > + struct gpio_consumer_device *dev;
> > > +
> > > + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> > > + if (!dev)
> > > + return ERR_PTR(-ENOMEM);
> > > +
> > > + dev->id = ida_alloc(&gpio_consumer_ida, GFP_KERNEL);
> > > + if (dev->id < 0) {
> > > + kfree(dev);
> >
> > Wondering if you can utilize cleanup.h.
>
> Whooaah! In february this year I suggested basic C RAII during my talk
> at fosdem and here we are? I missed this one. Yeah, I will use it!
> Even better, I will abuse the cr*p out of it in gpio-sim as well!
> Thanks for bringing this to my attention. This may be the best thing
> that happened to kernel C code in years if people widely adopt it.
> (This paragraph was written by a fan of GLib's autopointer paradigm.
> :) )
So let it be!
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-08-10 14:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 14:56 [PATCH v2] gpio: consumer: new virtual driver Bartosz Golaszewski
2023-08-08 17:23 ` Andy Shevchenko
2023-08-09 7:29 ` Bartosz Golaszewski
2023-08-10 14:53 ` Andy Shevchenko [this message]
2023-08-11 13:39 ` Bartosz Golaszewski
2023-08-11 14:32 ` Andy Shevchenko
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=ZNT546dM+7QX98pA@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=geert@linux-m68k.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viresh.kumar@linaro.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