Skip to content

Commit d1e972a

Browse files
Marc Zyngierlinusw
authored andcommitted
gpio: tegra186: Fix chip_data type confusion
The tegra186 GPIO driver makes the assumption that the pointer returned by irq_data_get_irq_chip_data() is a pointer to a tegra_gpio structure. Unfortunately, it is actually a pointer to the inner gpio_chip structure, as mandated by the gpiolib infrastructure. Nice try. The saving grace is that the gpio_chip is the first member of tegra_gpio, so the bug has gone undetected since... forever. Fix it by performing a container_of() on the pointer. This results in no additional code, and makes it possible to understand how the whole thing works. Fixes: 5b2b135 ("gpio: Add Tegra186 support") Signed-off-by: Marc Zyngier <[email protected]> Cc: Thierry Reding <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Bartosz Golaszewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 64fd52a commit d1e972a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/gpio/gpio-tegra186.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,12 @@ static int tegra186_gpio_of_xlate(struct gpio_chip *chip,
343343
return offset + pin;
344344
}
345345

346+
#define to_tegra_gpio(x) container_of((x), struct tegra_gpio, gpio)
347+
346348
static void tegra186_irq_ack(struct irq_data *data)
347349
{
348-
struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
350+
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
351+
struct tegra_gpio *gpio = to_tegra_gpio(gc);
349352
void __iomem *base;
350353

351354
base = tegra186_gpio_get_base(gpio, data->hwirq);
@@ -357,7 +360,8 @@ static void tegra186_irq_ack(struct irq_data *data)
357360

358361
static void tegra186_irq_mask(struct irq_data *data)
359362
{
360-
struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
363+
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
364+
struct tegra_gpio *gpio = to_tegra_gpio(gc);
361365
void __iomem *base;
362366
u32 value;
363367

@@ -372,7 +376,8 @@ static void tegra186_irq_mask(struct irq_data *data)
372376

373377
static void tegra186_irq_unmask(struct irq_data *data)
374378
{
375-
struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
379+
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
380+
struct tegra_gpio *gpio = to_tegra_gpio(gc);
376381
void __iomem *base;
377382
u32 value;
378383

@@ -387,7 +392,8 @@ static void tegra186_irq_unmask(struct irq_data *data)
387392

388393
static int tegra186_irq_set_type(struct irq_data *data, unsigned int type)
389394
{
390-
struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
395+
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
396+
struct tegra_gpio *gpio = to_tegra_gpio(gc);
391397
void __iomem *base;
392398
u32 value;
393399

0 commit comments

Comments
 (0)