gpio: fix pca953x set_type 'scheduling while atomic' bug

Bill Gatliff reported the following bug when using the irq_chip facility
of the pca953x driver on a PPC platform:

BUG: scheduling while atomic: insmod/1530/0x00000002

He traced it back to an i2c transaction in pca953x_irq_set_type(), which
can be called with interrupt disabled (from __setup_irq()). As the i2c
controller can sleep while sending a message, this qualifies as a bad
idea.

This patch moves the i2c transaction to pca953x_irq_bus_sync_unlock(),
where it is actually safe to send an i2c message.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Marc Zyngier <maz@misterjones.org>
Reported-by: Bill Gatliff <bgat@billgatliff.com>
Cc: Eric Miao <eric.y.miao@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Marc Zyngier and committed by Linus Torvalds a2cb9aeb 3835541d

+13 -1
+13 -1
drivers/gpio/pca953x.c
··· 252 252 static void pca953x_irq_bus_sync_unlock(unsigned int irq) 253 253 { 254 254 struct pca953x_chip *chip = get_irq_chip_data(irq); 255 + uint16_t new_irqs; 256 + uint16_t level; 257 + 258 + /* Look for any newly setup interrupt */ 259 + new_irqs = chip->irq_trig_fall | chip->irq_trig_raise; 260 + new_irqs &= ~chip->reg_direction; 261 + 262 + while (new_irqs) { 263 + level = __ffs(new_irqs); 264 + pca953x_gpio_direction_input(&chip->gpio_chip, level); 265 + new_irqs &= ~(1 << level); 266 + } 255 267 256 268 mutex_unlock(&chip->irq_lock); 257 269 } ··· 290 278 else 291 279 chip->irq_trig_raise &= ~mask; 292 280 293 - return pca953x_gpio_direction_input(&chip->gpio_chip, level); 281 + return 0; 294 282 } 295 283 296 284 static struct irq_chip pca953x_irq_chip = {