From: Naresh Solanki <naresh.solanki@9elements.com>
To: broonie@kernel.org, Liam Girdwood <lgirdwood@gmail.com>
Cc: mazziesaccount@gmail.com,
Naresh Solanki <naresh.solanki@9elements.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] regulator: event: Ensure atomicity for sequence number
Date: Thu, 4 Jan 2024 19:43:13 +0530 [thread overview]
Message-ID: <20240104141314.3337037-1-naresh.solanki@9elements.com> (raw)
Previously, the sequence number in the regulator event subsystem was
updated without atomic operations, potentially leading to race
conditions. This commit addresses the issue by making the sequence
number atomic.
Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com>
---
drivers/regulator/event.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/event.c b/drivers/regulator/event.c
index 0ec58f306b38..ea3bd49544e8 100644
--- a/drivers/regulator/event.c
+++ b/drivers/regulator/event.c
@@ -8,10 +8,11 @@
#include <regulator/regulator.h>
#include <net/netlink.h>
#include <net/genetlink.h>
+#include <linux/atomic.h>
#include "regnl.h"
-static unsigned int reg_event_seqnum;
+static atomic_t reg_event_seqnum = ATOMIC_INIT(0);
static const struct genl_multicast_group reg_event_mcgrps[] = {
{ .name = REG_GENL_MCAST_GROUP_NAME, },
@@ -43,9 +44,8 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)
return -ENOMEM;
/* add the genetlink message header */
- msg_header = genlmsg_put(skb, 0, reg_event_seqnum++,
- ®_event_genl_family, 0,
- REG_GENL_CMD_EVENT);
+ msg_header = genlmsg_put(skb, 0, atomic_inc_return(®_event_seqnum),
+ ®_event_genl_family, 0, REG_GENL_CMD_EVENT);
if (!msg_header) {
nlmsg_free(skb);
return -ENOMEM;
base-commit: 67ba055dd7758c34f6e64c9d35132362c1e1f0b5
--
2.41.0
next reply other threads:[~2024-01-04 14:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 14:13 Naresh Solanki [this message]
2024-01-05 7:07 ` Matti Vaittinen
2024-01-05 13:04 ` 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=20240104141314.3337037-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=mazziesaccount@gmail.com \
/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®