clockevent: sun4i: Fix race condition in the probe code
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / power / bq2415x_charger.c
index 79a37f6..1f49986 100644 (file)
@@ -840,8 +840,7 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
        if (bq->automode < 1)
                return NOTIFY_OK;
 
-       sysfs_notify(&bq->charger.dev->kobj, NULL, "reported_mode");
-       bq2415x_set_mode(bq, bq->reported_mode);
+       schedule_delayed_work(&bq->work, 0);
 
        return NOTIFY_OK;
 }
@@ -892,6 +891,11 @@ static void bq2415x_timer_work(struct work_struct *work)
        int error;
        int boost;
 
+       if (bq->automode > 0 && (bq->reported_mode != bq->mode)) {
+               sysfs_notify(&bq->charger.dev->kobj, NULL, "reported_mode");
+               bq2415x_set_mode(bq, bq->reported_mode);
+       }
+
        if (!bq->autotimer)
                return;
 
@@ -1575,8 +1579,15 @@ static int bq2415x_probe(struct i2c_client *client,
        if (np) {
                bq->notify_psy = power_supply_get_by_phandle(np, "ti,usb-charger-detection");
 
-               if (!bq->notify_psy)
-                       return -EPROBE_DEFER;
+               if (IS_ERR(bq->notify_psy)) {
+                       dev_info(&client->dev,
+                               "no 'ti,usb-charger-detection' property (err=%ld)\n",
+                               PTR_ERR(bq->notify_psy));
+                       bq->notify_psy = NULL;
+               } else if (!bq->notify_psy) {
+                       ret = -EPROBE_DEFER;
+                       goto error_2;
+               }
        }
        else if (pdata->notify_device)
                bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
@@ -1598,27 +1609,27 @@ static int bq2415x_probe(struct i2c_client *client,
                ret = of_property_read_u32(np, "ti,current-limit",
                                &bq->init_data.current_limit);
                if (ret)
-                       return ret;
+                       goto error_2;
                ret = of_property_read_u32(np, "ti,weak-battery-voltage",
                                &bq->init_data.weak_battery_voltage);
                if (ret)
-                       return ret;
+                       goto error_2;
                ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
                                &bq->init_data.battery_regulation_voltage);
                if (ret)
-                       return ret;
+                       goto error_2;
                ret = of_property_read_u32(np, "ti,charge-current",
                                &bq->init_data.charge_current);
                if (ret)
-                       return ret;
+                       goto error_2;
                ret = of_property_read_u32(np, "ti,termination-current",
                                &bq->init_data.termination_current);
                if (ret)
-                       return ret;
+                       goto error_2;
                ret = of_property_read_u32(np, "ti,resistor-sense",
                                &bq->init_data.resistor_sense);
                if (ret)
-                       return ret;
+                       goto error_2;
        } else {
                memcpy(&bq->init_data, pdata, sizeof(bq->init_data));
        }