gpio: pca9570: Ad-hoc cleanups
v2 cover gpio: pca9570: Ad-hoc cleanups
Looking at this driver for something else I took the opportunity to clean it up. Hence this mini-series.
Changelog v2:
- rephrased commit message in patch 1 (Bart)
- collected tags (Linus)
Andy Shevchenko (3):
gpio: pca9570: Use devm_mutex_init() for mutex initialization
gpio: pca9570: Don't use "proxy" headers
gpio: pca9570: use lock guards
drivers/gpio/gpio-pca9570.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
Signature · 1 line
2.50.1
PATCH v2 1/3 gpio: pca9570: Use devm_mutex_init() for mutex initialization
Use devm_mutex_init() since it brings some benefits when CONFIG_DEBUG_MUTEXES is enabled.
--- drivers/gpio/gpio-pca9570.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpio/gpio-pca9570.c +5 -1
@@ -115,7 +115,9 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)static int pca9570_probe (struct i2c_client *client) { +struct device *dev = &client->dev;struct pca9570 *gpio; +int ret; gpio =devm_kzalloc (&client->dev,sizeof (*gpio),GFP_KERNEL );if (!gpio)
@@ -132,7 +134,9 @@ static int pca9570_probe(struct i2c_client *client) gpio->chip.ngpio = gpio->chip_data->ngpio; gpio->chip.can_sleep = true; -mutex_init (&gpio->lock); + ret =devm_mutex_init (dev, &gpio->lock); +if (ret) +return ret;/* Read the current output level */ pca9570_read (gpio, &gpio->out);
Signature · 1 line
2.50.1
PATCH v2 2/3 gpio: pca9570: Don't use "proxy" headers
In reply to Andy ShevchenkoUpdate header inclusions to follow IWYU (Include What You Use) principle.
Note that kernel.h is discouraged to be included as it's written at the top of that file.
--- drivers/gpio/gpio-pca9570.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpio/gpio-pca9570.c +4 -0
@@ -9,11 +9,15 @@* Andrew F. Davis <[email protected]> */ +#include <linux/bits.h> +#include <linux/device/devres.h> +#include <linux/errno.h> #include <linux/gpio/driver.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/property.h> +#include <linux/types.h> #define SLG7XL45106_GPO_REG 0xDB
Signature · 1 line
2.50.1
PATCH v2 3/3 gpio: pca9570: use lock guards
In reply to Andy ShevchenkoShrink the code by a couple lines and improve lock management by using lock guards from cleanup.h.
--- drivers/gpio/gpio-pca9570.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pca9570.c +4 -5
@@ -10,6 +10,7 @@*/ #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/device/devres.h> #include <linux/errno.h> #include <linux/gpio/driver.h>
@@ -98,7 +99,7 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)u8 buffer;int ret; -mutex_lock (&gpio->lock); +guard (mutex)(&gpio->lock); buffer = gpio->out;if (value)
@@ -108,13 +109,11 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value) ret =pca9570_write (gpio, buffer);if (ret) - goto out; +return ret; gpio->out = buffer; -out: -mutex_unlock (&gpio->lock); -return ret; +return 0 ; }static int pca9570_probe (struct i2c_client *client)
Signature · 1 line
2.50.1
Bartosz Golaszewski
AppliedQuoted 8 lines · Andy Shevchenko
Looking at this driver for something else I took the opportunity to clean it up. Hence this mini-series.
Changelog v2:
- rephrased commit message in patch 1 (Bart)
- collected tags (Linus)[...]
Applied, thanks!
[1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
commit: e05ef046ebb1ca879d885593130fa822ff664ca1
[2/3] gpio: pca9570: Don't use "proxy" headers
commit: 053578d329e58cca98f084439e14cc2895c82b9c
[3/3] gpio: pca9570: use lock guards
commit: 4aa573002ba6884d392dbfce24c3ce057f2dbb6aBest regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>