Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-17 Thread Dan Carpenter
On Tue, May 17, 2016 at 10:22:20AM -0400, Lidza Louina wrote: > if (rc < 0) and if (rc) pretty much translates to the same thing. I wasn't talking about this patch in particular; it's just something I have thinking about recently. For example, there are a lot of functions that don't initialize pa

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-17 Thread Lidza Louina
On 05/17/2016 02:53 AM, Dan Carpenter wrote: When I read the code, I just assumed desc was a pointer and it should have been: if (!desc) return NULL; For me, "if (rc) " is way more readable than "if (rc != 0) ". So readability could go either way depending on what you

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread Dan Carpenter
When I read the code, I just assumed desc was a pointer and it should have been: if (!desc) return NULL; For me, "if (rc) " is way more readable than "if (rc != 0) ". So readability could go either way depending on what you're used to, I suppose. It should definitely ==

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread Lidza Louina
On 05/16/2016 02:35 PM, Dilger, Andreas wrote: On 2016/05/16, 12:16, "James Simmons" wrote: This looks wrong - You return -EINVAL from sptlrpc_pack_user_desc, but then the caller checks "!desc". Desc will not be null, since you've returned -EINVAL. Actually 'if (!desc)' is equal to 'if (de

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread Dilger, Andreas
On 2016/05/16, 12:16, "James Simmons" wrote: > >> This looks wrong - You return -EINVAL from sptlrpc_pack_user_desc, but then >> the caller checks "!desc". Desc will not be null, since you've returned >> -EINVAL. > >Actually 'if (!desc)' is equal to 'if (desc != 0). Yes it can be confusing. Ver

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread Patrick Farrell
James, No. You've got it backwards. 0 is false, any non-zero value is true. if(desc) would be equal to if (desc != 0). - Patrick On 05/16/2016 01:16 PM, James Simmons wrote: This looks wrong - You return -EINVAL from sptlrpc_pack_user_desc, but then the caller checks "!desc". Desc will no

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread James Simmons
> James, > > No. You've got it backwards. 0 is false, any non-zero value is true. > > if(desc) would be equal to if (desc != 0). Ah, you are right. Didn't get much sleep last night :-( > - Patrick > > On 05/16/2016 01:16 PM, James Simmons wrote: > > > This looks wrong - You return -EINVAL

Re: [lustre-devel] [PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread James Simmons
> This looks wrong - You return -EINVAL from sptlrpc_pack_user_desc, but then > the caller checks "!desc". Desc will not be null, since you've returned > -EINVAL. Actually 'if (!desc)' is equal to 'if (desc != 0). Yes it can be confusing. I recommend 'if (desc < 0)' instead to make it clearer wh

[PATCH v2] staging/lustre/ptlrpc: Removes potential null dereference

2016-05-16 Thread Lidza Louina
The lustre_msg_buf method could return NULL. Subsequent code didn't check if it's null before using it. This patch adds two checks. Signed-off-by: Lidza Louina --- drivers/staging/lustre/lustre/ptlrpc/sec.c | 2 ++ drivers/staging/lustre/lustre/ptlrpc/sec_plain.c | 9 +++-- 2 files cha