Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9489301pxu; Mon, 28 Dec 2020 18:27:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlvuk3wCffuEi3xQQ8Xg5JJ4NWPQDYZFSBbDB+OTgpADgPYMPTRTGiJgFNIhkxqL2C5G+z X-Received: by 2002:a17:906:d8a3:: with SMTP id qc3mr44118963ejb.443.1609208877146; Mon, 28 Dec 2020 18:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609208877; cv=none; d=google.com; s=arc-20160816; b=tvoep5ZS6u9v5CvoULYkZSz0AqkFMKpjcgB6WMMOsL2dpz9YPotdDtCNOYAJm2iEOm dfJ6ASMl9qRRuAwWT+ub5lBixH+zxQey0JWRCTU/NizwkcDYM2PdAGT5Rj9ttyfQPPwq kSRrns7ly1iJWqeoCwY07PDnkLSSUfB06nZkMXgG7fUg/ZfPStOua2vCYh2mEyXAiNKP Jg42uOYIJB0mxaIYi3aXvqBrycZVCB1o8pCyuwQgHsDtfKOICPdzjpZG3g/szCkdXb1/ 3DOeJg1PShSPln8CgYGBfW2/zdRMvocx5Bxq7XUQV76OYMdyrbl69lbZRk0n3SrgcyZ2 Rr3A== 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=IDlX6cvZlkCoGE6ewCxEME483jqZuhg7KDLAo+V6cDs=; b=Z0jTFbmXzEHQb2UMB+asyB97CFX0MU3Ksq6UThbVXUfkTluvGlbrwZg8VDcpG8Uv0a pLf4wxXzgFs+Va/0pu6iIfU23l/rCgTRQdSnOS6OpyN+Iih9dJ2oF1uOBWu0nHa+S762 vZdUWomAtmEsY5U97XNkNVew1mttbblLAUJemI3WZdV7UD/jRAz1A2vpPKtcCs8FAfpT Ca6mAaSrUfgTluZDZbJ78z3J8pMRX8t9zMRyjSSL07EKZxngAtbydxwoG76UkRq0gpBt SG8TI402roY0l2FweNisnomPuFvncPPZaIm6rT/1m0vk/YYZX8J4cxXTsWoylmIu/tZz afkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nYk+XMZ2; 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 ot14si19173318ejb.493.2020.12.28.18.27.35; Mon, 28 Dec 2020 18:27:57 -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=nYk+XMZ2; 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 S2438567AbgL1OIB (ORCPT + 99 others); Mon, 28 Dec 2020 09:08:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:42334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438545AbgL1OHz (ORCPT ); Mon, 28 Dec 2020 09:07:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 408CE20731; Mon, 28 Dec 2020 14:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164432; bh=hs3e2zPi1RaqwgroejTdVMzBsqV1hwk0x5DiuiTIvPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYk+XMZ2KKNMkSQ0dxbi+ZdYPIR0LlvjO/Yef/gdzkpnjZEdJyzZFrvub2mOSEWQs hdjiQWepTjtgTB6lc/WAloJPk072Ai6VCSBZDWt5UXpo+u55IXNdD1JLkI9SrJgWXK +lXzwXn8MU25PIDC5wPkT8I9rNC3gXM539Zg1xFI= 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 5.10 148/717] Input: ads7846 - fix integer overflow on Rt calculation Date: Mon, 28 Dec 2020 13:42:26 +0100 Message-Id: <20201228125028.053390822@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 69992d5e53118..78ed285c27ae3 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -802,10 +802,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