From: Bamvor Zhang Jian <bamvor.zhangjian@linaro.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
Mark Brown <broonie@kernel.org>,
Bamvor Zhang Jian <bamvor.zhangjian@linaro.org>
Subject: Re: [PATCH 1/2] gpiolib: improve overlap check of range of gpio
Date: Sat, 14 Nov 2015 19:20:18 +0800 [thread overview]
Message-ID: <CAFy1USQBpAhqmaHbky+BS3Eru-XHxnshcYnDEvwBux6T9MrP5w@mail.gmail.com> (raw)
In-Reply-To: <CACRpkdbnua=3Wsu9TLkh3naKH=DjWixEuTSUZfz4mxk+mprudQ@mail.gmail.com>
Hi, Linus
On 11/14/2015 07:01 PM, Linus Walleij wrote:
> On Sat, Nov 14, 2015 at 9:38 AM, Bamvor Jian Zhang
> <bamvor.zhangjian@linaro.org> wrote:
>
>> There are limitations for the current checker:
>> 1. Could not check the overlap if the new gpiochip is the secondly
>> gpiochip.
>> 2. Could not check the overlap if the new gpiochip is overlap
>> with the left of gpiochip. E.g. if we insert [c, d] between
>> [a,b] and [e, f], and e >= c + d, it will successful even if
>> c < a + b.
>> 3. Allow overlap of base of different gpiochip.
>>
>> This patch fix these issues by checking the overlap of both right and
>> left gpiochip in the same loop statement.
>>
>> Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
>
> Very interesting patch!
>
>> +++ b/drivers/gpio/gpiolib.c
>> @@ -191,29 +191,48 @@ static int gpiochip_add_to_list(struct gpio_chip *chip)
>> {
>> struct list_head *pos;
>> struct gpio_chip *_chip;
>> + struct gpio_chip *_chip_prev = NULL;
>
> Syntactic comment: we have too many things named "chip" (something).
> I also hate _underscore in variable names.
>
> Please take this opportunity to rename:
>
> "_chip" to "iterator"
> "_chip_prev" to "previous"
>
> That they are both gpio_chip pointers is obvious from context.
>
> This renaming makes the code more readable.
>
>> int err = 0;
>>
>> - /* find where to insert our chip */
>> - list_for_each(pos, &gpio_chips) {
>> - _chip = list_entry(pos, struct gpio_chip, list);
>> - /* shall we insert before _chip? */
>> - if (_chip->base >= chip->base + chip->ngpio)
>> - break;
>> + if (list_empty(&gpio_chips)) {
>> + pos = gpio_chips.next;
>> + goto found;
>> }
>>
>> - /* are we stepping on the chip right before? */
>> - if (pos != &gpio_chips && pos->prev != &gpio_chips) {
>> - _chip = list_entry(pos->prev, struct gpio_chip, list);
>> - if (_chip->base + _chip->ngpio > chip->base) {
>> + list_for_each(pos, &gpio_chips) {
>> + _chip = list_entry(pos, struct gpio_chip, list);
>> + if (_chip->base == chip->base) {
>> dev_err(chip->dev,
>> - "GPIO integer space overlap, cannot add chip\n");
>> + "GPIO base overlap<%d>, cannot add chip\n",
>> + chip->base);
>> err = -EBUSY;
>> + goto err;
>
> OK that is the obvious case...
>
>> }
>> + if (_chip->base >= chip->base + chip->ngpio) {
>
> So if the iterator is above this chip.
>
>> + /* we are the before the first existence gpio*/
>> + if (pos->prev == &gpio_chips) {
>> + goto found;
>
> This comment needs proper english. It should say:
> "iterator is at the first GPIO chip so there is no previous one"
>
> Can't you just check if _chip_prev == NULL?
Yes, it is more clear.
>
>> + } else {
>> + if (_chip_prev->base + _chip_prev->ngpio
>> + <= chip->base)
>> + goto found;
>
> Here we are also below the previous chip, so above the current
> iterator and below the previous one so we found a "hole".
> Insert a comment that "we found a hole in the GPIO chip bases".
Yes, we found a valid range between _chip_prev and chip. Is it more clear
if we use ranges(means [base,base+ngpio]) instead of bases?
>
>> + }
>> + }
>> + _chip_prev = _chip;
>> }
>> + if (_chip->base + _chip->ngpio <= chip->base)
>> + goto found;
>
> And here we are above the last chip in the list.
> Insert a comment about that too.
> "We are beyond the last chip in the list".
Yeap. I am sorry for the variable naming and comments. I will update them
in the next patch. Except for the above comment, any comments or suggestions
for the logic?
Thanks
Bamvor
>
> Yours,
> Linus Walleij
>
next prev parent reply other threads:[~2015-11-14 11:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-14 8:38 [PATCH 0/2] Fix bugs in the insertion of gpiochip Bamvor Jian Zhang
2015-11-14 8:38 ` [PATCH 1/2] gpiolib: improve overlap check of range of gpio Bamvor Jian Zhang
2015-11-14 11:01 ` Linus Walleij
2015-11-14 11:20 ` Bamvor Zhang Jian [this message]
2015-11-14 11:30 ` Linus Walleij
2015-11-14 8:38 ` [PATCH 2/2] gpiolib: do not allow to insert an empty gpiochip Bamvor Jian Zhang
2015-11-14 11:03 ` Linus Walleij
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=CAFy1USQBpAhqmaHbky+BS3Eru-XHxnshcYnDEvwBux6T9MrP5w@mail.gmail.com \
--to=bamvor.zhangjian@linaro.org \
--cc=broonie@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@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).