From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751074AbdAXPOo (ORCPT ); Tue, 24 Jan 2017 10:14:44 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38844 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750867AbdAXPOk (ORCPT ); Tue, 24 Jan 2017 10:14:40 -0500 Subject: Re: fs/jffs2/readinode.c:189: faulty logic ? To: Joakim Tjernlund , "linux-mtd@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "dwmw2@infradead.org" , "dcb314@hotmail.com" References: <8d72adf5-097f-0c72-edfc-d23d4199e9d4@gmail.com> <1485270700.4044.89.camel@infinera.com> From: Marek Vasut Message-ID: <87d819b7-8267-7d43-67b0-56c437c9290e@gmail.com> Date: Tue, 24 Jan 2017 16:14:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <1485270700.4044.89.camel@infinera.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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