From mboxrd@z Thu Jan 1 00:00:00 1970 From: Weijie Gao Date: Wed, 15 Apr 2020 15:20:56 +0800 Subject: [PATCH 3/3] mips: mt76x8: ddr_cal: Correct dqs_find_min/max implementations In-Reply-To: <20200306141405.24539-3-sr@denx.de> References: <20200306141405.24539-1-sr@denx.de> <20200306141405.24539-3-sr@denx.de> Message-ID: <1586935256.26858.145.camel@mcddlt001> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Fri, 2020-03-06 at 15:14 +0100, Stefan Roese wrote: > The current implementations have some issues detecting the correct > values: > > dqs_find_max() will return "last passing fieldval + 1" instead of > "last passing fieldval". Also it will return "maxval + 1" in the > case that all fieldvals are tested valid (without error). > > dqs_find_min() will not test the "lowest" value because of using ">" > instead of ">=". > > This patch now rewrites these functions to fix those issues. Also, > this patch uses the same approach of a for loop in both functions making > it easier to read and maintain. > > Since the variables are integers now, we can use min()/max(), which > handles the wrap around case for fieldval=0: return (0 - 1). > > Signed-off-by: Stefan Roese > Cc: Weijie Gao > Cc: Daniel Schwierzeck > --- > arch/mips/mach-mtmips/ddr_cal.c | 28 ++++++++++------------------ > 1 file changed, 10 insertions(+), 18 deletions(-) > Reviewed-by: Weijie Gao