[1/2] gpio: sim: use sysfs_streq() and avoid an strdup()

Message ID 20230809131442.25524-1-brgl@bgdev.pl
State New
Headers
Series [1/2] gpio: sim: use sysfs_streq() and avoid an strdup() |

Commit Message

Bartosz Golaszewski Aug. 9, 2023, 1:14 p.m. UTC
  From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

When comparing strings passed to us from configfs, we can pass the page
argument directly to sysfs_streq() and avoid manual string trimming.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-sim.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
  

Comments

Andy Shevchenko Aug. 10, 2023, 2:04 p.m. UTC | #1
On Wed, Aug 09, 2023 at 03:14:41PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> When comparing strings passed to us from configfs, we can pass the page
> argument directly to sysfs_streq() and avoid manual string trimming.

Good one!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  
Bartosz Golaszewski Aug. 11, 2023, 11:59 a.m. UTC | #2
On Wed, Aug 9, 2023 at 3:14 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> When comparing strings passed to us from configfs, we can pass the page
> argument directly to sysfs_streq() and avoid manual string trimming.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---

I applied this one, I'll send a v2 for other one.

Bart
  

Patch

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 8b49b0abacd5..dc4097dc0fbc 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -1272,7 +1272,6 @@  gpio_sim_hog_config_direction_store(struct config_item *item,
 {
 	struct gpio_sim_hog *hog = to_gpio_sim_hog(item);
 	struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog);
-	char *trimmed;
 	int dir;
 
 	mutex_lock(&dev->lock);
@@ -1282,23 +1281,15 @@  gpio_sim_hog_config_direction_store(struct config_item *item,
 		return -EBUSY;
 	}
 
-	trimmed = gpio_sim_strdup_trimmed(page, count);
-	if (!trimmed) {
-		mutex_unlock(&dev->lock);
-		return -ENOMEM;
-	}
-
-	if (strcmp(trimmed, "input") == 0)
+	if (sysfs_streq(page, "input"))
 		dir = GPIOD_IN;
-	else if (strcmp(trimmed, "output-high") == 0)
+	else if (sysfs_streq(page, "output-high"))
 		dir = GPIOD_OUT_HIGH;
-	else if (strcmp(trimmed, "output-low") == 0)
+	else if (sysfs_streq(page, "output-low"))
 		dir = GPIOD_OUT_LOW;
 	else
 		dir = -EINVAL;
 
-	kfree(trimmed);
-
 	if (dir < 0) {
 		mutex_unlock(&dev->lock);
 		return dir;