From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [PATCH v1 2/3] gpiolib: sysfs: Move kstrtox() calls outside of the mutex lock
Date: Wed, 9 Feb 2022 13:31:16 +0200 [thread overview]
Message-ID: <20220209113117.25760-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20220209113117.25760-1-andriy.shevchenko@linux.intel.com>
In a few places we perform kstrtox() operations under mutex that
do not require any locking. Move them outside of the mutex locks.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-sysfs.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 57d8ecab53b7..e7828d4dc7a8 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -121,24 +121,18 @@ static ssize_t value_store(struct device *dev,
{
struct gpiod_data *data = dev_get_drvdata(dev);
struct gpio_desc *desc = data->desc;
- ssize_t status = 0;
+ ssize_t status;
+ long value;
+
+ status = kstrtol(buf, 0, &value);
mutex_lock(&data->mutex);
if (!test_bit(FLAG_IS_OUT, &desc->flags)) {
status = -EPERM;
- } else {
- long value;
-
- if (size <= 2 && isdigit(buf[0]) &&
- (size == 1 || buf[1] == '\n'))
- value = buf[0] - '0';
- else
- status = kstrtol(buf, 0, &value);
- if (status == 0) {
- gpiod_set_value_cansleep(desc, value);
- status = size;
- }
+ } else if (status == 0) {
+ gpiod_set_value_cansleep(desc, value);
+ status = size;
}
mutex_unlock(&data->mutex);
@@ -342,11 +336,13 @@ static ssize_t active_low_store(struct device *dev,
ssize_t status;
long value;
+ status = kstrtol(buf, 0, &value);
+ if (status)
+ return status;
+
mutex_lock(&data->mutex);
- status = kstrtol(buf, 0, &value);
- if (status == 0)
- status = gpio_sysfs_set_active_low(dev, value);
+ status = gpio_sysfs_set_active_low(dev, value);
mutex_unlock(&data->mutex);
--
2.34.1
next prev parent reply other threads:[~2022-02-09 12:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 11:31 [PATCH v1 1/3] gpiolib: sysfs: Move sysfs_emit() calls outside of the mutex lock Andy Shevchenko
2022-02-09 11:31 ` Andy Shevchenko [this message]
2022-02-09 11:31 ` [PATCH v1 3/3] gpiolib: sysfs: Simplify edge handling in the code Andy Shevchenko
2022-02-16 15:03 ` [PATCH v1 1/3] gpiolib: sysfs: Move sysfs_emit() calls outside of the mutex lock Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209113117.25760-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).