diff mbox

hwmon: (gpio-fan) Fix null pointer dereference at probe

Message ID 20171016121210.25556-1-miquel.raynal@free-electrons.com (mailing list archive)
State Accepted
Headers show

Commit Message

Miquel Raynal Oct. 16, 2017, 12:12 p.m. UTC
A previous commit changed the argument list of gpio_fan_get_of_data(),
removing the "struct *dev" argument and retrieving it instead from the
gpio_fan_data structure. The "dev" entry of gpio_fan_data was then
dereferenced to access the of_node field, leading to a kernel panic
during the probe as the "dev" entry of the gpio_fan_data structure was
not filled yet.

Fix this by setting fan_data->dev before calling gpio_fan_get_of_data().

Fixes: 5859d8d30737 ("hwmon: (gpio-fan) Get rid of platform data struct")
Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
---
 drivers/hwmon/gpio-fan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Oct. 16, 2017, 1:05 p.m. UTC | #1
On 10/16/2017 05:12 AM, Miquel Raynal wrote:
> A previous commit changed the argument list of gpio_fan_get_of_data(),
> removing the "struct *dev" argument and retrieving it instead from the
> gpio_fan_data structure. The "dev" entry of gpio_fan_data was then
> dereferenced to access the of_node field, leading to a kernel panic
> during the probe as the "dev" entry of the gpio_fan_data structure was
> not filled yet.
> 
> Fix this by setting fan_data->dev before calling gpio_fan_get_of_data().
> 
> Fixes: 5859d8d30737 ("hwmon: (gpio-fan) Get rid of platform data struct")
> Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>   drivers/hwmon/gpio-fan.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
> index 43b697380987..5c9a52599cf6 100644
> --- a/drivers/hwmon/gpio-fan.c
> +++ b/drivers/hwmon/gpio-fan.c
> @@ -510,11 +510,11 @@ static int gpio_fan_probe(struct platform_device *pdev)
>   	if (!fan_data)
>   		return -ENOMEM;
>   
> +	fan_data->dev = dev;
>   	err = gpio_fan_get_of_data(fan_data);
>   	if (err)
>   		return err;
>   
> -	fan_data->dev = dev;
>   	platform_set_drvdata(pdev, fan_data);
>   	mutex_init(&fan_data->lock);
>   
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 43b697380987..5c9a52599cf6 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -510,11 +510,11 @@  static int gpio_fan_probe(struct platform_device *pdev)
 	if (!fan_data)
 		return -ENOMEM;
 
+	fan_data->dev = dev;
 	err = gpio_fan_get_of_data(fan_data);
 	if (err)
 		return err;
 
-	fan_data->dev = dev;
 	platform_set_drvdata(pdev, fan_data);
 	mutex_init(&fan_data->lock);