Re: [PATCH] lib/vsprintf.c:Avoid extra operation in dentry_name

From: Anshul Garg
Date: Tue Feb 17 2015 - 12:11:55 EST


Yes suggested code modification will break if (p==d) branch is not taken.
Thanks for pointing out this point.

So its better to keep code as it is.

On Tue, Feb 17, 2015 at 12:44 AM, Richard Weinberger
<richard.weinberger@xxxxxxxxx> wrote:
> On Mon, Feb 16, 2015 at 7:49 PM, Anshul Garg <aksgarg1989@xxxxxxxxx> wrote:
>> From: Anshul Garg <aksgarg1989@xxxxxxxxx>
>>
>> Remove unnecessary increment and decrement operation
>> in dentry_name function as after increment operation
>> loop is breaked and then decrement operation is
>> performed. So remove increment and decrement operation
>> from the function.
>>
>> Signed-off-by: Anshul Garg <aksgarg1989@xxxxxxxxx>
>> ---
>> lib/vsprintf.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
>> index ec337f6..2a38105 100644
>> --- a/lib/vsprintf.c
>> +++ b/lib/vsprintf.c
>> @@ -576,11 +576,10 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
>> if (p == d) {
>> if (i)
>> array[i] = "";
>> - i++;
>> break;
>> }
>> }
>> - s = array[--i];
>> + s = array[i];
>> for (n = 0; n != spec.precision; n++, buf++) {
>> char c = *s++;
>> if (!c) {
>
> What if the if (d == d) branch is not taken?
> Does the code then really behave exactly as before?
>
> --
> Thanks,
> //richard
--
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/