From patchwork Mon Mar 3 10:06:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 3752991 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 84E43BF13A for ; Mon, 3 Mar 2014 10:14:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 910AD2038C for ; Mon, 3 Mar 2014 10:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53F9A20304 for ; Mon, 3 Mar 2014 10:14:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754385AbaCCKJs (ORCPT ); Mon, 3 Mar 2014 05:09:48 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:49464 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754211AbaCCKIH (ORCPT ); Mon, 3 Mar 2014 05:08:07 -0500 Received: from [201.74.152.26] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1WKPn2-00078I-Q2; Mon, 03 Mar 2014 10:08:05 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1WKPmF-0006Yf-JU; Mon, 03 Mar 2014 07:07:15 -0300 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH 62/79] [media] drx-j: use the proper timeout code on scu_command Date: Mon, 3 Mar 2014 07:06:56 -0300 Message-Id: <1393841233-24840-63-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1393841233-24840-1-git-send-email-m.chehab@samsung.com> References: <1393841233-24840-1-git-send-email-m.chehab@samsung.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Checking if a time is after another one can have issues, as times are generally u32 wide. Use the proper macros for that at scu_command(). It should be noticed that other places also use jiffies calculus on an improper way. This should be fixed too, but the logic there is more complex. So, let's do it in separate patches. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/drx39xyj/drxj.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c index b1a7dfeec489..c843d8f4a96a 100644 --- a/drivers/media/dvb-frontends/drx39xyj/drxj.c +++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c @@ -4417,8 +4417,8 @@ rw_error: static int scu_command(struct i2c_device_addr *dev_addr, struct drxjscu_cmd *cmd) { int rc; - u32 start_time = 0; u16 cur_cmd = 0; + unsigned long timeout; /* Check param */ if (cmd == NULL) @@ -4478,15 +4478,17 @@ static int scu_command(struct i2c_device_addr *dev_addr, struct drxjscu_cmd *cmd } /* Wait until SCU has processed command */ - start_time = jiffies_to_msecs(jiffies); - do { + timeout = jiffies + msecs_to_jiffies(DRXJ_MAX_WAITTIME); + while (time_is_after_jiffies(timeout)) { rc = DRXJ_DAP.read_reg16func(dev_addr, SCU_RAM_COMMAND__A, &cur_cmd, 0); if (rc != 0) { pr_err("error %d\n", rc); goto rw_error; } - } while (!(cur_cmd == DRX_SCU_READY) - && ((jiffies_to_msecs(jiffies) - start_time) < DRXJ_MAX_WAITTIME)); + if (cur_cmd == DRX_SCU_READY) + break; + usleep_range(1000, 2000); + } if (cur_cmd != DRX_SCU_READY) return -EIO;