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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B218CC433EF for ; Sat, 11 Jun 2022 17:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ti/a804UKgevsO+X7SsvQqtWFIQdsLon/HsTn86ekdw=; b=sUqAHr4gsEsKI/ 1daKoOeUGIrV/10SrArlORMGu0HotLucOdXVskUbOiAb/8XfUZrodw6hfzQgFJ0zvV/Nt1yG9AihO b+nVodSsD6GezhuEvkoNUlWRmt+6Mg5JF00XnP24GhaRje64yJVQYke4it7E0FSEsQuFX5CbUvFee rpqw9mb9+V7xbg3legCjw/Wx1VAIwg0g7dZgc3hfJvNfwl1CX+pI50sxdQRI0m06jCk6qyGwGYBQV mUNc3GXlPiD8hZGUc0FRNZ149HkEavFp7BholVJgjgOOK3TWF9AyZQOy9ADvBPhkU0qRow5Qux70O D9DWP9YzU4MsgWzLqhFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o05AZ-00E1T4-7r; Sat, 11 Jun 2022 17:45:07 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o05AV-00E1Qj-Mv for linux-arm-kernel@lists.infradead.org; Sat, 11 Jun 2022 17:45:05 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 707F7CE09B5; Sat, 11 Jun 2022 17:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDDAAC34116; Sat, 11 Jun 2022 17:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654969494; bh=+CoBBCoe/KpGTA7h3kGWZ8vhCj+1Oix6HOVG6MCCe3s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NkZLVpVZKBdcTD/IhQsPtQ7tk3qoS2mrNkYgq9z7MgwS1IlKbr/gR4pzcHRkwUAjB Yn9oS71FEpV+miBQr0VaKqZKXNosA/YyP/TqMoNlNsEkF4X0CKTzONpaFFlQxoLvPl rKCYUGx0afdJjOTJLHVI+5kOXSbEdlVjLgN9iYTTNsBOGDkHkTed90EDo4iuPi50o7 emNJ0BBVwkcZFmLg3k3N0ng9EOSV3ZrF5114szKPkPhHQ3Ym4NHSIGpNWIn2HgoI4k NPq74A0TUKnJzFcbnF4mSoHY46+1lmq1Kc7TKY714U+6TO5HosHa/JmYd/PESCCHDe G8KqgMYlb8Q4w== Date: Sat, 11 Jun 2022 18:54:03 +0100 From: Jonathan Cameron To: Claudiu Beznea Subject: Re: [PATCH 07/16] iio: adc: at91-sama5d2_adc: simplify the code in at91_adc_read_info_raw() Message-ID: <20220611185403.3eaf9b65@jic23-huawei> In-Reply-To: <20220609083213.1795019-8-claudiu.beznea@microchip.com> References: <20220609083213.1795019-1-claudiu.beznea@microchip.com> <20220609083213.1795019-8-claudiu.beznea@microchip.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220611_104504_194256_B89FB944 X-CRM114-Status: GOOD ( 27.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, alexandre.belloni@bootlin.com, lars@metafoo.de, ludovic.desroches@atmel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, eugen.hristev@microchip.com, krzk+dt@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 9 Jun 2022 11:32:04 +0300 Claudiu Beznea wrote: > Simplify a bit the code in at91_adc_read_info_raw() by reducing the > number of lines of code. > > Signed-off-by: Claudiu Beznea I'm not convinced this is worth while, but there are some lesser steps visible in this patch that probably are. Given your earlier reorg to move at01_adc_adjust_val_osr() under the locks, you can now move the locks to the caller, thus not needing to handle them separately in all the exit paths. > --- > drivers/iio/adc/at91-sama5d2_adc.c | 35 +++++++++--------------------- > 1 file changed, 10 insertions(+), 25 deletions(-) > > diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c > index b52f1020feaf..fbb98e216e70 100644 > --- a/drivers/iio/adc/at91-sama5d2_adc.c > +++ b/drivers/iio/adc/at91-sama5d2_adc.c > @@ -1576,6 +1576,7 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, int *val) > { > struct at91_adc_state *st = iio_priv(indio_dev); > + int (*fn)(struct at91_adc_state *, int, u16 *) = NULL; > u16 tmp_val; > int ret; > > @@ -1583,29 +1584,18 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, > * Keep in mind that we cannot use software trigger or touchscreen > * if external trigger is enabled > */ > - if (chan->type == IIO_POSITIONRELATIVE) { > - ret = iio_device_claim_direct_mode(indio_dev); > - if (ret) > - return ret; You can drop this out of the if statements as it happens in all paths. Or even better, move it to the caller.. > - mutex_lock(&st->lock); > - > - ret = at91_adc_read_position(st, chan->channel, > - &tmp_val); huh? ret not checked? > - *val = tmp_val; > - ret = at91_adc_adjust_val_osr(st, val); Sure this is duplicated, but meh it's only a few lines. > - mutex_unlock(&st->lock); > - iio_device_release_direct_mode(indio_dev); this early release (compared to the long path) is the only bit really gets duplicated in all paths.. > + if (chan->type == IIO_POSITIONRELATIVE) > + fn = at91_adc_read_position; > + if (chan->type == IIO_PRESSURE) > + fn = at91_adc_read_pressure; > > + ret = iio_device_claim_direct_mode(indio_dev); > + if (ret) > return ret; > - } > - if (chan->type == IIO_PRESSURE) { this should always have been an else if () as the chan->type couldn't be both. > - ret = iio_device_claim_direct_mode(indio_dev); > - if (ret) > - return ret; > - mutex_lock(&st->lock); hence this lot can be shared with the above. > + mutex_lock(&st->lock); > > - ret = at91_adc_read_pressure(st, chan->channel, > - &tmp_val); > + if (fn) { > + ret = fn(st, chan->channel, &tmp_val); > *val = tmp_val; > ret = at91_adc_adjust_val_osr(st, val); > mutex_unlock(&st->lock); > @@ -1616,11 +1606,6 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, > > /* in this case we have a voltage channel */ > > - ret = iio_device_claim_direct_mode(indio_dev); > - if (ret) > - return ret; > - mutex_lock(&st->lock); > - > st->chan = chan; > > at91_adc_cor(st, chan); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel