Commit 87041a58 authored by Colin Pitrat's avatar Colin Pitrat Committed by Linus Walleij

gpio: sch: Fix Oops on module load on Asus Eee PC 1201

This fixes the issue descirbe in bug 117531
(https://bugzilla.kernel.org/show_bug.cgi?id=117531).
It's a regression introduced in linux 4.5 that causes a Oops at load of
gpio_sch and prevents powering off the computer.

The issue is that sch_gpio_reg_set is called in sch_gpio_probe before
gpio_chip data is initialized with the pointer to the sch_gpio struct. As
sch_gpio_reg_set calls gpiochip_get_data, it returns NULL which causes
the Oops.

The patch follows Mika's advice (https://lkml.org/lkml/2016/5/9/61) and
consists in modifying sch_gpio_reg_get and sch_gpio_reg_set to take a
sch_gpio struct directly instead of a gpio_chip, which avoids the call to
gpiochip_get_data.

Thanks Mika for your patience with me :-)

Cc: stable@vger.kernel.org
Signed-off-by: default avatarColin Pitrat <colin.pitrat@gmail.com>
Acked-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Acked-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent a99cde43
...@@ -61,9 +61,8 @@ static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio) ...@@ -61,9 +61,8 @@ static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
return gpio % 8; return gpio % 8;
} }
static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg) static int sch_gpio_reg_get(struct sch_gpio *sch, unsigned gpio, unsigned reg)
{ {
struct sch_gpio *sch = gpiochip_get_data(gc);
unsigned short offset, bit; unsigned short offset, bit;
u8 reg_val; u8 reg_val;
...@@ -75,10 +74,9 @@ static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg) ...@@ -75,10 +74,9 @@ static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg)
return reg_val; return reg_val;
} }
static void sch_gpio_reg_set(struct gpio_chip *gc, unsigned gpio, unsigned reg, static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned gpio, unsigned reg,
int val) int val)
{ {
struct sch_gpio *sch = gpiochip_get_data(gc);
unsigned short offset, bit; unsigned short offset, bit;
u8 reg_val; u8 reg_val;
...@@ -98,14 +96,15 @@ static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) ...@@ -98,14 +96,15 @@ static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
struct sch_gpio *sch = gpiochip_get_data(gc); struct sch_gpio *sch = gpiochip_get_data(gc);
spin_lock(&sch->lock); spin_lock(&sch->lock);
sch_gpio_reg_set(gc, gpio_num, GIO, 1); sch_gpio_reg_set(sch, gpio_num, GIO, 1);
spin_unlock(&sch->lock); spin_unlock(&sch->lock);
return 0; return 0;
} }
static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num) static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
{ {
return sch_gpio_reg_get(gc, gpio_num, GLV); struct sch_gpio *sch = gpiochip_get_data(gc);
return sch_gpio_reg_get(sch, gpio_num, GLV);
} }
static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
...@@ -113,7 +112,7 @@ static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) ...@@ -113,7 +112,7 @@ static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
struct sch_gpio *sch = gpiochip_get_data(gc); struct sch_gpio *sch = gpiochip_get_data(gc);
spin_lock(&sch->lock); spin_lock(&sch->lock);
sch_gpio_reg_set(gc, gpio_num, GLV, val); sch_gpio_reg_set(sch, gpio_num, GLV, val);
spin_unlock(&sch->lock); spin_unlock(&sch->lock);
} }
...@@ -123,7 +122,7 @@ static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num, ...@@ -123,7 +122,7 @@ static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
struct sch_gpio *sch = gpiochip_get_data(gc); struct sch_gpio *sch = gpiochip_get_data(gc);
spin_lock(&sch->lock); spin_lock(&sch->lock);
sch_gpio_reg_set(gc, gpio_num, GIO, 0); sch_gpio_reg_set(sch, gpio_num, GIO, 0);
spin_unlock(&sch->lock); spin_unlock(&sch->lock);
/* /*
...@@ -182,13 +181,13 @@ static int sch_gpio_probe(struct platform_device *pdev) ...@@ -182,13 +181,13 @@ static int sch_gpio_probe(struct platform_device *pdev)
* GPIO7 is configured by the CMC as SLPIOVR * GPIO7 is configured by the CMC as SLPIOVR
* Enable GPIO[9:8] core powered gpios explicitly * Enable GPIO[9:8] core powered gpios explicitly
*/ */
sch_gpio_reg_set(&sch->chip, 8, GEN, 1); sch_gpio_reg_set(sch, 8, GEN, 1);
sch_gpio_reg_set(&sch->chip, 9, GEN, 1); sch_gpio_reg_set(sch, 9, GEN, 1);
/* /*
* SUS_GPIO[2:0] enabled by default * SUS_GPIO[2:0] enabled by default
* Enable SUS_GPIO3 resume powered gpio explicitly * Enable SUS_GPIO3 resume powered gpio explicitly
*/ */
sch_gpio_reg_set(&sch->chip, 13, GEN, 1); sch_gpio_reg_set(sch, 13, GEN, 1);
break; break;
case PCI_DEVICE_ID_INTEL_ITC_LPC: case PCI_DEVICE_ID_INTEL_ITC_LPC:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment