From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D8B1C433DF for ; Tue, 25 Aug 2020 06:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BC0E2076C for ; Tue, 25 Aug 2020 06:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729074AbgHYGiY (ORCPT ); Tue, 25 Aug 2020 02:38:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:45118 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729068AbgHYGiW (ORCPT ); Tue, 25 Aug 2020 02:38:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7E359AD2F; Tue, 25 Aug 2020 06:38:51 +0000 (UTC) Date: Tue, 25 Aug 2020 08:38:19 +0200 From: Jean Delvare To: Bartosz Golaszewski Cc: Linux I2C , Arnd Bergmann , Greg Kroah-Hartman Subject: Re: [PATCH 2/2 RFC] eeprom: at24: Tidy at24_read() Message-ID: <20200825083819.7478f26e@endymion> In-Reply-To: References: <20200807150005.48c8c89b@endymion> <20200807161906.6d119d2e@endymion> Organization: SUSE Linux X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Hi Bartosz, On Tue, 18 Aug 2020 15:46:36 +0200, Bartosz Golaszewski wrote: > On Fri, Aug 7, 2020 at 4:19 PM Jean Delvare wrote: > > The elegant code in at24_read() has the drawback that we now need > > to make a copy of all parameters to pass them to the post-processing > > callback function if there is one. Rewrite the loop in such a way that > > the parameters are not modified, so saving them is no longer needed. > > > > Signed-off-by: Jean Delvare > > Cc: Bartosz Golaszewski > > Cc: Arnd Bergmann > > Cc: Greg Kroah-Hartman > > --- > > This has the drawback of creating an asymetry with at24_write(), so > > I'm not 100% if we want to apply this. If anyone has a better idea, > > please let me know. > > > > drivers/misc/eeprom/at24.c | 13 +++++-------- > > 1 file changed, 5 insertions(+), 8 deletions(-) > > > > --- linux-5.7.orig/drivers/misc/eeprom/at24.c 2020-08-07 14:23:39.882191500 +0200 > > +++ linux-5.7/drivers/misc/eeprom/at24.c 2020-08-07 14:28:39.039360687 +0200 > > (...) > > @@ -449,15 +446,15 @@ static int at24_read(void *priv, unsigne > > */ > > mutex_lock(&at24->lock); > > > > + i = 0; > > Hi Jean, > > I think doing: > > for (i = 0; count; i += ret, count -= ret) > > would be even more elegant, don't you think? Definitely. I'll change the code that way and send v2 of the patch, thank you for the suggestion. > Bartosz > > > while (count) { > > - ret = at24_regmap_read(at24, buf, off, count); > > + ret = at24_regmap_read(at24, buf + i, off + i, count); > > if (ret < 0) { > > mutex_unlock(&at24->lock); > > pm_runtime_put(dev); > > return ret; > > } > > - buf += ret; > > - off += ret; > > + i += ret; > > count -= ret; > > } > > -- Jean Delvare SUSE L3 Support