lkml.org 
[lkml]   [2006]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] Minor coding style fix
Date
Jesper Juhl wrote:
> On 08/10/06, Aneesh Kumar K.V <aneesh.kumar@gmail.com> wrote:
>> Kernel generally follow the style
>>
>> if (func()) {
>> /* failed case */
>> } else {
>> /* success */
>> }
>>
>>
>
> Please submit patches inline, having to copy them from attachments to
> be able to reply is a pain.
>
>>
>> diff --git a/kernel/sys.c b/kernel/sys.c
>> index 98489d8..55cb77c 100644
>> --- a/kernel/sys.c
>> +++ b/kernel/sys.c
>> @@ -517,7 +517,7 @@ EXPORT_SYMBOL_GPL(srcu_notifier_call_cha
>> void srcu_init_notifier_head(struct srcu_notifier_head *nh)
>> {
>> mutex_init(&nh->mutex);
>> - if (init_srcu_struct(&nh->srcu) < 0)
>> + if (init_srcu_struct(&nh->srcu))
>> BUG();
>> nh->head = NULL;
>> }
>
> I really liked the old code better. If in the future
> init_srcu_struct() is changed to also return >0 for some conditions,
> then that would not previously have triggered BUG(), but after your
> changes it will. The code, as it were, perfectly expressed what it
> wanted to happen - if it returns less than zero it's a BUG().
> I say leave it alone.
>
>


As per Documentation/CodingStyle

"Functions can return values of many different kinds, and one of the
most common is a value indicating whether the function succeeded or
failed. Such a value can be represented as an error-code integer
(-Exxx = failure, 0 = success) or a "succeeded" boolean (0 = failure,
non-zero = success)."

That means if the function need to indicate success it should be made to return 0.
I don't see any other value being returned from init_srcu_struct. Also having a consistent
style of if() check make code reading easier.

-aneesh

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

\
 
 \ /
  Last update: 2006-10-08 19:21    [W:0.043 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site