Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1565917 > unrolled thread

Re: fs/jffs2/readinode.c:189: faulty logic ?

Started byMarek Vasut <marek.vasut@gmail.com>
First post2017-01-24 16:00 +0100
Last post2017-01-24 21:10 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: fs/jffs2/readinode.c:189: faulty logic ? Marek Vasut <marek.vasut@gmail.com> - 2017-01-24 16:00 +0100
    Re: fs/jffs2/readinode.c:189: faulty logic ? Marek Vasut <marek.vasut@gmail.com> - 2017-01-24 16:20 +0100
    Re: fs/jffs2/readinode.c:189: faulty logic ? Marek Vasut <marek.vasut@gmail.com> - 2017-01-24 21:10 +0100

#1565917 — Re: fs/jffs2/readinode.c:189: faulty logic ?

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-01-24 16:00 +0100
SubjectRe: fs/jffs2/readinode.c:189: faulty logic ?
Message-ID<t3aJI-5zH-19@gated-at.bofh.it>
On 01/24/2017 09:15 AM, David Binderman wrote:
> Hello there,
> 
> fs/jffs2/readinode.c:189]: (style) Condition 'tn.fn.ofs>=offset' is always true
> 
> Source code is
> 
>         if (tn->fn->ofs < offset)
>             next = tn->rb.rb_right;
>         else if (tn->fn->ofs >= offset)
>             next = tn->rb.rb_left;
>         else
>             break;
> 
> Maybe better code
> 
>         if (tn->fn->ofs < offset)
>             next = tn->rb.rb_right;
>         else if (tn->fn->ofs > offset)
>             next = tn->rb.rb_left;
>         else
>             break;

This changes the logic of the code for equality case, please elaborate
why this is OK.

> Regards
> 
> David Binderman
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
> 


-- 
Best regards,
Marek Vasut

[toc] | [next] | [standalone]


#1565936

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-01-24 16:20 +0100
Message-ID<t3b34-5VZ-35@gated-at.bofh.it>
In reply to#1565917
On 01/24/2017 04:11 PM, Joakim Tjernlund wrote:
> On Tue, 2017-01-24 at 15:52 +0100, Marek Vasut wrote:
>> On 01/24/2017 09:15 AM, David Binderman wrote:
>>> Hello there,
>>>
>>> fs/jffs2/readinode.c:189]: (style) Condition 'tn.fn.ofs>=offset' is always true
>>>
>>> Source code is
>>>
>>>         if (tn->fn->ofs < offset)
>>>             next = tn->rb.rb_right;
>>>         else if (tn->fn->ofs >= offset)
>>>             next = tn->rb.rb_left;
>>>         else
>>>             break;
>>>
>>> Maybe better code
>>>
>>>         if (tn->fn->ofs < offset)
>>>             next = tn->rb.rb_right;
>>>         else if (tn->fn->ofs > offset)
>>>             next = tn->rb.rb_left;
>>>         else
>>>             break;
>>
>> This changes the logic of the code for equality case, please elaborate
>> why this is OK.
> 
> There is something odd with current code:
> 	next = tn_root->rb_node;
> 
> 	while (next) {
> 		tn = rb_entry(next, struct jffs2_tmp_dnode_info, rb);
> 
> 		if (tn->fn->ofs < offset)
> 			next = tn->rb.rb_right;
> 		else if (tn->fn->ofs >= offset)
> 			next = tn->rb.rb_left;
> 		else
> 			break;
> 	}
> 
> The else break; is never reached so the above change makes the break work for ==
> Weather this is correct or not I cannot say.

Indeed, I agree with this one. This is why I asked for more detailed
explanation too :)

-- 
Best regards,
Marek Vasut

[toc] | [prev] | [next] | [standalone]


#1566103

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-01-24 21:10 +0100
Message-ID<t3fzI-kX-5@gated-at.bofh.it>
In reply to#1565917
On 01/24/2017 08:17 PM, David Binderman wrote:
> 
> Hello there,
> 
> 
> ________________________________
> 
>> This changes the logic of the code for equality case, please elaborate
>> why this is OK.
> 
> RTFM.
> 
> Linux kernel file Documentation/rbtree.txt, around line 95, has the standard logic
> for traversing a red black tree.

In that case, please RTFM Documentation/process/submitting-patches.rst
and we continue the discussion there :)

-- 
Best regards,
Marek Vasut

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web