mfd: tps80031: rewrite exit path in probe failure
Laxman Dewangan [Thu, 26 Jul 2012 11:00:58 +0000 (16:00 +0530)]
Rewrite exit path in case of failure in registration in
probe.

Change-Id: I6c2a8ce3d4fcc01dff97eeea63124d2da419da27
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/118956
Reviewed-by: Automatic_Commit_Validation_User

drivers/mfd/tps80031.c

index 691c9d2..42e1faa 100644 (file)
@@ -1303,7 +1303,7 @@ static int __devinit tps80031_i2c_probe(struct i2c_client *client,
                if (!tps->client) {
                        dev_err(&client->dev, "can't attach client %d\n", i);
                        ret = -ENOMEM;
-                       goto fail;
+                       goto fail_client_reg;
                }
                i2c_set_clientdata(tps->client, tps80031);
                mutex_init(&tps->lock);
@@ -1314,7 +1314,7 @@ static int __devinit tps80031_i2c_probe(struct i2c_client *client,
                        ret = PTR_ERR(tps80031->regmap[i]);
                        dev_err(&client->dev,
                                "regmap %d init failed, err %d\n", i, ret);
-                       goto fail;
+                       goto fail_client_reg;
                }
        }
 
@@ -1323,7 +1323,7 @@ static int __devinit tps80031_i2c_probe(struct i2c_client *client,
                                        pdata->irq_base);
                if (ret) {
                        dev_err(&client->dev, "IRQ init failed: %d\n", ret);
-                       goto fail;
+                       goto fail_client_reg;
                }
        }
 
@@ -1334,7 +1334,7 @@ static int __devinit tps80031_i2c_probe(struct i2c_client *client,
        ret = tps80031_add_subdevs(tps80031, pdata);
        if (ret) {
                dev_err(&client->dev, "add devices failed: %d\n", ret);
-               goto fail;
+               goto fail_add_subdev;
        }
 
        tps80031_gpio_init(tps80031, pdata);
@@ -1352,8 +1352,18 @@ static int __devinit tps80031_i2c_probe(struct i2c_client *client,
 
        return 0;
 
-fail:
-       tps80031_i2c_remove(client);
+fail_add_subdev:
+       if (client->irq)
+               free_irq(client->irq, tps80031);
+
+fail_client_reg:
+       for (i = 0; i < TPS_NUM_SLAVES; i++) {
+               struct tps80031_client *tps = &tps80031->tps_clients[i];
+               if (tps->client && tps->client != client)
+                       i2c_unregister_device(tps->client);
+               tps80031->tps_clients[i].client = NULL;
+               mutex_destroy(&tps->lock);
+       }
        return ret;
 }