POWER: gpio-charger: Check result of kzalloc
PATCH 1/1 POWER: gpio-charger: Check result of kzalloc
Since kzalloc can return NULL we have to check its result.
--- drivers/power/gpio-charger.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/power/gpio-charger.c +4 -0
@@ -87,6 +87,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) } gpio_charger =kzalloc (sizeof (*gpio_charger),GFP_KERNEL ); +if (!gpio_charger) { +dev_err (&pdev->dev,"Failed to alloc driver structure\n" ); +return -ENOMEM ; + } charger = &gpio_charger->charger;
Signature · 1 line
1.5.6.5
PATCH 1/1 POWER: gpio-charger: Fix potential race between irq handler and probe/remove function
This patch fixes a potential race between the irq handler and the probe and remove functions.
The irq should not be requested before the chargers power_supply has been registered and has to be freed before the power_supply is unregistered, otherwise it is possible that the irq fires while the power_supply is not initialized yet or has already been freed.
While we are at it replace request_irq with request_any_context_irq.
--- drivers/power/gpio-charger.c | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-)
drivers/power/gpio-charger.c +13 -15
@@ -98,7 +98,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) charger->type = pdata->type; charger->properties = gpio_charger_properties; charger->num_properties =ARRAY_SIZE (gpio_charger_properties); - charger->get_property = gpio_charger_get_property; + charger->get_property = gpio_charger_get_property; charger->supplied_to = pdata->supplied_to; charger->num_supplicants = pdata->num_supplicants;
@@ -113,9 +113,17 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) goto err_gpio_free; } + gpio_charger->pdata = pdata; + + ret =power_supply_register (&pdev->dev, charger); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to register power supply: %d\n" , ret); + goto err_gpio_free; + } + irq =gpio_to_irq (pdata->gpio);if (irq >0 ) { - ret =request_irq (irq, gpio_charger_irq, + ret =request_any_context_irq (irq, gpio_charger_irq,IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING ,dev_name (&pdev->dev), charger);if (ret)
@@ -124,21 +132,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) gpio_charger->irq = irq; } - gpio_charger->pdata = pdata; - - ret =power_supply_register (&pdev->dev, charger); -if (ret <0 ) { -dev_err (&pdev->dev,"Failed to register power supply: %d\n" , ret); - goto err_irq_free; - } -platform_set_drvdata (pdev, gpio_charger);return 0 ; -err_irq_free: -if (gpio_charger->irq) -free_irq (gpio_charger->irq, charger); err_gpio_free:gpio_free (pdata->gpio); err_free:
@@ -150,10 +147,11 @@ static int __devexit gpio_charger_remove(struct platform_device *pdev) {struct gpio_charger *gpio_charger =platform_get_drvdata (pdev); -power_supply_unregister (&gpio_charger->charger); -if (gpio_charger->irq)free_irq (gpio_charger->irq, &gpio_charger->charger); + +power_supply_unregister (&gpio_charger->charger); +gpio_free (gpio_charger->pdata->gpio);platform_set_drvdata (pdev,NULL );
Signature · 1 line
1.5.6.5
Anton Vorontsov
AppliedRe: [PATCH] POWER: gpio-charger: Fix potential race between irq handler and probe/remove function
Quoted 10 lines · Lars-Peter Clausen
This patch fixes a potential race between the irq handler and the probe and remove functions.
The irq should not be requested before the chargerspower_supplyhas been registered and has to be freed before thepower_supplyis unregistered, otherwise it is possible that the irq fires while thepower_supplyis not initialized yet or has already been freed.While we are at it replace
request_irqwithrequest_any_context_irq.Signed-off-by Lars-Peter Clausen <[email protected]>
Applied to battery-2.6.git, thanks!
Signature · 2 lines
Anton Vorontsov Email: [email protected]
PATCH 1/1 POWER: gpio-chager: Provide default name for the power_supply
In reply to Lars-Peter ClausenThis patch sets a default name for the power_supply in case there was no name supplied through the platform_data.
--- drivers/power/gpio-charger.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/power/gpio-charger.c +1 -1
@@ -94,7 +94,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) charger = &gpio_charger->charger; - charger->name = pdata->name; + charger->name = pdata->name ?:"gpio-charger" ; charger->type = pdata->type; charger->properties = gpio_charger_properties; charger->num_properties =ARRAY_SIZE (gpio_charger_properties);
Signature · 1 line
1.5.6.5
Anton Vorontsov
AppliedRe: [PATCH] POWER: gpio-chager: Provide default name for the power_supply
Quoted 5 lines · Lars-Peter Clausen
This patch sets a default name for the
power_supplyin case there was no name supplied through theplatform_data.Signed-off-by Lars-Peter Clausen <[email protected]>---
Applied, thanks!
Quoted 16 lines
drivers/power/gpio-charger.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/power/gpio-charger.c +1
-1@@ -94,7 +94,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) charger = &gpio_charger->charger; - charger->name = pdata->name; + charger->name = pdata->name ?:"gpio-charger" ; charger->type = pdata->type; charger->properties = gpio_charger_properties; charger->num_properties =ARRAY_SIZE (gpio_charger_properties);
Quoted 4 lines · Lars-Peter Clausen
Since kzalloc can return NULL we have to check its result.
Signed-off-by Lars-Peter Clausen <[email protected]>---
Lars, Vasiliy, Dan,
Thanks for the patch! I applied the following:
commit 2e9ff5f5e4c6b034554f3539f29529265279102c
Author: Lars-Peter Clausen <[email protected]> Date: Thu Nov 18 23:08:37 2010 +0100
gpio-charger: Check result of kzalloc
Since kzalloc can return NULL we have to check its result.
drivers/power/gpio-charger.c +4 -0
@@ -87,6 +87,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev) } gpio_charger =kzalloc (sizeof (*gpio_charger),GFP_KERNEL ); +if (!gpio_charger) { +dev_err (&pdev->dev,"Failed to alloc driver structure\n" ); +return -ENOMEM ; + } charger = &gpio_charger->charger;