Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4398874pxk; Wed, 30 Sep 2020 01:40:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/KLCLZ1en5ajnlcXgXmzrbhXEaWM8kgSTNb/yoXCVnUakc5XJNCH1taFjxksjcv5+fsoa X-Received: by 2002:a17:906:c191:: with SMTP id g17mr1759469ejz.117.1601455235744; Wed, 30 Sep 2020 01:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601455235; cv=none; d=google.com; s=arc-20160816; b=WeV7pJiIyLtVBrilC3acBRklW4mDTF6O7i06UsibUi/WSxDdfhdk//VnD7uRZZnN4B eid33xf3gyPsQHIshnB55GTRT1eGLjsrZ+/1wS286lBuJnKiO4QAEjbtoJTHDkt8nMur iM3LVH7dWbVCw3BV9Vinset9y7/dH5NXygjEHeu0zho0EnrSFcifGDVulT6TXDfhl5fm Z+zEBhwqjYsy4v1zSinthh24EC3NPEhqPHjH32vOkJ+ooqtqj0KNJQYK15gLrJIvjyUc OdQxOt3a1uSTZ1tGf2c1UvcC64p5wj2Bb5VntkZSf15Ac7N2jfOETkvsZtrrjS/AcBiu 9aaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=umCDvoHS92WYFRuwfVxZMNhfWaiHknS4wbUC7gryG04=; b=Pnk1hRWk2AlkbJCWpeWMOn0dp3+twomHzgmEbKWQeY3uuVNYA/yA1akVLnAZ77G/O1 /03lSwBfnfU3RqtgZNtor8mJkLuudxkoI1qqQli4unXpEKmh+Frt2owbse2+CO8pqBQx r2wsvczySvy4kHJ9VQF+OHt84hJhkTt4NuFcu8sfphxjQTT7GTqizZZLnikv5OTsNvji 83k2z614/kt+csOyfFafnaVc39DXygBinU0O3jNB2S8imGnXXUMcK0goEEPgyzPYY6Cq HwUJnglU9zwvIIB4J0Wet0GviQ2VrzSiyAeRg5lRU98Rbl/pAepJqg/hGdPPt9hRRF3x 0sug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b=UnmVqInn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i24si565970edr.73.2020.09.30.01.40.12; Wed, 30 Sep 2020 01:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b=UnmVqInn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728655AbgI3IhO (ORCPT + 99 others); Wed, 30 Sep 2020 04:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728608AbgI3IhN (ORCPT ); Wed, 30 Sep 2020 04:37:13 -0400 Received: from mail-wm1-x363.google.com (mail-wm1-x363.google.com [IPv6:2a00:1450:4864:20::363]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70FC4C0613D0 for ; Wed, 30 Sep 2020 01:37:13 -0700 (PDT) Received: by mail-wm1-x363.google.com with SMTP id x23so758078wmi.3 for ; Wed, 30 Sep 2020 01:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flowbird.group; s=google; h=from:to:cc:subject:date:message-id; bh=umCDvoHS92WYFRuwfVxZMNhfWaiHknS4wbUC7gryG04=; b=UnmVqInnkaIedrnmIPkE3QV6FeOhxdSjDbkePDyLRzfUyZCDG1+6b2Vq5YV+dPQ3Zg 83rICFA1CLGhiTCzGhceNh9uHrcdfw3zbRgv587hL6LtebVwX2v8fSjNTy7fAKGqAzG9 FY0vmojfLITQc6+byDY+UGkgCVTlYM5+qL7zPHU0Zf38g4yX1Cbz5EwAqMLxb6ZUq0pl tXQQRSjg0BzdbMi5Ocrb+G0QSNh1SR1F/SY3WrfGCvGQ3XNmygsf76Tnq5740PuRTQM9 6/1jWdkt14KboXqNQamKpra/5UnyFK13T5M4X0+724YfRdEsnIRYYIgKGM3kNmcxF0ng fezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=umCDvoHS92WYFRuwfVxZMNhfWaiHknS4wbUC7gryG04=; b=es5i787IkZPTflpA7ken6UO+rx3x+fYbHjgYcqjU/mQRDZOMXb7W2eT7lipLbuZ+5k x/skxikVvIUdkGAkzsKLVlFqJiBw1UYddogzhmovsZ6eE9PK2463sPBSxFld1z7DRYP6 pDxUsS1a+3N72ZG0q1TumM6ENkEU+4S+1tEqH7miPjC0E+wCmMTJxvKIijwUxJs9IHgD 8mZ77kT70ASCyHsUWk7kBNTL8UByTEtz5lpJ5BzEG1cThOUd3Qm02LCw4gy4tQr34LOF /6cvs6EFbSvqWfssRPpAoLFNjuwHwi34n9Jyqj/qWtFbt28UV1sn0bkgdSsfdXHvVHwm haXQ== X-Gm-Message-State: AOAM531yX3YIOkMAf+2ozdUo12xMNhgkNW0nPyG+Kmrm8juzr/9qf9DJ y75AMT2q/bG8DtM1D4UMnF4drsl9s8+QQSGtqOzWzajjGORb X-Received: by 2002:a1c:dd87:: with SMTP id u129mr1718447wmg.172.1601455031053; Wed, 30 Sep 2020 01:37:11 -0700 (PDT) Received: from mta1.parkeon.com ([185.149.63.251]) by smtp-relay.gmail.com with ESMTPS id m7sm25035wrn.45.2020.09.30.01.37.10 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 30 Sep 2020 01:37:11 -0700 (PDT) X-Relaying-Domain: flowbird.group Received: from [172.16.12.34] (port=47850 helo=PC12445-BES.dynamic.besancon.parkeon.com) by mta1.parkeon.com with esmtp (Exim 4.71) (envelope-from ) id 1kNXbq-0003VN-LL; Wed, 30 Sep 2020 10:37:10 +0200 From: Martin Fuzzey To: Evgeniy Polyakov Cc: Alexander Shiyan , stable , linux-kernel@vger.kernel.org Subject: [PATCH] w1: mxc_w1: Fix timeout resolution problem leading to bus error Date: Wed, 30 Sep 2020 10:36:46 +0200 Message-Id: <1601455030-6607-1-git-send-email-martin.fuzzey@flowbird.group> X-Mailer: git-send-email 1.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On my platform (i.MX53) bus access sometimes fails with w1_search: max_slave_count 64 reached, will continue next search. The reason is the use of jiffies to implement a 200us timeout in mxc_w1_ds2_touch_bit(). On some platforms the jiffies timer resolution is insufficient for this. Fix by replacing jiffies by ktime_get(). For consistency apply the same change to the other use of jiffies in mxc_w1_ds2_reset_bus(). Fixes: f80b2581a706 ("w1: mxc_w1: Optimize mxc_w1_ds2_touch_bit()") Cc: stable Signed-off-by: Martin Fuzzey --- drivers/w1/masters/mxc_w1.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c index 1ca880e..090cbbf 100644 --- a/drivers/w1/masters/mxc_w1.c +++ b/drivers/w1/masters/mxc_w1.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,12 +40,12 @@ struct mxc_w1_device { static u8 mxc_w1_ds2_reset_bus(void *data) { struct mxc_w1_device *dev = data; - unsigned long timeout; + ktime_t timeout; writeb(MXC_W1_CONTROL_RPP, dev->regs + MXC_W1_CONTROL); /* Wait for reset sequence 511+512us, use 1500us for sure */ - timeout = jiffies + usecs_to_jiffies(1500); + timeout = ktime_add_us(ktime_get(), 1500); udelay(511 + 512); @@ -55,7 +55,7 @@ static u8 mxc_w1_ds2_reset_bus(void *data) /* PST bit is valid after the RPP bit is self-cleared */ if (!(ctrl & MXC_W1_CONTROL_RPP)) return !(ctrl & MXC_W1_CONTROL_PST); - } while (time_is_after_jiffies(timeout)); + } while (ktime_before(ktime_get(), timeout)); return 1; } @@ -68,12 +68,12 @@ static u8 mxc_w1_ds2_reset_bus(void *data) static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit) { struct mxc_w1_device *dev = data; - unsigned long timeout; + ktime_t timeout; writeb(MXC_W1_CONTROL_WR(bit), dev->regs + MXC_W1_CONTROL); /* Wait for read/write bit (60us, Max 120us), use 200us for sure */ - timeout = jiffies + usecs_to_jiffies(200); + timeout = ktime_add_us(ktime_get(), 200); udelay(60); @@ -83,7 +83,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit) /* RDST bit is valid after the WR1/RD bit is self-cleared */ if (!(ctrl & MXC_W1_CONTROL_WR(bit))) return !!(ctrl & MXC_W1_CONTROL_RDST); - } while (time_is_after_jiffies(timeout)); + } while (ktime_before(ktime_get(), timeout)); return 0; } -- 1.9.1