Skip to content

Commit

Permalink
gpio: sim: replace memmove() + strstrip() with skip_spaces() + strim()
Browse files Browse the repository at this point in the history
Turns out we can avoid the memmove() by using skip_spaces() and strim().
We did that in gpio-consumer, let's do it in gpio-sim.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
Bartosz Golaszewski committed Aug 15, 2023
1 parent a40fe1f commit ba0294d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/gpio/gpio-sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,13 @@ static bool gpio_sim_device_is_live_unlocked(struct gpio_sim_device *dev)

static char *gpio_sim_strdup_trimmed(const char *str, size_t count)
{
char *dup, *trimmed;
char *trimmed;

dup = kstrndup(str, count, GFP_KERNEL);
if (!dup)
trimmed = kstrndup(skip_spaces(str), count, GFP_KERNEL);
if (!trimmed)
return NULL;

trimmed = strstrip(dup);
memmove(dup, trimmed, strlen(trimmed) + 1);

return dup;
return strim(trimmed);
}

static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item,
Expand Down

0 comments on commit ba0294d

Please sign in to comment.