Skip to contentSkip to conversation

taskstats: tidy up the cpumask command path

PATCH Applied Bradley Morgan 1 participant 3 messages Jul 28 Taskstats statistics interface

lore
Share & tools
lore
#0 lore raw

cover taskstats: tidy up the cpumask command path

Two small cleanups from reading kernel/taskstats.c. No functional change in either one.

Patch 1 removes an unreachable NULL attribute check in parse(). Its stray "return 1" is not an error to any caller, so had the path ever been reached it would have registered listeners against an uninitialized cpumask.

Patch 2 folds cmd_attr_register_cpumask() and cmd_attr_deregister_cpumask() together, since they only differed in one attribute and one action.

Bradley Morgan (2):
taskstats: drop the dead NULL attribute check in parse()
taskstats: fold the two cpumask handlers into one

 kernel/taskstats.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 taskstats: drop the dead NULL attribute check in parse()

taskstats_user_cmd() only calls the cpumask handlers after checking the same info->attrs[] entry, so parse() never sees a NULL attribute. Drop the check and its odd "return 1", which no caller tested for anyway.

No functional change.

---
 kernel/taskstats.c | 2 --
 1 file changed, 2 deletions(-)
kernel/taskstats.c +0 -2
index bca91c394793..e7f8e1b5d1bc 100644
@@ -361,8 +361,6 @@ static int parse(struct nlattr *na, struct cpumask *mask)
 	int len;
 	int ret;
 
-	if (na == NULL)
-		return 1;
 	len = nla_len(na);
 	if (len > TASKSTATS_CPUMASK_MAXLEN)
 		return -E2BIG;
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/2 taskstats: fold the two cpumask handlers into one

In reply to Bradley Morgan

cmd_attr_register_cpumask() and cmd_attr_deregister_cpumask() differed only in which attribute they parsed and which action they passed on, so take both as arguments. __free(free_cpumask_var) then removes the goto.

No functional change.

---
 kernel/taskstats.c | 38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
kernel/taskstats.c +12 -26
index e7f8e1b5d1bc..3ae1755ca1b5 100644
@@ -449,36 +449,18 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
 	return send_reply(rep_skb, info);
 }
 
-static int cmd_attr_register_cpumask(struct genl_info *info)
+static int cmd_attr_cpumask(struct genl_info *info, int attr,
+			    enum actions action)
 {
-	cpumask_var_t mask;
+	cpumask_var_t mask __free(free_cpumask_var) = CPUMASK_VAR_NULL;
 	int rc;
 
 	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
 		return -ENOMEM;
-	rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
+	rc = parse(info->attrs[attr], mask);
 	if (rc < 0)
-		goto out;
-	rc = add_del_listener(info->snd_portid, mask, REGISTER);
-out:
-	free_cpumask_var(mask);
-	return rc;
-}
-
-static int cmd_attr_deregister_cpumask(struct genl_info *info)
-{
-	cpumask_var_t mask;
-	int rc;
-
-	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
-		return -ENOMEM;
-	rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
-	if (rc < 0)
-		goto out;
-	rc = add_del_listener(info->snd_portid, mask, DEREGISTER);
-out:
-	free_cpumask_var(mask);
-	return rc;
+		return rc;
+	return add_del_listener(info->snd_portid, mask, action);
 }
 
 static size_t taskstats_packet_size(void)
@@ -553,9 +535,13 @@ static int cmd_attr_tgid(struct genl_info *info)
 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
 {
 	if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
-		return cmd_attr_register_cpumask(info);
+		return cmd_attr_cpumask(info,
+					TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
+					REGISTER);
 	else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
-		return cmd_attr_deregister_cpumask(info);
+		return cmd_attr_cpumask(info,
+					TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
+					DEREGISTER);
 	else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
 		return cmd_attr_pid(info);
 	else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
Signature · 1 line
2.47.3