lkml.org 
[lkml]   [2018]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 03/25] staging: lustre: libcfs: implement cfs_cpt_cpumask for UMP case
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

\
 
 \ /
  Last update: 2018-04-16 15:53    [W:0.086 / U:3.556 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site