Skip to content

Commit b19d955

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Use pre_doit / post_doit hooks
Each operation from user space should be protected by the global drop monitor mutex. Use the pre_doit / post_doit hooks to take / release the lock instead of doing it explicitly in each function. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9651009 commit b19d955

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

net/core/drop_monitor.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,9 @@ static int set_all_monitor_traces(int state, struct netlink_ext_ack *extack)
247247
struct dm_hw_stat_delta *new_stat = NULL;
248248
struct dm_hw_stat_delta *temp;
249249

250-
mutex_lock(&net_dm_mutex);
251-
252250
if (state == trace_state) {
253251
NL_SET_ERR_MSG_MOD(extack, "Trace state already set to requested state");
254-
rc = -EAGAIN;
255-
goto out_unlock;
252+
return -EAGAIN;
256253
}
257254

258255
switch (state) {
@@ -296,9 +293,6 @@ static int set_all_monitor_traces(int state, struct netlink_ext_ack *extack)
296293
else
297294
rc = -EINPROGRESS;
298295

299-
out_unlock:
300-
mutex_unlock(&net_dm_mutex);
301-
302296
return rc;
303297
}
304298

@@ -380,10 +374,26 @@ static const struct genl_ops dropmon_ops[] = {
380374
},
381375
};
382376

377+
static int net_dm_nl_pre_doit(const struct genl_ops *ops,
378+
struct sk_buff *skb, struct genl_info *info)
379+
{
380+
mutex_lock(&net_dm_mutex);
381+
382+
return 0;
383+
}
384+
385+
static void net_dm_nl_post_doit(const struct genl_ops *ops,
386+
struct sk_buff *skb, struct genl_info *info)
387+
{
388+
mutex_unlock(&net_dm_mutex);
389+
}
390+
383391
static struct genl_family net_drop_monitor_family __ro_after_init = {
384392
.hdrsize = 0,
385393
.name = "NET_DM",
386394
.version = 2,
395+
.pre_doit = net_dm_nl_pre_doit,
396+
.post_doit = net_dm_nl_post_doit,
387397
.module = THIS_MODULE,
388398
.ops = dropmon_ops,
389399
.n_ops = ARRAY_SIZE(dropmon_ops),

0 commit comments

Comments
 (0)