iio: light: gp2ap002: Make use of the helper function dev_err_probe()
authorCai Huoqing <caihuoqing@baidu.com>
Fri, 8 Oct 2021 09:26:54 +0000 (17:26 +0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 20 Oct 2021 13:43:53 +0000 (14:43 +0100)
When possible use dev_err_probe help to properly deal with the
PROBE_DEFER error, the benefit is that DEFER issue will be logged
in the devices_deferred debugfs file.
Using dev_err_probe() can reduce code size, and the error value
gets printed.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
Link: https://lore.kernel.org/r/20211008092656.421-3-caihuoqing@baidu.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/gp2ap002.c

index f960be7d40016c72de11ff0e71a0b5e04f0ecfc9..c6d1d88d3775e7287e67591eeae0af45ab2ea1f3 100644 (file)
@@ -503,12 +503,9 @@ static int gp2ap002_probe(struct i2c_client *client,
        if (!gp2ap002->is_gp2ap002s00f) {
                gp2ap002->alsout = devm_iio_channel_get(dev, "alsout");
                if (IS_ERR(gp2ap002->alsout)) {
-                       if (PTR_ERR(gp2ap002->alsout) == -ENODEV) {
-                               dev_err(dev, "no ADC, deferring...\n");
-                               return -EPROBE_DEFER;
-                       }
-                       dev_err(dev, "failed to get ALSOUT ADC channel\n");
-                       return PTR_ERR(gp2ap002->alsout);
+                       ret = PTR_ERR(gp2ap002->alsout);
+                       ret = (ret == -ENODEV) ? -EPROBE_DEFER : ret;
+                       return dev_err_probe(dev, ret, "failed to get ALSOUT ADC channel\n");
                }
                ret = iio_get_channel_type(gp2ap002->alsout, &ch_type);
                if (ret < 0)
@@ -521,15 +518,14 @@ static int gp2ap002_probe(struct i2c_client *client,
        }
 
        gp2ap002->vdd = devm_regulator_get(dev, "vdd");
-       if (IS_ERR(gp2ap002->vdd)) {
-               dev_err(dev, "failed to get VDD regulator\n");
-               return PTR_ERR(gp2ap002->vdd);
-       }
+       if (IS_ERR(gp2ap002->vdd))
+               return dev_err_probe(dev, PTR_ERR(gp2ap002->vdd),
+                                    "failed to get VDD regulator\n");
+
        gp2ap002->vio = devm_regulator_get(dev, "vio");
-       if (IS_ERR(gp2ap002->vio)) {
-               dev_err(dev, "failed to get VIO regulator\n");
-               return PTR_ERR(gp2ap002->vio);
-       }
+       if (IS_ERR(gp2ap002->vio))
+               return dev_err_probe(dev, PTR_ERR(gp2ap002->vio),
+                                    "failed to get VIO regulator\n");
 
        /* Operating voltage 2.4V .. 3.6V according to datasheet */
        ret = regulator_set_voltage(gp2ap002->vdd, 2400000, 3600000);