iio: accel: kxcjk-1013: power off device if probe fails
authorIrina Tirdea <irina.tirdea@intel.com>
Wed, 10 Dec 2014 16:23:54 +0000 (18:23 +0200)
committerJonathan Cameron <jic23@kernel.org>
Fri, 12 Dec 2014 12:28:35 +0000 (12:28 +0000)
When the device is initialized in probe, it is also powered on.
If there is an error after the initialization, the device will
remain powered on.

Power off the device in case probe fails after device initialization.

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Suggested-by: Daniel Baluta <daniel.baluta@intel.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/kxcjk-1013.c

index 0dc6ccfbee4616ee07b9d40bca5406c72c428efc..a5e7d30bc368299563a136a3e72a4a1a4c6eb33b 100644 (file)
@@ -1240,21 +1240,25 @@ static int kxcjk1013_probe(struct i2c_client *client,
                                                KXCJK1013_IRQ_NAME,
                                                indio_dev);
                if (ret)
-                       return ret;
+                       goto err_poweroff;
 
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
                                                           indio_dev->id);
-               if (!data->dready_trig)
-                       return -ENOMEM;
+               if (!data->dready_trig) {
+                       ret = -ENOMEM;
+                       goto err_poweroff;
+               }
 
                data->motion_trig = devm_iio_trigger_alloc(&client->dev,
                                                          "%s-any-motion-dev%d",
                                                          indio_dev->name,
                                                          indio_dev->id);
-               if (!data->motion_trig)
-                       return -ENOMEM;
+               if (!data->motion_trig) {
+                       ret = -ENOMEM;
+                       goto err_poweroff;
+               }
 
                data->dready_trig->dev.parent = &client->dev;
                data->dready_trig->ops = &kxcjk1013_trigger_ops;
@@ -1263,7 +1267,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
                iio_trigger_get(indio_dev->trig);
                ret = iio_trigger_register(data->dready_trig);
                if (ret)
-                       return ret;
+                       goto err_poweroff;
 
                data->motion_trig->dev.parent = &client->dev;
                data->motion_trig->ops = &kxcjk1013_trigger_ops;
@@ -1312,6 +1316,8 @@ err_trigger_unregister:
                iio_trigger_unregister(data->dready_trig);
        if (data->motion_trig)
                iio_trigger_unregister(data->motion_trig);
+err_poweroff:
+       kxcjk1013_set_mode(data, STANDBY);
 
        return ret;
 }