Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9183255pxu; Mon, 28 Dec 2020 08:39:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLVshYXd/Exw2XnqG5cDdtwz23JEg0m+UpUKXXibfvjEZF2ETzgH/N6DgBrnAa34mFq4yh X-Received: by 2002:aa7:c884:: with SMTP id p4mr42202630eds.72.1609173577268; Mon, 28 Dec 2020 08:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173577; cv=none; d=google.com; s=arc-20160816; b=bY7JxUv2koD35XptsOT1mrLMrx8Ipeke5DqIaAWFOXM8iN29tyV/TnJgrOGqc3amq8 IpCrnSM98ofMgxwtUAAtxrmQh4RSPjufYm3fRI+emlFWb/2lD0mU82glrCNvt5XjJ30R FopQlvoQz1Vg9HCJYhJTINgDFFdGk/j/e+5FdjUDQ8+CHIuSt7JkO59u/Uob4AJP0uhu Gk+ZTp4pKopaXrxsLymvKGoYzge+6e25ZnFAFOR6/ED67O4n+JwSK0X8k2JY+kBQ3XYc 62CnwprXLWXU+UcxXn4lFQv8xXfYbSU5+VQGd6A4HJ2KcJNrgBcfk0tszzfQK0mv63bR cEow== 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=YD6mesOSLCUW9Xkg9dsfGCRxNJnPT7GkcsTPjYIk5KY=; b=sfJx+izHnfsTJgPw6htfSGL4pYg79PPvip5APkeFPRPZYAdqrj+0CjAiVBNrWwgr4N D0OmxFyoi0gwFch2eMCjQ7HzUJWI/JUb8Zhnla5/LBR7X2/qIGLg8hftG+rDfNudBiCO r2YDIV7tLY+bqtV4e0tvxnPEwm4Nynhff+drfkGZP/8oWCdnrqETe17vje/KlKDx21xQ mK4k6y86isazjYxnsv8g/3v1tUkoYOB4OFLU9FBy8L32atDH9fU8ueWo5IsEs3+lssHt VPGXofJyRvJiwk3/pwrhGej9rMxV8mEdKmvHjDFaZb7z8mA8nn3OfPsqWuHq/gdzmQvX avdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P9IVEqvs; 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 s13si18505094ejv.28.2020.12.28.08.39.14; Mon, 28 Dec 2020 08:39:37 -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=P9IVEqvs; 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 S1733209AbgL1QfL (ORCPT + 99 others); Mon, 28 Dec 2020 11:35:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:58340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729983AbgL1NCJ (ORCPT ); Mon, 28 Dec 2020 08:02:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC66122A84; Mon, 28 Dec 2020 13:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160488; bh=nC/iBTq0QSCs/EILL/SEj0NV8zZLZTO1hUte7u7+n3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9IVEqvsv92Mvo4Ad7YIHupr2qpoBt6r5bnga9b+Rgk2foeiSJw49rRqN70Jqf8IC YpM/u2etM+kBBdRFHJ1aKls5A8WURO71pLLPE0ahrm9bmUDZe3s0F46m0cMDSYIBKF BmVtCqnmU8AFVvQL/QVhJaK3v689wGb3yU9Vmi30= 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.9 069/175] Input: ads7846 - fix integer overflow on Rt calculation Date: Mon, 28 Dec 2020 13:48:42 +0100 Message-Id: <20201228124856.595791689@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 1ce3ecbe37f89..9fa7ae12df80a 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -785,10 +785,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