[media] media: i2c: Convert to devm_gpio_request_one()
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Thu, 2 May 2013 11:29:43 +0000 (08:29 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 21 May 2013 10:53:18 +0000 (07:53 -0300)
Using the managed function the gpio_free() calls can be removed from the
probe error path and the remove handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/i2c/adv7183.c
drivers/media/i2c/m5mols/m5mols_core.c
drivers/media/i2c/noon010pc30.c
drivers/media/i2c/smiapp/smiapp-core.c
drivers/media/i2c/vs6624.c

index 56904174abc3038bdfffd4e8bef6e96cb2e297b4..42b2dec4ca3ae8b836c371f5bd9a195e51b14392 100644 (file)
@@ -580,17 +580,17 @@ static int adv7183_probe(struct i2c_client *client,
        decoder->reset_pin = pin_array[0];
        decoder->oe_pin = pin_array[1];
 
-       if (gpio_request_one(decoder->reset_pin, GPIOF_OUT_INIT_LOW,
-                            "ADV7183 Reset")) {
+       if (devm_gpio_request_one(&client->dev, decoder->reset_pin,
+                                 GPIOF_OUT_INIT_LOW, "ADV7183 Reset")) {
                v4l_err(client, "failed to request GPIO %d\n", decoder->reset_pin);
                return -EBUSY;
        }
 
-       if (gpio_request_one(decoder->oe_pin, GPIOF_OUT_INIT_HIGH,
-                            "ADV7183 Output Enable")) {
+       if (devm_gpio_request_one(&client->dev, decoder->oe_pin,
+                                 GPIOF_OUT_INIT_HIGH,
+                                 "ADV7183 Output Enable")) {
                v4l_err(client, "failed to request GPIO %d\n", decoder->oe_pin);
-               ret = -EBUSY;
-               goto err_free_reset;
+               return -EBUSY;
        }
 
        sd = &decoder->sd;
@@ -612,7 +612,7 @@ static int adv7183_probe(struct i2c_client *client,
                ret = hdl->error;
 
                v4l2_ctrl_handler_free(hdl);
-               goto err_free_oe;
+               return ret;
        }
 
        /* v4l2 doesn't support an autodetect standard, pick PAL as default */
@@ -637,26 +637,18 @@ static int adv7183_probe(struct i2c_client *client,
        ret = v4l2_ctrl_handler_setup(hdl);
        if (ret) {
                v4l2_ctrl_handler_free(hdl);
-               goto err_free_oe;
+               return ret;
        }
 
        return 0;
-err_free_oe:
-       gpio_free(decoder->oe_pin);
-err_free_reset:
-       gpio_free(decoder->reset_pin);
-       return ret;
 }
 
 static int adv7183_remove(struct i2c_client *client)
 {
        struct v4l2_subdev *sd = i2c_get_clientdata(client);
-       struct adv7183 *decoder = to_adv7183(sd);
 
        v4l2_device_unregister_subdev(sd);
        v4l2_ctrl_handler_free(sd->ctrl_handler);
-       gpio_free(decoder->oe_pin);
-       gpio_free(decoder->reset_pin);
        return 0;
 }
 
index 08ff082242c37c1722b68e66da5218ab328f0b81..f870d5057e3d87dc28865180082a8e29eca86293 100644 (file)
@@ -959,7 +959,8 @@ static int m5mols_probe(struct i2c_client *client,
 
        gpio_flags = pdata->reset_polarity
                   ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
-       ret = gpio_request_one(pdata->gpio_reset, gpio_flags, "M5MOLS_NRST");
+       ret = devm_gpio_request_one(&client->dev, pdata->gpio_reset, gpio_flags,
+                                   "M5MOLS_NRST");
        if (ret) {
                dev_err(&client->dev, "Failed to request gpio: %d\n", ret);
                return ret;
@@ -968,7 +969,7 @@ static int m5mols_probe(struct i2c_client *client,
        ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(supplies), supplies);
        if (ret) {
                dev_err(&client->dev, "Failed to get regulators: %d\n", ret);
-               goto out_gpio;
+               return ret;
        }
 
        sd = &info->sd;
@@ -1013,22 +1014,18 @@ out_me:
        media_entity_cleanup(&sd->entity);
 out_reg:
        regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
-out_gpio:
-       gpio_free(pdata->gpio_reset);
        return ret;
 }
 
 static int m5mols_remove(struct i2c_client *client)
 {
        struct v4l2_subdev *sd = i2c_get_clientdata(client);
-       struct m5mols_info *info = to_m5mols(sd);
 
        v4l2_device_unregister_subdev(sd);
        v4l2_ctrl_handler_free(sd->ctrl_handler);
        free_irq(client->irq, sd);
 
        regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
-       gpio_free(info->pdata->gpio_reset);
        media_entity_cleanup(&sd->entity);
 
        return 0;
index d205522e598e39c15b237bdac1e5895c502073ee..6f81b99ddd1ca04a7995bf6d50a2644a98cd088e 100644 (file)
@@ -746,8 +746,9 @@ static int noon010_probe(struct i2c_client *client,
        info->curr_win          = &noon010_sizes[0];
 
        if (gpio_is_valid(pdata->gpio_nreset)) {
-               ret = gpio_request_one(pdata->gpio_nreset, GPIOF_OUT_INIT_LOW,
-                                      "NOON010PC30 NRST");
+               ret = devm_gpio_request_one(&client->dev, pdata->gpio_nreset,
+                                           GPIOF_OUT_INIT_LOW,
+                                           "NOON010PC30 NRST");
                if (ret) {
                        dev_err(&client->dev, "GPIO request error: %d\n", ret);
                        goto np_err;
@@ -757,11 +758,12 @@ static int noon010_probe(struct i2c_client *client,
        }
 
        if (gpio_is_valid(pdata->gpio_nstby)) {
-               ret = gpio_request_one(pdata->gpio_nstby, GPIOF_OUT_INIT_LOW,
-                                     "NOON010PC30 NSTBY");
+               ret = devm_gpio_request_one(&client->dev, pdata->gpio_nstby,
+                                           GPIOF_OUT_INIT_LOW,
+                                           "NOON010PC30 NSTBY");
                if (ret) {
                        dev_err(&client->dev, "GPIO request error: %d\n", ret);
-                       goto np_gpio_err;
+                       goto np_err;
                }
                info->gpio_nstby = pdata->gpio_nstby;
                gpio_export(info->gpio_nstby, 0);
@@ -773,7 +775,7 @@ static int noon010_probe(struct i2c_client *client,
        ret = regulator_bulk_get(&client->dev, NOON010_NUM_SUPPLIES,
                                 info->supply);
        if (ret)
-               goto np_reg_err;
+               goto np_err;
 
        info->pad.flags = MEDIA_PAD_FL_SOURCE;
        sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
@@ -787,12 +789,6 @@ static int noon010_probe(struct i2c_client *client,
 
 np_me_err:
        regulator_bulk_free(NOON010_NUM_SUPPLIES, info->supply);
-np_reg_err:
-       if (gpio_is_valid(info->gpio_nstby))
-               gpio_free(info->gpio_nstby);
-np_gpio_err:
-       if (gpio_is_valid(info->gpio_nreset))
-               gpio_free(info->gpio_nreset);
 np_err:
        v4l2_ctrl_handler_free(&info->hdl);
        v4l2_device_unregister_subdev(sd);
@@ -808,13 +804,6 @@ static int noon010_remove(struct i2c_client *client)
        v4l2_ctrl_handler_free(&info->hdl);
 
        regulator_bulk_free(NOON010_NUM_SUPPLIES, info->supply);
-
-       if (gpio_is_valid(info->gpio_nreset))
-               gpio_free(info->gpio_nreset);
-
-       if (gpio_is_valid(info->gpio_nstby))
-               gpio_free(info->gpio_nstby);
-
        media_entity_cleanup(&sd->entity);
 
        return 0;
index cae4f46838517472f4f705267ed9b3e93a1999c1..c385454190457f2f5bd698e02241416370057676 100644 (file)
@@ -2383,8 +2383,9 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
        }
 
        if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
-               if (gpio_request_one(sensor->platform_data->xshutdown, 0,
-                                    "SMIA++ xshutdown") != 0) {
+               if (devm_gpio_request_one(&client->dev,
+                                         sensor->platform_data->xshutdown, 0,
+                                         "SMIA++ xshutdown") != 0) {
                        dev_err(&client->dev,
                                "unable to acquire reset gpio %d\n",
                                sensor->platform_data->xshutdown);
@@ -2393,10 +2394,8 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
        }
 
        rval = smiapp_power_on(sensor);
-       if (rval) {
-               rval = -ENODEV;
-               goto out_smiapp_power_on;
-       }
+       if (rval)
+               return -ENODEV;
 
        rval = smiapp_identify_module(subdev);
        if (rval) {
@@ -2656,11 +2655,6 @@ out_ident_release:
 
 out_power_off:
        smiapp_power_off(sensor);
-
-out_smiapp_power_on:
-       if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
-               gpio_free(sensor->platform_data->xshutdown);
-
        return rval;
 }
 
@@ -2858,8 +2852,6 @@ static int smiapp_remove(struct i2c_client *client)
                v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
        }
        smiapp_free_controls(sensor);
-       if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
-               gpio_free(sensor->platform_data->xshutdown);
 
        return 0;
 }
index 94e284908f394a65d04465f5cf50987e4af4973a..7b55b3ddd80f60dd78fc8344386822201ce43c26 100644 (file)
@@ -805,7 +805,8 @@ static int vs6624_probe(struct i2c_client *client,
        if (ce == NULL)
                return -EINVAL;
 
-       ret = gpio_request_one(*ce, GPIOF_OUT_INIT_HIGH, "VS6624 Chip Enable");
+       ret = devm_gpio_request_one(&client->dev, *ce, GPIOF_OUT_INIT_HIGH,
+                                   "VS6624 Chip Enable");
        if (ret) {
                v4l_err(client, "failed to request GPIO %d\n", *ce);
                return ret;
@@ -863,27 +864,22 @@ static int vs6624_probe(struct i2c_client *client,
                int err = hdl->error;
 
                v4l2_ctrl_handler_free(hdl);
-               gpio_free(*ce);
                return err;
        }
 
        /* initialize the hardware to the default control values */
        ret = v4l2_ctrl_handler_setup(hdl);
-       if (ret) {
+       if (ret)
                v4l2_ctrl_handler_free(hdl);
-               gpio_free(*ce);
-       }
        return ret;
 }
 
 static int vs6624_remove(struct i2c_client *client)
 {
        struct v4l2_subdev *sd = i2c_get_clientdata(client);
-       struct vs6624 *sensor = to_vs6624(sd);
 
        v4l2_device_unregister_subdev(sd);
        v4l2_ctrl_handler_free(sd->ctrl_handler);
-       gpio_free(sensor->ce_pin);
        return 0;
 }