staging: iio: ad799x: remove some unneeded IS_ERR() checks
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 30 Apr 2014 21:05:00 +0000 (22:05 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 May 2014 10:14:01 +0000 (11:14 +0100)
My static checker is upset that we check IS_ERR(t->reg) when we know it
is not an ERR_PTR.

Checking for IS_ERR() twice is often a sign of confusion and buggy code.
In this case, if the call to "ret = regulator_enable(st->vref);" fails,
then we call "regulator_disable(st->vref);" and that's a mistake because
"st->vref" is not enabled.

I fixed these problems and Hartmut Knaack pointed out a couple unneeded
IS_ERR() checks in ad799x_remove() so I have removed those as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/adc/ad799x.c

index 16a8b14b1921746b9449ee0645d231e346655819..39b4cb48d738c8f42a6d96beda5152869522d454 100644 (file)
@@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
        ret = iio_triggered_buffer_setup(indio_dev, NULL,
                &ad799x_trigger_handler, NULL);
        if (ret)
-               goto error_disable_reg;
+               goto error_disable_vref;
 
        if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev,
@@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
 
 error_cleanup_ring:
        iio_triggered_buffer_cleanup(indio_dev);
+error_disable_vref:
+       regulator_disable(st->vref);
 error_disable_reg:
-       if (!IS_ERR(st->vref))
-               regulator_disable(st->vref);
-       if (!IS_ERR(st->reg))
-               regulator_disable(st->reg);
+       regulator_disable(st->reg);
 
        return ret;
 }
@@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client)
        iio_device_unregister(indio_dev);
 
        iio_triggered_buffer_cleanup(indio_dev);
-       if (!IS_ERR(st->vref))
-               regulator_disable(st->vref);
-       if (!IS_ERR(st->reg))
-               regulator_disable(st->reg);
+       regulator_disable(st->vref);
+       regulator_disable(st->reg);
        kfree(st->rx_buf);
 
        return 0;