diff mbox

gpiolib: fix chip order in gpio list

Message ID 1452203205-4660-1-git-send-email-julien.grossholtz@savoirfairelinux.com
State New
Headers show

Commit Message

Julien Grossholtz Jan. 7, 2016, 9:46 p.m. UTC
In some situations the gpio_list order is not correct.
As a consequence gpiochip_find_base returns the same
base number twice. This happens when a first ship is added
with manual base number, then other ships are added using
automatic base number.

To prevent this behaviour, this patch add the new ship after
the last element of the gpio list.

Signed-off-by: Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>
---
 drivers/gpio/gpiolib.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Linus Walleij Jan. 13, 2016, 10:11 a.m. UTC | #1
On Thu, Jan 7, 2016 at 10:46 PM, Julien Grossholtz
<julien.grossholtz@savoirfairelinux.com> wrote:

> In some situations the gpio_list order is not correct.
> As a consequence gpiochip_find_base returns the same
> base number twice. This happens when a first ship is added
> with manual base number, then other ships are added using
> automatic base number.
>
> To prevent this behaviour, this patch add the new ship after
> the last element of the gpio list.
>
> Signed-off-by: Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>

Patch looks correct to me so applied.

Bamvor: please comment if you see some problems.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bamvor Jian Zhang Jan. 14, 2016, 7:09 a.m. UTC | #2
On 01/13/2016 06:11 PM, Linus Walleij wrote:
> On Thu, Jan 7, 2016 at 10:46 PM, Julien Grossholtz
> <julien.grossholtz@savoirfairelinux.com> wrote:
>
>> In some situations the gpio_list order is not correct.
>> As a consequence gpiochip_find_base returns the same
>> base number twice. This happens when a first ship is added
>> with manual base number, then other ships are added using
>> automatic base number.
>>
>> To prevent this behaviour, this patch add the new ship after
s/ship/chip
>> the last element of the gpio list.
>>
>> Signed-off-by: Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>
>
> Patch looks correct to me so applied.
>
> Bamvor: please comment if you see some problems.
Nope, it could pass all the testcases I wrote.

Regards

Bamvor
>
> Yours,
> Linus Walleij
>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 3db34e7..a180573 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -226,8 +226,10 @@  static int gpiochip_add_to_list(struct gpio_chip *chip)
 	 */
 
 	iterator = list_last_entry(&gpio_chips, struct gpio_chip, list);
-	if (iterator->base + iterator->ngpio <= chip->base)
-		goto found;
+	if (iterator->base + iterator->ngpio <= chip->base) {
+		list_add(&chip->list, &iterator->list);
+		return 0;
+	}
 
 	dev_err(chip->parent,
 	       "GPIO integer space overlap, cannot add chip\n");