lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20100927093205.GG11780@balbir.in.ibm.com>
Date:	Mon, 27 Sep 2010 15:02:05 +0530
From:	Balbir Singh <balbir@...ux.vnet.ibm.com>
To:	Michael Holzheu <holzheu@...ux.vnet.ibm.com>
Cc:	Shailabh Nagar <nagar1234@...ibm.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Venkatesh Pallipadi <venki@...gle.com>,
	Suresh Siddha <suresh.b.siddha@...el.com>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Ingo Molnar <mingo@...e.hu>, Oleg Nesterov <oleg@...hat.com>,
	John stultz <johnstul@...ibm.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Martin Schwidefsky <schwidefsky@...ibm.com>,
	Heiko Carstens <heiko.carstens@...ibm.com>,
	linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org
Subject: Re: [RFC][PATCH 02/10] taskstats: Separate taskstats commands

* Michael Holzheu <holzheu@...ux.vnet.ibm.com> [2010-09-23 16:01:02]:

> Subject: [PATCH] taskstats: Separate taskstats commands
> 
> From: Michael Holzheu <holzheu@...ux.vnet.ibm.com>
> 
> This patch moves each taskstats command into a single function. This
> makes
> the code more readable and makes it easier to add new commands.
> 
> Signed-off-by: Michael Holzheu <holzheu@...ux.vnet.ibm.com>
> ---
>  kernel/taskstats.c |  118
> +++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 78 insertions(+), 40 deletions(-)
> 
> --- a/kernel/taskstats.c
> +++ b/kernel/taskstats.c
> @@ -424,39 +424,76 @@ err:
>  	return rc;
>  }
> 
> -static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info
> *info)
> +static int cmd_attr_register_cpumask(struct genl_info *info)
>  {
> -	int rc;
> -	struct sk_buff *rep_skb;
> -	struct taskstats *stats;
> -	size_t size;
>  	cpumask_var_t mask;
> +	int rc;
> 
>  	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
>  		return -ENOMEM;
> -
>  	rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
>  	if (rc < 0)
> -		goto free_return_rc;
> -	if (rc == 0) {
> -		rc = add_del_listener(info->snd_pid, mask, REGISTER);
> -		goto free_return_rc;
> -	}
> +		goto out;
> +	rc = add_del_listener(info->snd_pid, 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 free_return_rc;
> -	if (rc == 0) {
> -		rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
> -free_return_rc:
> -		free_cpumask_var(mask);
> -		return rc;
> -	}
> +		goto out;
> +	rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
> +out:
>  	free_cpumask_var(mask);
> +	return rc;
> +}
> +
> +static int cmd_attr_pid(struct genl_info *info)
> +{
> +	struct taskstats *stats;
> +	struct sk_buff *rep_skb;
> +	size_t size;
> +	u32 pid;
> +	int rc;
> +
> +	size = nla_total_size(sizeof(u32)) +
> +		nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
> +
> +	rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
> +	if (rc < 0)
> +		return rc;
> +
> +	rc = -EINVAL;
> +	pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
> +	stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
> +	if (!stats)
> +		goto err;
> +
> +	rc = fill_pid(pid, NULL, stats);
> +	if (rc < 0)
> +		goto err;
> +	return send_reply(rep_skb, info);
> +err:
> +	nlmsg_free(rep_skb);
> +	return rc;
> +}
> +
> +static int cmd_attr_tgid(struct genl_info *info)
> +{
> +	struct taskstats *stats;
> +	struct sk_buff *rep_skb;
> +	size_t size;
> +	u32 tgid;
> +	int rc;
> 
> -	/*
> -	 * Size includes space for nested attributes
> -	 */
>  	size = nla_total_size(sizeof(u32)) +
>  		nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
> 
> @@ -465,33 +502,34 @@ free_return_rc:
>  		return rc;
> 
>  	rc = -EINVAL;
> -	if (info->attrs[TASKSTATS_CMD_ATTR_PID]) {
> -		u32 pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
> -		stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
> -		if (!stats)
> -			goto err;
> -
> -		rc = fill_pid(pid, NULL, stats);
> -		if (rc < 0)
> -			goto err;
> -	} else if (info->attrs[TASKSTATS_CMD_ATTR_TGID]) {
> -		u32 tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
> -		stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
> -		if (!stats)
> -			goto err;
> -
> -		rc = fill_tgid(tgid, NULL, stats);
> -		if (rc < 0)
> -			goto err;
> -	} else
> +	tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
> +	stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
> +	if (!stats)
>  		goto err;
> 
> +	rc = fill_tgid(tgid, NULL, stats);
> +	if (rc < 0)
> +		goto err;
>  	return send_reply(rep_skb, info);
>  err:
>  	nlmsg_free(rep_skb);
>  	return rc;
>  }
> 
> +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);
> +	else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
> +		return cmd_attr_deregister_cpumask(info);
> +	else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
> +		return cmd_attr_pid(info);
> +	else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
> +		return cmd_attr_tgid(info);
> +	else
> +		return -EINVAL;
> +}
> +
>  static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
>  {
>  	struct signal_struct *sig = tsk->signal;
> 
> 


Looks like good clean-up

Acked-by: Balbir Singh <balbir@...ux.vnet.ibm.com>
 

-- 
	Three Cheers,
	Balbir
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ