Skip to content

Commit 1cadc04

Browse files
nsolanki22broonie
authored andcommitted
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>
1 parent 51088e5 commit 1cadc04

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/regulator/event.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
#include <regulator/regulator.h>
99
#include <net/netlink.h>
1010
#include <net/genetlink.h>
11+
#include <linux/atomic.h>
1112

1213
#include "regnl.h"
1314

14-
static unsigned int reg_event_seqnum;
15+
static atomic_t reg_event_seqnum = ATOMIC_INIT(0);
1516

1617
static const struct genl_multicast_group reg_event_mcgrps[] = {
1718
{ .name = REG_GENL_MCAST_GROUP_NAME, },
@@ -43,9 +44,8 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)
4344
return -ENOMEM;
4445

4546
/* add the genetlink message header */
46-
msg_header = genlmsg_put(skb, 0, reg_event_seqnum++,
47-
&reg_event_genl_family, 0,
48-
REG_GENL_CMD_EVENT);
47+
msg_header = genlmsg_put(skb, 0, atomic_inc_return(&reg_event_seqnum),
48+
&reg_event_genl_family, 0, REG_GENL_CMD_EVENT);
4949
if (!msg_header) {
5050
nlmsg_free(skb);
5151
return -ENOMEM;

0 commit comments

Comments
 (0)