Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 358766
b: refs/heads/master
c: 83cabe3
h: refs/heads/master
v: v3
  • Loading branch information
Alexandre Courbot authored and Grant Likely committed Feb 9, 2013
1 parent f97e91b commit 7e777d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cb1650d4e0da27e88c1a1bd8fe98c40ae1a5d313
refs/heads/master: 83cabe33eb05b51a6239a3df344d89cafac2306c
37 changes: 16 additions & 21 deletions trunk/drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,25 @@ struct gpio_chip *gpio_to_chip(unsigned gpio)
/* dynamic allocation of GPIOs, e.g. on a hotplugged device */
static int gpiochip_find_base(int ngpio)
{
int i;
int spare = 0;
int base = -ENOSPC;

for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) {
struct gpio_desc *desc = &gpio_desc[i];
struct gpio_chip *chip = desc->chip;

if (!chip) {
spare++;
if (spare == ngpio) {
base = i;
break;
}
} else {
spare = 0;
if (chip)
i -= chip->ngpio - 1;
}
struct gpio_chip *chip;
int base = ARCH_NR_GPIOS - ngpio;

list_for_each_entry_reverse(chip, &gpio_chips, list) {
/* found a free space? */
if (chip->base + chip->ngpio <= base)
break;
else
/* nope, check the space right before the chip */
base = chip->base - ngpio;
}

if (gpio_is_valid(base))
if (gpio_is_valid(base)) {
pr_debug("%s: found new base at %d\n", __func__, base);
return base;
return base;
} else {
pr_err("%s: cannot find free range\n", __func__);
return -ENOSPC;
}
}

/* caller ensures gpio is valid and requested, chip->get_direction may sleep */
Expand Down

0 comments on commit 7e777d5

Please sign in to comment.