Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9174723pxu; Mon, 28 Dec 2020 08:26:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsui2hJCL0DOIeCu/8a66JJGHrMIRO5F/l/CG42ro8PntvnaxrmU5QQWBB7rtrQFm3+OHM X-Received: by 2002:a17:906:22c7:: with SMTP id q7mr42165262eja.486.1609172763125; Mon, 28 Dec 2020 08:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172763; cv=none; d=google.com; s=arc-20160816; b=plN0L1EreoWwNxbsjUw89OoKxfIa7O7CKZ1Z7LbRSOtnpLngWueF8LG6SoJ4YpcJHh oF2GzXZw+2pz3SWB30zsGpSCvJvEon93pqc8Cxg0su1TC903uXznC96VCg89f8ibV5QV r7mCx0NuphaxNFoZBYG0IEMce1wtuxwOLbNqF4PrRjG6BrVnzBxgGDYSifetf+4lxsyz 8J5NwiHkOvtFtQLOuLWIy3ddImKrTI48UXh2hh9ja72MetRBV37BWysPN5YWjl2SJmrr kO0T0eNX9eVWbN9Bc+Jh9/tPVnS2A77ZjuWdAq5mlFUp61yktO3Plo//XMpKgY1/zpi9 aXNg== 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=We0rkHN9SCxI05r9zKEeg6SjXUpvnvxYt9oM8wKoQVg=; b=MCEX89IwG7fTtQcDxT7oMKq7+AMMzMXrcXDE2hNdg0dNlVFwCu3yDwNAXjoHymmuei 8i5riVGiGSQZrwSubRToSawuHYUjEOhiRNqZ1kt+rf5nCsn+TCHVa+7qbqHJhJmUGNmU Ap0WrMNtQu6jRBxYYsUVYN7ZDPvTCWpnsMrYVWXCExClA1N4dDVg648pvXZhCg0y+12F cvbz6X3YJx3ZaL/rBhgr2zX8nm/NFIsO/nS6ZyqmTHr/Q1UTYPeTYxj8BfGZ/eXbGI4P 5lhUGaolziWnYV8TOkLW3uc9rHVy36OtBwNHiCbfTwyavQf64SBpr0zUSrL6woz9/I3/ D1vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q+oLlLmW; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o24si18951098ejm.674.2020.12.28.08.25.39; Mon, 28 Dec 2020 08:26:03 -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=@linuxfoundation.org header.s=korg header.b=q+oLlLmW; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731854AbgL1QXj (ORCPT + 99 others); Mon, 28 Dec 2020 11:23:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:38716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731859AbgL1NLu (ORCPT ); Mon, 28 Dec 2020 08:11:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1BC3922AEC; Mon, 28 Dec 2020 13:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161094; bh=m7W4TKN+pz1FPn3U3CcLtI0In9PRR9pUBl7A3UEoAOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+oLlLmWOOGDnLhTSzFK7+seC2NHptnPtnzkZB+RzUHeqA3GgymwJx4IYjDaDBFpy EH0WKfDVqqwppqSE380SUkhPrn/3VAEllww+9K+R1U7KWj7Uhw/s/YutHl0+0xXn+L QhBFLZW3V0MgpUjLstw8vdGHqY45xxUZnn/SqKNM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Jander , Oleksij Rempel , Dmitry Torokhov , Sasha Levin Subject: [PATCH 4.14 098/242] Input: ads7846 - fix integer overflow on Rt calculation Date: Mon, 28 Dec 2020 13:48:23 +0100 Message-Id: <20201228124909.514419706@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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: Oleksij Rempel [ Upstream commit 820830ec918f6c3dcd77a54a1c6198ab57407916 ] In some rare cases the 32 bit Rt value will overflow if z2 and x is max, z1 is minimal value and x_plate_ohms is relatively high (for example 800 ohm). This would happen on some screen age with low pressure. There are two possible fixes: - make Rt 64bit - reorder calculation to avoid overflow The second variant seems to be preferable, since 64 bit calculation on 32 bit system is a bit more expensive. Fixes: ffa458c1bd9b6f653008d450f337602f3d52a646 ("spi: ads7846 driver") Co-developed-by: David Jander Signed-off-by: David Jander Signed-off-by: Oleksij Rempel Link: https://lore.kernel.org/r/20201113112240.1360-1-o.rempel@pengutronix.de Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/touchscreen/ads7846.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 0fbad337e45a3..7ce0eedaa0e5e 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -801,10 +801,11 @@ static void ads7846_report_state(struct ads7846 *ts) /* compute touch pressure resistance using equation #2 */ Rt = z2; Rt -= z1; - Rt *= x; Rt *= ts->x_plate_ohms; + Rt = DIV_ROUND_CLOSEST(Rt, 16); + Rt *= x; Rt /= z1; - Rt = (Rt + 2047) >> 12; + Rt = DIV_ROUND_CLOSEST(Rt, 256); } else { Rt = 0; } -- 2.27.0