Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp803668pxb; Tue, 3 Nov 2020 13:00:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwht3bQ3MzYB06HwLmMKZOgnb0mljUbupZkTZoIClZhAI1Vlb35ti6waVu9KJMi91cnxDks X-Received: by 2002:aa7:cb02:: with SMTP id s2mr15710306edt.211.1604437231349; Tue, 03 Nov 2020 13:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437231; cv=none; d=google.com; s=arc-20160816; b=IzT6KeK3L/xtiNv2MqDX0bWKhNtmNNx8oRWji263BhzSYcXGe+chVFfVlTpv3aroiO l/n2+WfTpdTa5DMqNhFlEioNrGlIJ4LO6rEzGDOSivVPbEdAve15kXRkRJWvxJJaqfmw TR+V327USNkEPHU1uJ/3ZGybY8u07acm3P3a0ObwtiKumL++O5GPRkQE+W+lhRgSzmXB Cb9lMT9CIxOb/fyxZq9iBmMDlCmGZgXLJLKVc9dERntnP7BILkKyyhniRvt/1JecmRj+ EWCcQeSIiKupk8J52kT5azrc/XJfun2wNT035cirJrWYJIwlyqy0Z2/bNQ6QJzduflbF bt4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1ZzMQ2egPSKnZPO8WW/vwfHZfxwirXdE6TMFp2aW8QI=; b=oL1vfZIqZcbxRpKOrfJMktbarNpvRoXNdA3sOf2x2cikQ3yAIC5UWNi5DUK+D7kmxk ymmYHlVGlDEoDFTq1rZZLdgUrilmprpOYK5hKGD86/WWPXgonuPF++fwtfbSP6Q91S4j BnXeZI+ddmmB3R1H8vQj/8cUR2NXhmMJxAcwtKzt+fVIzFey+hcWhKqvmV5zKYQmPUEc TjKFflA3V1f285BRcLoLPdH1FhW+MJUGrPY/NBFx0LnehiEdtJFz9vywZBF23RbSUCRw ImkCW+h29PrMauhaHlIaycW428hM43I7asDu7CFGankKsnS8xW/t6/S0ZhvJRosbJPRj 84ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VwSFnLQj; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si10605571edi.391.2020.11.03.13.00.08; Tue, 03 Nov 2020 13:00:31 -0800 (PST) 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=@kernel.org header.s=default header.b=VwSFnLQj; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733018AbgKCU6u (ORCPT + 99 others); Tue, 3 Nov 2020 15:58:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:33412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732371AbgKCU6q (ORCPT ); Tue, 3 Nov 2020 15:58:46 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 97EC8223C7; Tue, 3 Nov 2020 20:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437125; bh=FytFa8TWDqxC9E6EocZFRBk3FNc7lYI4RPDDGt0dgjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwSFnLQjvjA0rl2q438RAWWPu8LaY2JOQRsF0eM5IexfJ2ZRaroupK63+xrSOWigd X2hO/e3kpodWGP7kombhcRbuIDM6LnGNxXc6ZdTQ3NvnvuOO+zRmOzf7R4k45RDY8E Xg2ykmUbjSA83okEOPZdh9hib6UHiaN3iiKorlng= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Fuzzey Subject: [PATCH 5.4 118/214] w1: mxc_w1: Fix timeout resolution problem leading to bus error Date: Tue, 3 Nov 2020 21:36:06 +0100 Message-Id: <20201103203301.944030141@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Fuzzey commit c9723750a699c3bd465493ac2be8992b72ccb105 upstream. 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 Link: https://lore.kernel.org/r/1601455030-6607-1-git-send-email-martin.fuzzey@flowbird.group Signed-off-by: Greg Kroah-Hartman --- drivers/w1/masters/mxc_w1.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- 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 *dat /* 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 *dat 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 *dat /* 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; }