* [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device()
@ 2019-05-21 9:03 Bartosz Golaszewski
2019-05-21 9:03 ` [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data() Bartosz Golaszewski
2019-05-28 15:52 ` [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
0 siblings, 2 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2019-05-21 9:03 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
We now have a resource managed version of i2c_new_dummy_device() that
also returns an actual error code instead of a NULL-pointer. Use it
in the max732x GPIO driver and simplify code in the process.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/gpio/gpio-max732x.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index f03cb0ba7726..7fd1bdfe00e5 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -652,12 +652,12 @@ static int max732x_probe(struct i2c_client *client,
case 0x60:
chip->client_group_a = client;
if (nr_port > 8) {
- c = i2c_new_dummy(client->adapter, addr_b);
- if (!c) {
+ c = devm_i2c_new_dummy_device(&client->dev,
+ client->adapter, addr_b);
+ if (IS_ERR(c)) {
dev_err(&client->dev,
"Failed to allocate I2C device\n");
- ret = -ENODEV;
- goto out_failed;
+ return PTR_ERR(c);
}
chip->client_group_b = chip->client_dummy = c;
}
@@ -665,12 +665,12 @@ static int max732x_probe(struct i2c_client *client,
case 0x50:
chip->client_group_b = client;
if (nr_port > 8) {
- c = i2c_new_dummy(client->adapter, addr_a);
- if (!c) {
+ c = devm_i2c_new_dummy_device(&client->dev,
+ client->adapter, addr_a);
+ if (IS_ERR(c)) {
dev_err(&client->dev,
"Failed to allocate I2C device\n");
- ret = -ENODEV;
- goto out_failed;
+ return PTR_ERR(c);
}
chip->client_group_a = chip->client_dummy = c;
}
@@ -678,36 +678,34 @@ static int max732x_probe(struct i2c_client *client,
default:
dev_err(&client->dev, "invalid I2C address specified %02x\n",
client->addr);
- ret = -EINVAL;
- goto out_failed;
+ return -EINVAL;
}
if (nr_port > 8 && !chip->client_dummy) {
dev_err(&client->dev,
"Failed to allocate second group I2C device\n");
- ret = -ENODEV;
- goto out_failed;
+ return -ENODEV;
}
mutex_init(&chip->lock);
ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
if (ret)
- goto out_failed;
+ return ret;
if (nr_port > 8) {
ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]);
if (ret)
- goto out_failed;
+ return ret;
}
ret = gpiochip_add_data(&chip->gpio_chip, chip);
if (ret)
- goto out_failed;
+ return ret;
ret = max732x_irq_setup(chip, id);
if (ret) {
gpiochip_remove(&chip->gpio_chip);
- goto out_failed;
+ return ret;
}
if (pdata && pdata->setup) {
@@ -719,10 +717,6 @@ static int max732x_probe(struct i2c_client *client,
i2c_set_clientdata(client, chip);
return 0;
-
-out_failed:
- i2c_unregister_device(chip->client_dummy);
- return ret;
}
static int max732x_remove(struct i2c_client *client)
@@ -744,9 +738,6 @@ static int max732x_remove(struct i2c_client *client)
gpiochip_remove(&chip->gpio_chip);
- /* unregister any dummy i2c_client */
- i2c_unregister_device(chip->client_dummy);
-
return 0;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data()
2019-05-21 9:03 [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
@ 2019-05-21 9:03 ` Bartosz Golaszewski
2019-06-01 17:45 ` Linus Walleij
2019-05-28 15:52 ` [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2019-05-21 9:03 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
We can simplify the code a bit with a resource managed variant of
gpiochip_add_data().
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/gpio/gpio-max732x.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 7fd1bdfe00e5..42c9b6ce4227 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -698,15 +698,13 @@ static int max732x_probe(struct i2c_client *client,
return ret;
}
- ret = gpiochip_add_data(&chip->gpio_chip, chip);
+ ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip);
if (ret)
return ret;
ret = max732x_irq_setup(chip, id);
- if (ret) {
- gpiochip_remove(&chip->gpio_chip);
+ if (ret)
return ret;
- }
if (pdata && pdata->setup) {
ret = pdata->setup(client, chip->gpio_chip.base,
@@ -736,8 +734,6 @@ static int max732x_remove(struct i2c_client *client)
}
}
- gpiochip_remove(&chip->gpio_chip);
-
return 0;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device()
2019-05-21 9:03 [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
2019-05-21 9:03 ` [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data() Bartosz Golaszewski
@ 2019-05-28 15:52 ` Bartosz Golaszewski
2019-06-01 17:44 ` Linus Walleij
1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2019-05-28 15:52 UTC (permalink / raw)
To: Linus Walleij
Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List, Bartosz Golaszewski
wt., 21 maj 2019 o 11:03 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> We now have a resource managed version of i2c_new_dummy_device() that
> also returns an actual error code instead of a NULL-pointer. Use it
> in the max732x GPIO driver and simplify code in the process.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
If there are no objections I'll apply it by the end of this week.
Bart
> drivers/gpio/gpio-max732x.c | 37 ++++++++++++++-----------------------
> 1 file changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
> index f03cb0ba7726..7fd1bdfe00e5 100644
> --- a/drivers/gpio/gpio-max732x.c
> +++ b/drivers/gpio/gpio-max732x.c
> @@ -652,12 +652,12 @@ static int max732x_probe(struct i2c_client *client,
> case 0x60:
> chip->client_group_a = client;
> if (nr_port > 8) {
> - c = i2c_new_dummy(client->adapter, addr_b);
> - if (!c) {
> + c = devm_i2c_new_dummy_device(&client->dev,
> + client->adapter, addr_b);
> + if (IS_ERR(c)) {
> dev_err(&client->dev,
> "Failed to allocate I2C device\n");
> - ret = -ENODEV;
> - goto out_failed;
> + return PTR_ERR(c);
> }
> chip->client_group_b = chip->client_dummy = c;
> }
> @@ -665,12 +665,12 @@ static int max732x_probe(struct i2c_client *client,
> case 0x50:
> chip->client_group_b = client;
> if (nr_port > 8) {
> - c = i2c_new_dummy(client->adapter, addr_a);
> - if (!c) {
> + c = devm_i2c_new_dummy_device(&client->dev,
> + client->adapter, addr_a);
> + if (IS_ERR(c)) {
> dev_err(&client->dev,
> "Failed to allocate I2C device\n");
> - ret = -ENODEV;
> - goto out_failed;
> + return PTR_ERR(c);
> }
> chip->client_group_a = chip->client_dummy = c;
> }
> @@ -678,36 +678,34 @@ static int max732x_probe(struct i2c_client *client,
> default:
> dev_err(&client->dev, "invalid I2C address specified %02x\n",
> client->addr);
> - ret = -EINVAL;
> - goto out_failed;
> + return -EINVAL;
> }
>
> if (nr_port > 8 && !chip->client_dummy) {
> dev_err(&client->dev,
> "Failed to allocate second group I2C device\n");
> - ret = -ENODEV;
> - goto out_failed;
> + return -ENODEV;
> }
>
> mutex_init(&chip->lock);
>
> ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
> if (ret)
> - goto out_failed;
> + return ret;
> if (nr_port > 8) {
> ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]);
> if (ret)
> - goto out_failed;
> + return ret;
> }
>
> ret = gpiochip_add_data(&chip->gpio_chip, chip);
> if (ret)
> - goto out_failed;
> + return ret;
>
> ret = max732x_irq_setup(chip, id);
> if (ret) {
> gpiochip_remove(&chip->gpio_chip);
> - goto out_failed;
> + return ret;
> }
>
> if (pdata && pdata->setup) {
> @@ -719,10 +717,6 @@ static int max732x_probe(struct i2c_client *client,
>
> i2c_set_clientdata(client, chip);
> return 0;
> -
> -out_failed:
> - i2c_unregister_device(chip->client_dummy);
> - return ret;
> }
>
> static int max732x_remove(struct i2c_client *client)
> @@ -744,9 +738,6 @@ static int max732x_remove(struct i2c_client *client)
>
> gpiochip_remove(&chip->gpio_chip);
>
> - /* unregister any dummy i2c_client */
> - i2c_unregister_device(chip->client_dummy);
> -
> return 0;
> }
>
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device()
2019-05-28 15:52 ` [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
@ 2019-06-01 17:44 ` Linus Walleij
0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2019-06-01 17:44 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List, Bartosz Golaszewski
On Tue, May 28, 2019 at 5:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> wt., 21 maj 2019 o 11:03 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
> >
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > We now have a resource managed version of i2c_new_dummy_device() that
> > also returns an actual error code instead of a NULL-pointer. Use it
> > in the max732x GPIO driver and simplify code in the process.
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > ---
>
> If there are no objections I'll apply it by the end of this week.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Just include it in some pull request to me!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data()
2019-05-21 9:03 ` [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data() Bartosz Golaszewski
@ 2019-06-01 17:45 ` Linus Walleij
0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2019-06-01 17:45 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski
On Tue, May 21, 2019 at 11:03 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> We can simplify the code a bit with a resource managed variant of
> gpiochip_add_data().
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-01 17:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 9:03 [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
2019-05-21 9:03 ` [PATCH 2/2] gpio: max732x: use devm_gpiochip_add_data() Bartosz Golaszewski
2019-06-01 17:45 ` Linus Walleij
2019-05-28 15:52 ` [PATCH 1/2] gpio: max732x: use i2c_new_dummy_device() Bartosz Golaszewski
2019-06-01 17:44 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).