mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Naresh Solanki <naresh.solanki@9elements.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: zev@bewilderbeest.net,
	Naresh Solanki <Naresh.Solanki@9elements.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] regulator: userspace-consumer: Use atomic operation
Date: Wed, 23 Aug 2023 16:15:57 +0200	[thread overview]
Message-ID: <20230823141558.957526-1-Naresh.Solanki@9elements.com> (raw)

Replace mutexes with atomic operations.

Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
 drivers/regulator/userspace-consumer.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index a0b980022993..a86714bd32fd 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -32,7 +32,7 @@ struct userspace_consumer_data {
 
 	struct kobject *kobj;
 	struct notifier_block nb;
-	unsigned long events;
+	atomic_long_t events;
 };
 
 static ssize_t name_show(struct device *dev,
@@ -99,12 +99,7 @@ static ssize_t events_show(struct device *dev,
 			   struct device_attribute *attr, char *buf)
 {
 	struct userspace_consumer_data *data = dev_get_drvdata(dev);
-	unsigned long e;
-
-	mutex_lock(&events_lock);
-	e = data->events;
-	data->events = 0;
-	mutex_unlock(&events_lock);
+	unsigned long e = atomic_long_xchg(&data->events, 0);
 
 	return sprintf(buf, "0x%lx\n", e);
 }
@@ -144,9 +139,7 @@ static int regulator_userspace_notify(struct notifier_block *nb,
 	struct userspace_consumer_data *data =
 		container_of(nb, struct userspace_consumer_data, nb);
 
-	mutex_lock(&events_lock);
-	data->events |= event;
-	mutex_unlock(&events_lock);
+	atomic_long_or(event, &data->events);
 
 	sysfs_notify(data->kobj, NULL, dev_attr_events.attr.name);
 

base-commit: 8950c4a350c188deb5f5b05df3244d4db82fe3d8
-- 
2.41.0


             reply	other threads:[~2023-08-23 14:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 14:15 Naresh Solanki [this message]
2023-08-23 15:11 ` Mark Brown
2023-08-24 11:04   ` Naresh Solanki
2023-08-24 16:55     ` Mark Brown
2023-08-24 19:32       ` Zev Weiss
2023-08-24 20:03         ` Mark Brown

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=20230823141558.957526-1-Naresh.Solanki@9elements.com \
    --to=naresh.solanki@9elements.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zev@bewilderbeest.net \
    /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

all inboxes | Powered by JetHome®