diff mbox series

pinctrl: axp209: dereference pointer after it's been set

Message ID 20171213085503.31899-1-quentin.schulz@free-electrons.com
State New
Headers show
Series pinctrl: axp209: dereference pointer after it's been set | expand

Commit Message

Quentin Schulz Dec. 13, 2017, 8:55 a.m. UTC
The number of GPIOs is gotten from a field within the structure
referenced in the of_device.data but it was actually read before it was
retrieved, thus it was dereferencing a null pointer.

Set the number of GPIOs after retrieving of_device.data.

Fixes: e1190083b89b ("pinctrl: axp209: add support for AXP813 GPIOs")

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Reported-by: Mylène Josserand <mylene.josserand@free-electrons.com>
---
 drivers/pinctrl/pinctrl-axp209.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Mylene Josserand Dec. 13, 2017, 9:20 a.m. UTC | #1
Hello Quentin,

Le Wed, 13 Dec 2017 09:55:03 +0100,
Quentin Schulz <quentin.schulz@free-electrons.com> a écrit :

> The number of GPIOs is gotten from a field within the structure
> referenced in the of_device.data but it was actually read before it was
> retrieved, thus it was dereferencing a null pointer.
> 
> Set the number of GPIOs after retrieving of_device.data.
> 
> Fixes: e1190083b89b ("pinctrl: axp209: add support for AXP813 GPIOs")
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> Reported-by: Mylène Josserand <mylene.josserand@free-electrons.com>

Tested-by: Mylène Josserand <mylene.josserand@free-electrons.com>

Thanks,

Mylène

> ---
>  drivers/pinctrl/pinctrl-axp209.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c
> index 22d3bb0bf927..510a2821e910 100644
> --- a/drivers/pinctrl/pinctrl-axp209.c
> +++ b/drivers/pinctrl/pinctrl-axp209.c
> @@ -413,9 +413,11 @@ static int axp20x_pctl_probe(struct platform_device *pdev)
>  	pctl->chip.set			= axp20x_gpio_set;
>  	pctl->chip.direction_input	= axp20x_gpio_input;
>  	pctl->chip.direction_output	= axp20x_gpio_output;
> -	pctl->chip.ngpio		= pctl->desc->npins;
>  
>  	pctl->desc = (struct axp20x_pctrl_desc *)of_device_get_match_data(dev);
> +
> +	pctl->chip.ngpio		= pctl->desc->npins;
> +
>  	pctl->regmap = axp20x->regmap;
>  	pctl->dev = &pdev->dev;
>
Chen-Yu Tsai Dec. 14, 2017, 3:05 a.m. UTC | #2
On Wed, Dec 13, 2017 at 5:20 PM, Mylene JOSSERAND
<mylene.josserand@free-electrons.com> wrote:
> Hello Quentin,
>
> Le Wed, 13 Dec 2017 09:55:03 +0100,
> Quentin Schulz <quentin.schulz@free-electrons.com> a écrit :
>
>> The number of GPIOs is gotten from a field within the structure
>> referenced in the of_device.data but it was actually read before it was
>> retrieved, thus it was dereferencing a null pointer.
>>
>> Set the number of GPIOs after retrieving of_device.data.
>>
>> Fixes: e1190083b89b ("pinctrl: axp209: add support for AXP813 GPIOs")
>>
>> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
>> Reported-by: Mylène Josserand <mylene.josserand@free-electrons.com>
>
> Tested-by: Mylène Josserand <mylene.josserand@free-electrons.com>

Acked-by: Chen-Yu Tsai <wens@csie.org>
--
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
Linus Walleij Dec. 20, 2017, 8:07 a.m. UTC | #3
On Wed, Dec 13, 2017 at 9:55 AM, Quentin Schulz
<quentin.schulz@free-electrons.com> wrote:

> The number of GPIOs is gotten from a field within the structure
> referenced in the of_device.data but it was actually read before it was
> retrieved, thus it was dereferencing a null pointer.
>
> Set the number of GPIOs after retrieving of_device.data.
>
> Fixes: e1190083b89b ("pinctrl: axp209: add support for AXP813 GPIOs")
>
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> Reported-by: Mylène Josserand <mylene.josserand@free-electrons.com>

Patch applied with the tags for test and ACK.

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
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c
index 22d3bb0bf927..510a2821e910 100644
--- a/drivers/pinctrl/pinctrl-axp209.c
+++ b/drivers/pinctrl/pinctrl-axp209.c
@@ -413,9 +413,11 @@  static int axp20x_pctl_probe(struct platform_device *pdev)
 	pctl->chip.set			= axp20x_gpio_set;
 	pctl->chip.direction_input	= axp20x_gpio_input;
 	pctl->chip.direction_output	= axp20x_gpio_output;
-	pctl->chip.ngpio		= pctl->desc->npins;
 
 	pctl->desc = (struct axp20x_pctrl_desc *)of_device_get_match_data(dev);
+
+	pctl->chip.ngpio		= pctl->desc->npins;
+
 	pctl->regmap = axp20x->regmap;
 	pctl->dev = &pdev->dev;