Skip to content

Commit 89240c6

Browse files
committed
Merge tag 'gpio-v4.17-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Sorry for lagging behind on sending the first batch of GPIO fixes for this cycle. Just too busy conferencing and the weather was too nice. Here it is anyway: some real important polishing on the error path facing userspace (tagged for stable as well) and some normal driver fixes. - Fix proper IRQ unmasking in the Aspeed driver. - Do not free unrequested descriptors on the errorpath when creating line handles from the userspace chardev requested GPIO lines. - Also fix the errorpath in the linehandle creation function. - Fix the get/set multiple GPIO lines for a few of the funky industrial GPIO cards on the ISA bus" * tag 'gpio-v4.17-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: pcie-idio-24: Fix off-by-one error in get_multiple loop gpio: pcie-idio-24: Fix port memory offset for get_multiple/set_multiple callbacks gpio: pci-idio-16: Fix port memory offset for get_multiple callback gpio: fix error path in lineevent_create gpioib: do not free unrequested descriptors gpio: fix aspeed_gpio unmask irq
2 parents f142f08 + e026646 commit 89240c6

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

drivers/gpio/gpio-aspeed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set)
384384
if (set)
385385
reg |= bit;
386386
else
387-
reg &= bit;
387+
reg &= ~bit;
388388
iowrite32(reg, addr);
389389

390390
spin_unlock_irqrestore(&gpio->lock, flags);

drivers/gpio/gpio-pci-idio-16.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
116116
unsigned long word_mask;
117117
const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
118118
unsigned long port_state;
119-
u8 __iomem ports[] = {
120-
idio16gpio->reg->out0_7, idio16gpio->reg->out8_15,
121-
idio16gpio->reg->in0_7, idio16gpio->reg->in8_15,
119+
void __iomem *ports[] = {
120+
&idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15,
121+
&idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15,
122122
};
123123

124124
/* clear bits array to a clean slate */
@@ -143,7 +143,7 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
143143
}
144144

145145
/* read bits from current gpio port */
146-
port_state = ioread8(ports + i);
146+
port_state = ioread8(ports[i]);
147147

148148
/* store acquired bits at respective bits array offset */
149149
bits[word_index] |= port_state << word_offset;

drivers/gpio/gpio-pcie-idio-24.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip,
206206
unsigned long word_mask;
207207
const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
208208
unsigned long port_state;
209-
u8 __iomem ports[] = {
210-
idio24gpio->reg->out0_7, idio24gpio->reg->out8_15,
211-
idio24gpio->reg->out16_23, idio24gpio->reg->in0_7,
212-
idio24gpio->reg->in8_15, idio24gpio->reg->in16_23,
209+
void __iomem *ports[] = {
210+
&idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15,
211+
&idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7,
212+
&idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23,
213213
};
214214
const unsigned long out_mode_mask = BIT(1);
215215

216216
/* clear bits array to a clean slate */
217217
bitmap_zero(bits, chip->ngpio);
218218

219219
/* get bits are evaluated a gpio port register at a time */
220-
for (i = 0; i < ARRAY_SIZE(ports); i++) {
220+
for (i = 0; i < ARRAY_SIZE(ports) + 1; i++) {
221221
/* gpio offset in bits array */
222222
bits_offset = i * gpio_reg_size;
223223

@@ -236,7 +236,7 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip,
236236

237237
/* read bits from current gpio port (port 6 is TTL GPIO) */
238238
if (i < 6)
239-
port_state = ioread8(ports + i);
239+
port_state = ioread8(ports[i]);
240240
else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask)
241241
port_state = ioread8(&idio24gpio->reg->ttl_out0_7);
242242
else
@@ -301,9 +301,9 @@ static void idio_24_gpio_set_multiple(struct gpio_chip *chip,
301301
const unsigned long port_mask = GENMASK(gpio_reg_size, 0);
302302
unsigned long flags;
303303
unsigned int out_state;
304-
u8 __iomem ports[] = {
305-
idio24gpio->reg->out0_7, idio24gpio->reg->out8_15,
306-
idio24gpio->reg->out16_23
304+
void __iomem *ports[] = {
305+
&idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15,
306+
&idio24gpio->reg->out16_23
307307
};
308308
const unsigned long out_mode_mask = BIT(1);
309309
const unsigned int ttl_offset = 48;
@@ -327,9 +327,9 @@ static void idio_24_gpio_set_multiple(struct gpio_chip *chip,
327327
raw_spin_lock_irqsave(&idio24gpio->lock, flags);
328328

329329
/* process output lines */
330-
out_state = ioread8(ports + i) & ~gpio_mask;
330+
out_state = ioread8(ports[i]) & ~gpio_mask;
331331
out_state |= (*bits >> bits_offset) & gpio_mask;
332-
iowrite8(out_state, ports + i);
332+
iowrite8(out_state, ports[i]);
333333

334334
raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
335335
}

drivers/gpio/gpiolib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
497497
struct gpiohandle_request handlereq;
498498
struct linehandle_state *lh;
499499
struct file *file;
500-
int fd, i, ret;
500+
int fd, i, count = 0, ret;
501501
u32 lflags;
502502

503503
if (copy_from_user(&handlereq, ip, sizeof(handlereq)))
@@ -558,6 +558,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
558558
if (ret)
559559
goto out_free_descs;
560560
lh->descs[i] = desc;
561+
count = i;
561562

562563
if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
563564
set_bit(FLAG_ACTIVE_LOW, &desc->flags);
@@ -628,7 +629,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
628629
out_put_unused_fd:
629630
put_unused_fd(fd);
630631
out_free_descs:
631-
for (; i >= 0; i--)
632+
for (i = 0; i < count; i++)
632633
gpiod_free(lh->descs[i]);
633634
kfree(lh->label);
634635
out_free_lh:
@@ -902,7 +903,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
902903
desc = &gdev->descs[offset];
903904
ret = gpiod_request(desc, le->label);
904905
if (ret)
905-
goto out_free_desc;
906+
goto out_free_label;
906907
le->desc = desc;
907908
le->eflags = eflags;
908909

0 commit comments

Comments
 (0)