Commit 1cadc04c authored by Naresh Solanki's avatar Naresh Solanki Committed by Mark Brown

regulator: event: Ensure atomicity for sequence number

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: default avatarNaresh Solanki <naresh.solanki@9elements.com>
Link: https://msgid.link/r/20240104141314.3337037-1-naresh.solanki@9elements.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 51088e5c
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
#include <regulator/regulator.h> #include <regulator/regulator.h>
#include <net/netlink.h> #include <net/netlink.h>
#include <net/genetlink.h> #include <net/genetlink.h>
#include <linux/atomic.h>
#include "regnl.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[] = { static const struct genl_multicast_group reg_event_mcgrps[] = {
{ .name = REG_GENL_MCAST_GROUP_NAME, }, { .name = REG_GENL_MCAST_GROUP_NAME, },
...@@ -43,9 +44,8 @@ int reg_generate_netlink_event(const char *reg_name, u64 event) ...@@ -43,9 +44,8 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)
return -ENOMEM; return -ENOMEM;
/* add the genetlink message header */ /* add the genetlink message header */
msg_header = genlmsg_put(skb, 0, reg_event_seqnum++, msg_header = genlmsg_put(skb, 0, atomic_inc_return(&reg_event_seqnum),
&reg_event_genl_family, 0, &reg_event_genl_family, 0, REG_GENL_CMD_EVENT);
REG_GENL_CMD_EVENT);
if (!msg_header) { if (!msg_header) {
nlmsg_free(skb); nlmsg_free(skb);
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment