Skip to content

Commit d15d6cf

Browse files
William Breathitt Graylinusw
authored andcommitted
gpio: 104-dio-48e: Fix control port offset computation off-by-one error
There are only two control ports, each controlling three distinct I/O ports. To compute the control port address offset for a respective I/O port, the I/O port address offset should be divided by 3; dividing by 2 may result in not only the wrong address offset but possibly also an out-of-bounds array memory access for a non-existent third control port. Fixes: 1b06d64 ("gpio: Add GPIO support for the ACCES 104-DIO-48E") Signed-off-by: William Breathitt Gray <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent af8c34c commit d15d6cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpio/gpio-104-dio-48e.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
7575
{
7676
struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
7777
const unsigned io_port = offset / 8;
78-
const unsigned control_port = io_port / 2;
78+
const unsigned int control_port = io_port / 3;
7979
const unsigned control_addr = dio48egpio->base + 3 + control_port*4;
8080
unsigned long flags;
8181
unsigned control;
@@ -115,7 +115,7 @@ static int dio48e_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
115115
{
116116
struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
117117
const unsigned io_port = offset / 8;
118-
const unsigned control_port = io_port / 2;
118+
const unsigned int control_port = io_port / 3;
119119
const unsigned mask = BIT(offset % 8);
120120
const unsigned control_addr = dio48egpio->base + 3 + control_port*4;
121121
const unsigned out_port = (io_port > 2) ? io_port + 1 : io_port;

0 commit comments

Comments
 (0)