[PATCH 03/25] staging: lustre: libcfs: implement cfs_cpt_cpumask for UMP case

Dan Carpenter dan.carpenter at oracle.com
Mon Apr 16 13:51:57 UTC 2018


On Mon, Apr 16, 2018 at 12:09:45AM -0400, James Simmons wrote:
> diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
> index 705abf2..5ea294f 100644
> --- a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
> +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c
> @@ -54,6 +54,9 @@ struct cfs_cpt_table *
>  	cptab = kzalloc(sizeof(*cptab), GFP_NOFS);
>  	if (cptab) {
        ^^^^^^^^^^^^
Don't do "success handling", do "error handling".  Success handling
means we have to indent the code and it makes it more complicated to
read.  Ideally code would look like:

	do_this();
	do_that();
	do_the_next_thing();

But because of error handling then we have to add a bunch of if
statements.  It's better when those if statements are very quick and
we can move on.  The success path is all at indent level one still like
and ideal situation above and the the error paths are at indent level
two.

	if (!cptab)
		return NULL;


>  		cptab->ctb_version = CFS_CPU_VERSION_MAGIC;
> +		if (!zalloc_cpumask_var(&cptab->ctb_mask, GFP_NOFS))
> +			return NULL;

This leaks.  It should be:

	if (!zalloc_cpumask_var(&cptab->ctb_mask, GFP_NOFS)) {
		kfree(cptab);
		return NULL;
	}

> +		cpumask_set_cpu(0, cptab->ctb_mask);
>  		node_set(0, cptab->ctb_nodemask);
>  		cptab->ctb_nparts  = ncpt;
>  	}

regards,
dan carpenter


More information about the devel mailing list