Skip to contentSkip to conversation

Mask read inputs for get_multiple callbacks

PATCH In review William Breathitt Gray 2 participants 8 messages Oct 22, 2018 – Oct 31, 2018

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Mask read inputs for get_multiple callbacks

The implementation for several drivers' get_multiple callbacks return additional input states that were not requested by the mask passed in. Although the current caller in the kernel does not care, it would be prudent to ensure the behavior of the get_multiple implementations is to return exactly the requested input states and not more. This patchset ensures such behavior by applying a final mask on the read inputs before setting the bits array.

William Breathitt Gray (6):
gpio: 104-dio-48e: Mask read inputs for get_multiple
gpio: 104-idi-48e: Mask the read inputs for get_multiple
gpio: gpio-mm: Mask read inputs for get_multiple
gpio: ws16c48: Mask read inputs for get_multiple
gpio: pci-idio-16: Mask read inputs for get_multiple
gpio: pcie-idio-24: Mask read inputs for get_multiple

 drivers/gpio/gpio-104-dio-48e.c  | 2 +-
 drivers/gpio/gpio-104-idi-48.c   | 2 +-
 drivers/gpio/gpio-gpio-mm.c      | 2 +-
 drivers/gpio/gpio-pci-idio-16.c  | 2 +-
 drivers/gpio/gpio-pcie-idio-24.c | 2 +-
 drivers/gpio/gpio-ws16c48.c      | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/6 gpio: 104-dio-48e: Mask read inputs for get_multiple

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-104-dio-48e.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-104-dio-48e.c +1 -1
index 9c4e07fcb74b..92c8f944bf64 100644
@@ -222,7 +222,7 @@ static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 		port_state = inb(dio48egpio->base + ports[i]);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#2 lore raw

PATCH 2/6 gpio: 104-idi-48e: Mask the read inputs for get_multiple

In reply to William Breathitt Gray

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-104-idi-48.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-104-idi-48.c +1 -1
index 2c9738adb3a6..88dc6f2449f6 100644
@@ -128,7 +128,7 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 		port_state = inb(idi48gpio->base + ports[i]);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#3 lore raw

PATCH 3/6 gpio: gpio-mm: Mask read inputs for get_multiple

In reply to William Breathitt Gray

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-gpio-mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-gpio-mm.c +1 -1
index b56ff2efbf36..8c150fd68d9d 100644
@@ -211,7 +211,7 @@ static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 		port_state = inb(gpiommgpio->base + ports[i]);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#4 lore raw

PATCH 4/6 gpio: ws16c48: Mask read inputs for get_multiple

In reply to William Breathitt Gray

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-ws16c48.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-ws16c48.c +1 -1
index c7028eb0b8e1..5cf3697bfb15 100644
@@ -169,7 +169,7 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip,
 		port_state = inb(ws16c48gpio->base + i);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#5 lore raw

PATCH 5/6 gpio: pci-idio-16: Mask read inputs for get_multiple

In reply to William Breathitt Gray

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-pci-idio-16.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pci-idio-16.c +1 -1
index 25d16b2af1c3..6b7349783223 100644
@@ -146,7 +146,7 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip,
 		port_state = ioread8(ports[i]);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#6 lore raw

PATCH 6/6 gpio: pcie-idio-24: Mask read inputs for get_multiple

In reply to William Breathitt Gray

This patch masks the read inputs with the word mask in order to ensure only requested input states are returned in the bits array.

---
 drivers/gpio/gpio-pcie-idio-24.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pcie-idio-24.c +1 -1
index f953541e7890..52f1647a46fd 100644
@@ -243,7 +243,7 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip,
 			port_state = ioread8(&idio24gpio->reg->ttl_in0_7);
 
 		/* store acquired bits at respective bits array offset */
-		bits[word_index] |= port_state << word_offset;
+		bits[word_index] |= (port_state << word_offset) & word_mask;
 	}
 
 	return 0;
Signature · 1 line
2.19.1
#7 lore raw
In reply to William Breathitt Gray
Quoted 8 lines · William Breathitt Gray

The implementation for several drivers' get_multiple callbacks return additional input states that were not requested by the mask passed in. Although the current caller in the kernel does not care, it would be prudent to ensure the behavior of the get_multiple implementations is to return exactly the requested input states and not more. This patchset ensures such behavior by applying a final mask on the read inputs before setting the bits array.

Quoted 7 lines

William Breathitt Gray (6):
gpio: 104-dio-48e: Mask read inputs for get_multiple
gpio: 104-idi-48e: Mask the read inputs for get_multiple
gpio: gpio-mm: Mask read inputs for get_multiple
gpio: ws16c48: Mask read inputs for get_multiple
gpio: pci-idio-16: Mask read inputs for get_multiple
gpio: pcie-idio-24: Mask read inputs for get_multiple

All patches applied for v4.21.

Yours,
Linus Walleij