diff options
author | Naresh Solanki <naresh.solanki@9elements.com> | 2024-01-04 19:43:13 +0530 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2024-01-04 20:02:06 +0000 |
commit | 1cadc04c1a1ac5015c2eb0fadfabf4b61bbe167e (patch) | |
tree | ef26b1d4ed61031079e93c1a68c8fcb1ae3a932a /drivers/regulator/event.c | |
parent | 51088e5cc241178ccd6db2dd6d161dc8df32057d (diff) | |
download | linux-stable-1cadc04c1a1ac5015c2eb0fadfabf4b61bbe167e.tar.gz linux-stable-1cadc04c1a1ac5015c2eb0fadfabf4b61bbe167e.tar.bz2 linux-stable-1cadc04c1a1ac5015c2eb0fadfabf4b61bbe167e.zip |
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: Naresh Solanki <naresh.solanki@9elements.com>
Link: https://msgid.link/r/20240104141314.3337037-1-naresh.solanki@9elements.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/event.c')
-rw-r--r-- | drivers/regulator/event.c | 8 |
1 files 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; |