Re: [PATCH] sysctl: remove impossible condition check
From: Eric W. Biederman
Date: Thu Jun 02 2011 - 09:40:28 EST
Lucas De Marchi <lucas.demarchi@xxxxxxxxxxxxxx> writes:
> [ CC'ing Al Viro ]
>
> On Wed, Jun 1, 2011 at 10:25 AM, Jesper Juhl <jj@xxxxxxxxxxxxx> wrote:
>> How about compacting it even further by getting rid of the 'len' variable
>> as well?
>> Like this:
>>
>> Signed-off-by: Jesper Juhl <jj@xxxxxxxxxxxxx>
>> ---
>> Âproc_sysctl.c | Â 10 ++--------
>> Â1 file changed, 2 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
>> index f50133c..bd7f7af 100644
>> --- a/fs/proc/proc_sysctl.c
>> +++ b/fs/proc/proc_sysctl.c
>> @@ -49,17 +49,11 @@ out:
>>
>> Âstatic struct ctl_table *find_in_table(struct ctl_table *p, struct qstr *name)
>> Â{
>> - Â Â Â int len;
>> Â Â Â Âfor ( ; p->procname; p++) {
>> -
>> - Â Â Â Â Â Â Â if (!p->procname)
>> - Â Â Â Â Â Â Â Â Â Â Â continue;
>> -
>> - Â Â Â Â Â Â Â len = strlen(p->procname);
>> - Â Â Â Â Â Â Â if (len != name->len)
>> + Â Â Â Â Â Â Â if (strlen(p->procname) != name->len)
>> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
>>
>> - Â Â Â Â Â Â Â if (memcmp(p->procname, name->name, len) != 0)
>> + Â Â Â Â Â Â Â if (memcmp(p->procname, name->name, name->len) != 0)
>> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
>>
>> Â Â Â Â Â Â Â Â/* I have a match */
>>
>
>
> Looking again at the code, I'm wondering if this is not actually a
> bug. There might be entries with procname == NULL, meaning they are
> not mirrored in /proc. What seems wrong is the condition in the for().
> It should stop when all fields are 0 (meaning the end of the table)
> instead of stopping when procname is NULL.
It is not a bug. The condition was originally p->ctlname then
it became p->ctlname || p->procname and then finally I was able to
kill ctl_name.
What you see is a left over that didn't get removed.
This is also the second time in the last couple of weeks someone has
sent this patch.
There is some ongoing work to make sysctl scale better that with
any luck should be ready for 3.1. Decide which version of this
patch you like and please resend, and I will add this to my
sysctl tree.
Thank you,
Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/