From patchwork Thu Sep 20 16:14:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10608023 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C83615A6 for ; Thu, 20 Sep 2018 16:14:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C95652E0B4 for ; Thu, 20 Sep 2018 16:14:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5B6C2DEEE; Thu, 20 Sep 2018 16:14:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A6BC2DEEE for ; Thu, 20 Sep 2018 16:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbeITV6r (ORCPT ); Thu, 20 Sep 2018 17:58:47 -0400 Received: from sauhun.de ([88.99.104.3]:60932 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbeITV6r (ORCPT ); Thu, 20 Sep 2018 17:58:47 -0400 Received: from localhost (i577B999D.versanet.de [87.123.153.157]) by pokefinder.org (Postfix) with ESMTPSA id AC2962E35A2; Thu, 20 Sep 2018 18:14:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Stefan Lengfeld , preid@electromag.com.au, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Keerthy , Tero Kristo , Grygorii Strashko , Andy Shevchenko , Wolfram Sang Subject: [RFC PATCH 2/4] i2c: core: remove level of indentation in i2c_transfer Date: Thu, 20 Sep 2018 18:14:21 +0200 Message-Id: <20180920161423.13990-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> References: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using the common kernel pattern to bail out at the beginning if some conditions are not met, we can save a level of indentation. No functional change. Signed-off-by: Wolfram Sang Acked-by: Peter Rosin --- drivers/i2c/i2c-core-base.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index c2b352c46fae..799776c6d421 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1922,6 +1922,11 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { int ret; + if (!adap->algo->master_xfer) { + dev_dbg(&adap->dev, "I2C level transfers not supported\n"); + return -EOPNOTSUPP; + } + /* REVISIT the fault reporting model here is weak: * * - When we get an error after receiving N bytes from a slave, @@ -1938,25 +1943,19 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) * one (discarding status on the second message) or errno * (discarding status on the first one). */ - - if (adap->algo->master_xfer) { - if (in_atomic() || irqs_disabled()) { - ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); - if (!ret) - /* I2C activity is ongoing. */ - return -EAGAIN; - } else { - i2c_lock_bus(adap, I2C_LOCK_SEGMENT); - } - - ret = __i2c_transfer(adap, msgs, num); - i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); - - return ret; + if (in_atomic() || irqs_disabled()) { + ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); + if (!ret) + /* I2C activity is ongoing. */ + return -EAGAIN; } else { - dev_dbg(&adap->dev, "I2C level transfers not supported\n"); - return -EOPNOTSUPP; + i2c_lock_bus(adap, I2C_LOCK_SEGMENT); } + + ret = __i2c_transfer(adap, msgs, num); + i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); + + return ret; } EXPORT_SYMBOL(i2c_transfer);