Skip to contentSkip to conversation

gpio: sim: driver improvements

PATCH Applied Bartosz Golaszewski 2 participants 9 messages Jun 10, 2024 – Jun 11, 2024 GPIO

lore
Share & tools
lore
#0 lore raw

cover gpio: sim: driver improvements

From: Bartosz Golaszewski <[email protected]>

Andy had some suggestions in his review of the gpio-virtuser that also apply to gpio-sim so let's use them.

Bartosz Golaszewski (3):
gpio: sim: use device_match_name() instead of strcmp(dev_name(...
gpio: sim: drop kernel.h include
gpio: sim: use devm_mutex_init()

 drivers/gpio/gpio-sim.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/3 gpio: sim: use device_match_name() instead of strcmp(dev_name(...

From: Bartosz Golaszewski <[email protected]>

Use the dedicated helper for comparing device names against strings. While at it: reshuffle the code a bit for less indentation.

---
 drivers/gpio/gpio-sim.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/gpio/gpio-sim.c +11 -11
index 2ed5cbe7c8a8..278bb0c54636 100644
@@ -581,19 +581,19 @@ static int gpio_sim_bus_notifier_call(struct notifier_block *nb,
 
 	snprintf(devname, sizeof(devname), "gpio-sim.%u", simdev->id);
 
-	if (strcmp(dev_name(dev), devname) == 0) {
-		if (action == BUS_NOTIFY_BOUND_DRIVER)
-			simdev->driver_bound = true;
-		else if (action == BUS_NOTIFY_DRIVER_NOT_BOUND)
-			simdev->driver_bound = false;
-		else
-			return NOTIFY_DONE;
+	if (!device_match_name(dev, devname))
+		return NOTIFY_DONE;
 
-		complete(&simdev->probe_completion);
-		return NOTIFY_OK;
-	}
+	if (action == BUS_NOTIFY_BOUND_DRIVER)
+		simdev->driver_bound = true;
+	else if (action == BUS_NOTIFY_DRIVER_NOT_BOUND)
+		simdev->driver_bound = false;
+	else
+		return NOTIFY_DONE;
 
-	return NOTIFY_DONE;
+	complete(&simdev->probe_completion);
+
+	return NOTIFY_OK;
 }
 
 static struct gpio_sim_device *to_gpio_sim_device(struct config_item *item)
Signature · 1 line
2.40.1
#2 lore raw

PATCH 2/3 gpio: sim: drop kernel.h include

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

We included kernel.h for ARRAY_SIZE() which has since been moved into its own header. Use it instead.

---
 drivers/gpio/gpio-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-sim.c +1 -1
index 278bb0c54636..21ad8d87ef04 100644
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/array_size.h>
 #include <linux/bitmap.h>
 #include <linux/cleanup.h>
 #include <linux/completion.h>
@@ -20,7 +21,6 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/irq_sim.h>
-#include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/lockdep.h>
 #include <linux/minmax.h>
Signature · 1 line
2.40.1
#3 lore raw

PATCH 3/3 gpio: sim: use devm_mutex_init()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Drop the hand-coded devres action callback for destroying the mutex in favor of devm_mutex_init().

---
 drivers/gpio/gpio-sim.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/gpio/gpio-sim.c +1 -10
index 21ad8d87ef04..4157735ea791 100644
@@ -308,13 +308,6 @@ static ssize_t gpio_sim_sysfs_pull_store(struct device *dev,
 	return len;
 }
 
-static void gpio_sim_mutex_destroy(void *data)
-{
-	struct mutex *lock = data;
-
-	mutex_destroy(lock);
-}
-
 static void gpio_sim_put_device(void *data)
 {
 	struct device *dev = data;
@@ -458,9 +451,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
 	if (ret)
 		return ret;
 
-	mutex_init(&chip->lock);
-	ret = devm_add_action_or_reset(dev, gpio_sim_mutex_destroy,
-				       &chip->lock);
+	ret = devm_mutex_init(dev, &chip->lock);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.40.1
Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] gpio: sim: use devm_mutex_init()

Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Drop the hand-coded devres action callback for destroying the mutex in favor of devm_mutex_init().

All three LGTM,

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH 3/3] gpio: sim: use devm_mutex_init()

Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Drop the hand-coded devres action callback for destroying the mutex in favor of devm_mutex_init().

All three LGTM,

Can you leave your tags under the cover letter in such cases? This will make b4 pick it up for all patches automatically.

Thanks,
Bart

Quoted 3 lines

Thanks!

#6 lore raw

Re: [PATCH 3/3] gpio: sim: use devm_mutex_init()

Mon, Jun 10, 2024 at 05:31:44PM +0200, Bartosz Golaszewski kirjoitti:

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Bartosz Golaszewski
Quoted 3 lines

From: Bartosz Golaszewski <[email protected]>

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Drop the hand-coded devres action callback for destroying the mutex in favor of devm_mutex_init().

All three LGTM,

Can you leave your tags under the cover letter in such cases? This will make b4 pick it up for all patches automatically.

For some reason I was thinking there is no cover letter. But okay, done now.

Quoted 2 lines
Quoted 2 lines

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author Applied
#8 lore raw
In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 11 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Andy had some suggestions in his review of the gpio-virtuser that also apply to gpio-sim so let's use them.

Bartosz Golaszewski (3):
gpio: sim: use device_match_name() instead of strcmp(dev_name(...
gpio: sim: drop kernel.h include
gpio: sim: use devm_mutex_init()

[...]

Applied, thanks!

[1/3] gpio: sim: use device_match_name() instead of strcmp(dev_name(...

      commit: 8a05de23adabc4d982dfdeabc184a267f7a50491
[2/3] gpio: sim: drop kernel.h include
      commit: b5f5cbee764e2faffe5241445830a5e43084f3a0
[3/3] gpio: sim: use devm_mutex_init()
      commit: 413427153921ac8263d3a516bfbdaa42fa058085

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>