linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Andy Shevchenko <andy@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	brgl@bgdev.pl, linus.walleij@linaro.org
Subject: Re: [PATCH 1/4] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
Date: Wed, 13 Dec 2023 22:27:38 +0800	[thread overview]
Message-ID: <ZXm_WsIpgIyOUNHt@rigel> (raw)
In-Reply-To: <ZXm3rayrcvfO1t1Z@smile.fi.intel.com>

On Wed, Dec 13, 2023 at 03:54:53PM +0200, Andy Shevchenko wrote:
> On Tue, Dec 12, 2023 at 01:42:50PM +0800, Kent Gibson wrote:
> > Store the debounce period for a requested line locally, rather than in
> > the debounce_period_us field in the gpiolib struct gpio_desc.
> >
> > Add a global tree of lines containing supplemental line information
> > to make the debounce period available to be reported by the
> > GPIO_V2_GET_LINEINFO_IOCTL and the line change notifier.
>
> ...
>
> >  struct line {
> >  	struct gpio_desc *desc;
> > +	struct rb_node node;
>
> If you swap them, would it benefit in a code generation (bloat-o-meter)?
>

Didn't consider that placement within the scruct could impact code
generation.
Having the rb_nodes at the beginning of struct is preferable?

> >  };
>
> ...
>
> > +struct supinfo {
> > +	spinlock_t lock;
> > +	struct rb_root tree;
> > +};
>
> Same Q.
>

Same - I tend to put locks before the field(s) they cover.
But if the node being first results in nicer code then happy to swap.

> ...
>
> > +static struct supinfo supinfo;
>
> Why supinfo should be a struct to begin with? Seems to me as an unneeded
> complication.
>

Yeah, that is a hangover from an earlier iteration where supinfo was
contained in other object rather than being a global.
Could merge the struct definition into the variable now.

> ...
>
> > +			pr_warn("%s: duplicate line inserted\n", __func__);
>
> I hope at bare minimum we have pr_fmt(), but even though this is poor message
> that might require some information about exact duplication (GPIO chip label /
> name, line number, etc). Generally speaking the __func__ in non-debug messages
> _usually_ is a symptom of poorly written message.
>
> ...

Yeah, I wasn't sure about the best way to log here.

The details of chip or line etc don't add anything - seeing this error
means there is a logic error in the code - we have inserted a line
without erasing it.  Knowing which chip or line it happened to occur on
wont help debug it.  It should never happen, but you can't just leave it
unhandled, so I went with a basic log.

>
> > +out_unlock:
> > +	spin_unlock(&supinfo.lock);
>
> No use of cleanup.h?
>

Again, that is new to me, so no not yet.

> ...
>
> > +static inline bool line_is_supplemental(struct line *line)
> > +{
> > +	return READ_ONCE(line->debounce_period_us) != 0;
>
> " != 0" is redundant.
>

I prefer conversion from int to bool to be explicit, but if you
insist...

> > +}
>
> ...
>
> >  	for (i = 0; i < lr->num_lines; i++) {
> > -		if (lr->lines[i].desc) {
> > -			edge_detector_stop(&lr->lines[i]);
> > -			gpiod_free(lr->lines[i].desc);
> > +		line = &lr->lines[i];
> > +		if (line->desc) {
>
> Perhaps
>
> 		if (!line->desc)
> 			continue;
>
> ?

Seems reasonable - I was just going with what was already there.

>
> > +			edge_detector_stop(line);
> > +			if (line_is_supplemental(line))
> > +				supinfo_erase(line);
> > +			gpiod_free(line->desc);
> >  		}
> >  	}
>
> ...
>
> > +static int __init gpiolib_cdev_init(void)
> > +{
> > +	supinfo_init();
> > +	return 0;
> > +}
>
> It's a good practice to explain initcalls (different to the default ones),
> can you add a comment on top to explain the choice of this initcall, please?
>

Not sure what you mean.  This section used gpiolib-sysfs as a template,
and that has no documentation.

> > +postcore_initcall(gpiolib_cdev_init);
>

Thanks for the review - always instructive.

Cheers,
Kent.

  reply	other threads:[~2023-12-13 14:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  5:42 [PATCH 0/4] gpiolib: cdev: relocate debounce_period_us Kent Gibson
2023-12-12  5:42 ` [PATCH 1/4] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc Kent Gibson
2023-12-13 13:54   ` Andy Shevchenko
2023-12-13 14:27     ` Kent Gibson [this message]
2023-12-13 15:40       ` Bartosz Golaszewski
2023-12-13 15:59         ` Kent Gibson
2023-12-13 16:12           ` Andy Shevchenko
2023-12-13 16:15             ` Bartosz Golaszewski
2023-12-13 16:29               ` Andy Shevchenko
2023-12-13 19:03                 ` Bartosz Golaszewski
2023-12-13 20:07                   ` Andy Shevchenko
2023-12-14  0:18                     ` Kent Gibson
2023-12-14  2:15                       ` Kent Gibson
2023-12-14  9:40                         ` Bartosz Golaszewski
2023-12-14 14:35                           ` Andy Shevchenko
2023-12-14 14:47                             ` Kent Gibson
2023-12-13 16:14           ` Bartosz Golaszewski
2023-12-13 16:15         ` Kent Gibson
2023-12-13 16:16           ` Bartosz Golaszewski
2023-12-13 16:27           ` Andy Shevchenko
2023-12-12  5:42 ` [PATCH 2/4] gpiolib: remove " Kent Gibson
2023-12-12  5:42 ` [PATCH 3/4] gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo() Kent Gibson
2023-12-13 13:56   ` Andy Shevchenko
2023-12-13 14:07     ` Kent Gibson
2023-12-13 15:05       ` Andy Shevchenko
2023-12-13 15:11       ` Kent Gibson
2023-12-13 15:28         ` Andy Shevchenko
2023-12-12  5:42 ` [PATCH 4/4] gpiolib: cdev: improve documentation of get/set values Kent Gibson
2023-12-12 17:09 ` [PATCH 0/4] gpiolib: cdev: relocate debounce_period_us Bartosz Golaszewski
2023-12-12 23:58   ` Kent Gibson
2023-12-13 10:03     ` Bartosz Golaszewski
2023-12-13 13:17       ` Kent Gibson

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=ZXm_WsIpgIyOUNHt@rigel \
    --to=warthog618@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@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;
as well as URLs for NNTP newsgroup(s).