[media] s5k6aa: Convert to devm_gpio_request_one()

Use the devm_gpio_request_one() managed function to simplify cleanup
code paths.

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>
This commit is contained in:
Laurent Pinchart 2013-05-02 08:29:43 -03:00 committed by Mauro Carvalho Chehab
parent 598d8d1e4c
commit 31857e54fa

View File

@ -1491,58 +1491,41 @@ static const struct v4l2_subdev_ops s5k6aa_subdev_ops = {
/* /*
* GPIO setup * GPIO setup
*/ */
static int s5k6aa_configure_gpio(int nr, int val, const char *name)
{
unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
int ret;
if (!gpio_is_valid(nr))
return 0;
ret = gpio_request_one(nr, flags, name);
if (!ret)
gpio_export(nr, 0);
return ret;
}
static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa)
{
int i;
for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) {
if (!gpio_is_valid(s5k6aa->gpio[i].gpio))
continue;
gpio_free(s5k6aa->gpio[i].gpio);
s5k6aa->gpio[i].gpio = -EINVAL;
}
}
static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa, static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa,
const struct s5k6aa_platform_data *pdata) const struct s5k6aa_platform_data *pdata)
{ {
const struct s5k6aa_gpio *gpio = &pdata->gpio_stby; struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
const struct s5k6aa_gpio *gpio;
unsigned long flags;
int ret; int ret;
s5k6aa->gpio[STBY].gpio = -EINVAL; s5k6aa->gpio[STBY].gpio = -EINVAL;
s5k6aa->gpio[RST].gpio = -EINVAL; s5k6aa->gpio[RST].gpio = -EINVAL;
ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY"); gpio = &pdata->gpio_stby;
if (ret) { if (gpio_is_valid(gpio->gpio)) {
s5k6aa_free_gpios(s5k6aa); flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
return ret; | GPIOF_EXPORT;
ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags,
"S5K6AA_STBY");
if (ret < 0)
return ret;
s5k6aa->gpio[STBY] = *gpio;
} }
s5k6aa->gpio[STBY] = *gpio;
if (gpio_is_valid(gpio->gpio))
gpio_set_value(gpio->gpio, 0);
gpio = &pdata->gpio_reset; gpio = &pdata->gpio_reset;
ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST"); if (gpio_is_valid(gpio->gpio)) {
if (ret) { flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
s5k6aa_free_gpios(s5k6aa); | GPIOF_EXPORT;
return ret; ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags,
"S5K6AA_RST");
if (ret < 0)
return ret;
s5k6aa->gpio[RST] = *gpio;
} }
s5k6aa->gpio[RST] = *gpio;
if (gpio_is_valid(gpio->gpio))
gpio_set_value(gpio->gpio, 0);
return 0; return 0;
} }
@ -1593,7 +1576,7 @@ static int s5k6aa_probe(struct i2c_client *client,
ret = s5k6aa_configure_gpios(s5k6aa, pdata); ret = s5k6aa_configure_gpios(s5k6aa, pdata);
if (ret) if (ret)
goto out_err2; goto out_err;
for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++) for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
s5k6aa->supplies[i].supply = s5k6aa_supply_names[i]; s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
@ -1602,12 +1585,12 @@ static int s5k6aa_probe(struct i2c_client *client,
s5k6aa->supplies); s5k6aa->supplies);
if (ret) { if (ret) {
dev_err(&client->dev, "Failed to get regulators\n"); dev_err(&client->dev, "Failed to get regulators\n");
goto out_err3; goto out_err;
} }
ret = s5k6aa_initialize_ctrls(s5k6aa); ret = s5k6aa_initialize_ctrls(s5k6aa);
if (ret) if (ret)
goto out_err3; goto out_err;
s5k6aa_presets_data_init(s5k6aa); s5k6aa_presets_data_init(s5k6aa);
@ -1618,9 +1601,7 @@ static int s5k6aa_probe(struct i2c_client *client,
return 0; return 0;
out_err3: out_err:
s5k6aa_free_gpios(s5k6aa);
out_err2:
media_entity_cleanup(&s5k6aa->sd.entity); media_entity_cleanup(&s5k6aa->sd.entity);
return ret; return ret;
} }
@ -1628,12 +1609,10 @@ out_err2:
static int s5k6aa_remove(struct i2c_client *client) static int s5k6aa_remove(struct i2c_client *client)
{ {
struct v4l2_subdev *sd = i2c_get_clientdata(client); struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct s5k6aa *s5k6aa = to_s5k6aa(sd);
v4l2_device_unregister_subdev(sd); v4l2_device_unregister_subdev(sd);
v4l2_ctrl_handler_free(sd->ctrl_handler); v4l2_ctrl_handler_free(sd->ctrl_handler);
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
s5k6aa_free_gpios(s5k6aa);
return 0; return 0;
} }