[1/1] gpio: pca953x: Move memcpy into mutex lock for set multiple function.
diff mbox

Message ID 1478582291-57976-1-git-send-email-preid@electromag.com.au
State New
Headers show

Commit Message

Phil Reid Nov. 8, 2016, 5:18 a.m. UTC
Need to ensure that reg_output is not updated while setting multiple
bits. This makes the mutex locking behaviour for the set_multiple call
consistent with that of the set_value call.

Signed-off-by: Phil Reid <preid@electromag.com.au>
---
 drivers/gpio/gpio-pca953x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Linus Walleij Nov. 8, 2016, 8:32 a.m. UTC | #1
On Tue, Nov 8, 2016 at 6:18 AM, Phil Reid <preid@electromag.com.au> wrote:

> Need to ensure that reg_output is not updated while setting multiple
> bits. This makes the mutex locking behaviour for the set_multiple call
> consistent with that of the set_value call.
>
> Signed-off-by: Phil Reid <preid@electromag.com.au>

Patch applied for fixes.

Stable? Fixes:?

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
Phil Reid Nov. 8, 2016, 9:03 a.m. UTC | #2
On 8/11/2016 16:32, Linus Walleij wrote:
> On Tue, Nov 8, 2016 at 6:18 AM, Phil Reid <preid@electromag.com.au> wrote:
>
>> Need to ensure that reg_output is not updated while setting multiple
>> bits. This makes the mutex locking behaviour for the set_multiple call
>> consistent with that of the set_value call.
>>
>> Signed-off-by: Phil Reid <preid@electromag.com.au>
>
> Patch applied for fixes.
>
> Stable? Fixes:?
>
> Yours,
> Linus Walleij
>
>
It looks like it was broken in my original implementation of the set_multiple call.
fixes commit: b4818afeacbd81821f89a89951471cffcb6a65e0

This one is pretty nasty, it should go into stable.

Patch
diff mbox

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index e422568..b0eb113 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -372,8 +372,8 @@  static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
 
 	bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
 
-	memcpy(reg_val, chip->reg_output, NBANK(chip));
 	mutex_lock(&chip->i2c_lock);
+	memcpy(reg_val, chip->reg_output, NBANK(chip));
 	for (bank = 0; bank < NBANK(chip); bank++) {
 		bank_mask = mask[bank / sizeof(*mask)] >>
 			   ((bank % sizeof(*mask)) * 8);
@@ -607,7 +607,6 @@  static int pca953x_irq_setup(struct pca953x_chip *chip,
 
 	if (client->irq && irq_base != -1
 			&& (chip->driver_data & PCA_INT)) {
-
 		ret = pca953x_read_regs(chip,
 					chip->regs->input, chip->irq_stat);
 		if (ret)