[Cocci] [patch] CodingStyle: add some more error handling guidelines

Julia Lawall julia.lawall at lip6.fr
Tue Dec 2 10:09:02 CET 2014


> @@ -403,9 +408,10 @@ The rationale is:
>  int fun(int a)
>  {
>  	int result = 0;
> -	char *buffer = kmalloc(SIZE);
> +	char *buffer;
>
> -	if (buffer == NULL)
> +	buffer = kmalloc(SIZE);

kmalloc actually takes two arguments.  Perhaps it would be better to show
something that looks like a valid call.

Otherwise,

Acked-by: Julia Lawall <julia.lawall at lip6.fr>

julia

> +	if (!buffer)
>  		return -ENOMEM;
>
>  	if (condition1) {
> @@ -413,14 +419,25 @@ int fun(int a)
>  			...
>  		}
>  		result = 1;
> -		goto out;
> +		goto out_buffer;
>  	}
>  	...
> -out:
> +out_buffer:
>  	kfree(buffer);
>  	return result;
>  }
>
> +A common type of bug to be aware of it "one err bugs" which look like this:
> +
> +err:
> +	kfree(foo->bar);
> +	kfree(foo);
> +	return ret;
> +
> +The bug in this code is that on some exit paths "foo" is NULL.  Normally the
> +fix for this is to split it up into two error labels "err_bar:" and "err_foo:".
> +
> +
>  		Chapter 8: Commenting
>
>  Comments are good, but there is also a danger of over-commenting.  NEVER
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


More information about the Cocci mailing list