]> Git Repo - linux.git/commitdiff
regulator: event: Ensure atomicity for sequence number
authorNaresh Solanki <[email protected]>
Thu, 4 Jan 2024 14:13:13 +0000 (19:43 +0530)
committerMark Brown <[email protected]>
Thu, 4 Jan 2024 20:02:06 +0000 (20:02 +0000)
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 <[email protected]>
Link: https://msgid.link/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
drivers/regulator/event.c

index 0ec58f306b3866bdf68648aeb7ce9613ce6bf1a7..ea3bd49544e88a532b5bcee0393f53c82431ff23 100644 (file)
@@ -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++,
-                                &reg_event_genl_family, 0,
-                                REG_GENL_CMD_EVENT);
+       msg_header = genlmsg_put(skb, 0, atomic_inc_return(&reg_event_seqnum),
+                                &reg_event_genl_family, 0, REG_GENL_CMD_EVENT);
        if (!msg_header) {
                nlmsg_free(skb);
                return -ENOMEM;
This page took 0.056595 seconds and 4 git commands to generate.