power: max77665: fix null pointer dereference
Sivaram Nair [Wed, 16 Jan 2013 11:28:11 +0000 (13:28 +0200)]
This patch fixes a null pointer dereferece that happens because the irq
handler is called before the charger is completely initialized.

Change-Id: I893fe0aba712965e36472146882272bdf115faa5
Signed-off-by: Sivaram Nair <sivaramn@nvidia.com>
Reviewed-on: http://git-master/r/191681
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/power/max77665-charger.c

index 52331b4..a74f663 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * max77665-charger.c - Battery charger driver
  *
- *  Copyright (C) 2012 nVIDIA corporation
+ *  Copyright (C) 2012-2013 NVIDIA corporation
  *  Syed Rafiuddin <srafiuddin@nvidia.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -461,18 +461,6 @@ static __devinit int max77665_battery_probe(struct platform_device *pdev)
                goto error;
        }
 
-       if (charger->plat_data->irq_base) {
-               ret = request_threaded_irq(charger->plat_data->irq_base +
-                               MAX77665_IRQ_CHARGER, NULL,
-                               max77665_charger_irq_handler,
-                               0, "charger_irq",
-                                       charger);
-               if (ret) {
-                       dev_err(&pdev->dev,
-                               "failed: irq request error :%d)\n", ret);
-                       goto chrg_error;
-               }
-       }
        charger->ac.name                = "ac";
        charger->ac.type                = POWER_SUPPLY_TYPE_MAINS;
        charger->ac.get_property        = max77665_ac_get_property;
@@ -522,6 +510,19 @@ static __devinit int max77665_battery_probe(struct platform_device *pdev)
        if (!charger->edev)
                return -ENODEV;
 
+       if (charger->plat_data->irq_base) {
+               ret = request_threaded_irq(charger->plat_data->irq_base +
+                               MAX77665_IRQ_CHARGER, NULL,
+                               max77665_charger_irq_handler,
+                               0, "charger_irq",
+                                       charger);
+               if (ret) {
+                       dev_err(&pdev->dev,
+                               "failed: irq request error :%d)\n", ret);
+                       goto chrg_error;
+               }
+       }
+
        ret = max77665_enable_charger(charger);
        if (ret < 0) {
                dev_err(charger->dev, "failed to initialize charger\n");