From patchwork Thu Aug 27 14:32:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11740787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20F83109B for ; Thu, 27 Aug 2020 14:34:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED3F72177B for ; Thu, 27 Aug 2020 14:34:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z34SCglD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED3F72177B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; 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:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=U51tVrROQ1tiRj5AEhjMJHQzst0kmpgut74TS7bkXQw=; b=Z34SCglDZmNmgUGafW6/gATiN d7/xG/D+UkMxie+ShJ1ACQiz1WFX5+H4tCjnG38QBHxBec7GreYZ+lzxLT0uf5Oh2VaVGJ18zWRz4 cFqd27F/MHSiND1UGxXy9m/kuSeD9hmsb7A6fec04m5lXEJw7QDMBiGkQ4Yr+iCkyu1XsUmkwMfgw cU0dZVXQmgS7xeUMyMwGHXkuWP9+FsDg5yTA+EVGvVjdzSuItwZpmLfGiyDifFcciiIBWpo8WVEMC iCTcB5Wc1xVZP7M5be9rED8h7VKGUIidBdubiAddwdh4k2M17qL0iLbRAHoIYFop9Pn70P/mJIuMJ 11JAlEirw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBIxk-0002bC-St; Thu, 27 Aug 2020 14:33:13 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBIxa-0002Xk-5A for linux-arm-kernel@lists.infradead.org; Thu, 27 Aug 2020 14:33:03 +0000 Received: from [78.134.86.56] (port=49228 helo=melee.fritz.box) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBIxZ-0006H2-83; Thu, 27 Aug 2020 16:33:01 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v2 3/5] fpga manager: xilinx-spi: rework write_complete loop implementation Date: Thu, 27 Aug 2020 16:32:47 +0200 Message-Id: <20200827143249.10973-3-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200827143249.10973-1-luca@lucaceresoli.net> References: <20200827143249.10973-1-luca@lucaceresoli.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_103302_310503_4546A964 X-CRM114-Status: GOOD ( 10.62 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rix , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In preparation to add error checking for gpiod_get_value(), rework the loop to avoid the duplication of these lines: if (gpiod_get_value(conf->done)) return xilinx_spi_apply_cclk_cycles(conf); There is little advantage in this rework with current code. However error checking will expand these two lines to five, making code duplication more annoying. Signed-off-by: Luca Ceresoli --- This patch is new in v2 --- drivers/fpga/xilinx-spi.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index 01f494172379..cfc933d70f52 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -151,22 +151,19 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr, struct fpga_image_info *info) { struct xilinx_spi_conf *conf = mgr->priv; - unsigned long timeout; + unsigned long timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); int ret; - if (gpiod_get_value(conf->done)) - return xilinx_spi_apply_cclk_cycles(conf); - - timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); + while (true) { + if (gpiod_get_value(conf->done)) + return xilinx_spi_apply_cclk_cycles(conf); - while (time_before(jiffies, timeout)) { + if (time_after(jiffies, timeout)) + break; ret = xilinx_spi_apply_cclk_cycles(conf); if (ret) return ret; - - if (gpiod_get_value(conf->done)) - return xilinx_spi_apply_cclk_cycles(conf); } dev_err(&mgr->dev, "Timeout after config data transfer\n");