Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3031148pxb; Mon, 18 Oct 2021 06:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7/H96WHKiRvse/ygvilnWFmEVNZ9qdLCM18R8/DH6IYePIRK5+iqfq8uYB1lE20No43z/ X-Received: by 2002:a17:902:8d8b:b0:138:e09d:d901 with SMTP id v11-20020a1709028d8b00b00138e09dd901mr27892090plo.34.1634565515718; Mon, 18 Oct 2021 06:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565515; cv=none; d=google.com; s=arc-20160816; b=SuJ7xJNEeVCL4YdnnD8U3fCd9q2R4jAzY+tPG/gwjCSw2FzYIQNk63sAawJny4NLk0 L81fp0h81Tzt+U5zT5WClrGjesjN5TnYGa24/Qbm2Rxa8ggItZK23waHUoMhsNucAZPn MdyPQO6y+itLQnqADadkvsEEFo6KxEx+HO/wCyum37bDWzNMBTxn9DKypLy7Hxs1hMME fO6wIDIwVvpHQtHeJjtFUou5Ox7aJTjvDLounXsdEPKrS8PtYYluXf9huHt+Pb/9VjZJ 0GEiM5cNu7z5XnE4gZIVbo12Hw4O53leqnfvbSTZdi96hVqDznsBwIX/rW25+r6DIzuo wocA== 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=RmxIy14pqbBv/07F+mJrjocf+HNF6IztYuoAFZ0dZpE=; b=WXht8BrnGsFQcz9JvZKCb4el7iEcAZTe7CLKM5Q4eWKhx2Tt4BP1jB0e2CxU6/9+8R UPkAd9gUqUn4dfDPdUGJYo5YogIl9b1wiYPnE5omBUxp0Kh2hOuhrBNC9C/v/yAD8Qgs PmcwTApC5y/93R/gpb4tpVfR7petymPGndjvLoCqEsDytmsX6adv/axlzA58esFZIGf9 PgXICRQfu5kIwoYPADWsKI9slcQo2eOIcXy/gSpFDJUISwQR1fVL44nAmB4DiJZmskDL xN4tT3eV06VkOseXUULo72b/tUKdku6DGxKuuGOFqIH9ZY0QeH5dxB37rK3MxmDLlbMG LI7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AqvlK5oF; 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 185si19570502pgj.514.2021.10.18.06.58.18; Mon, 18 Oct 2021 06:58: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=@linuxfoundation.org header.s=korg header.b=AqvlK5oF; 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 S234313AbhJRN5z (ORCPT + 99 others); Mon, 18 Oct 2021 09:57:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:58170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234379AbhJRNzz (ORCPT ); Mon, 18 Oct 2021 09:55:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7116161A09; Mon, 18 Oct 2021 13:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564413; bh=kwp69nCicNMGTGijpilK/aeFbRLe8dLyuEcvNpJsi54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AqvlK5oFA5yOEB/LXCY4Q1LF17OQr3YcCoMghYWyQc9KZ/yUxTDBugr9vYOnMs8q7 Uaz8/wb7wfu6nqoAR/fbQpiULYxHDZHmJn1vz6eMzjeLFJcs5bOGRuTdn3GQNY1/3t 7MPtpWFr7nWf/5O4pGQXjwG9RwTfTPAElmT2M10E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Dmitry Torokhov Subject: [PATCH 5.14 081/151] Input: resistive-adc-touch - fix division by zero error on z1 == 0 Date: Mon, 18 Oct 2021 15:24:20 +0200 Message-Id: <20211018132343.325869282@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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 commit fe0a7e3d012738b0034b3c97ddb0e8bc0a3ff0e6 upstream. For proper pressure calculation we need at least x and z1 to be non zero. Even worse, in case z1 we may run in to division by zero error. Fixes: 60b7db914ddd ("Input: resistive-adc-touch - rework mapping of channels") Signed-off-by: Oleksij Rempel Link: https://lore.kernel.org/r/20211007095727.29579-1-o.rempel@pengutronix.de Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/touchscreen/resistive-adc-touch.c | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) --- a/drivers/input/touchscreen/resistive-adc-touch.c +++ b/drivers/input/touchscreen/resistive-adc-touch.c @@ -71,19 +71,22 @@ static int grts_cb(const void *data, voi unsigned int z2 = touch_info[st->ch_map[GRTS_CH_Z2]]; unsigned int Rt; - Rt = z2; - Rt -= z1; - Rt *= st->x_plate_ohms; - Rt = DIV_ROUND_CLOSEST(Rt, 16); - Rt *= x; - Rt /= z1; - Rt = DIV_ROUND_CLOSEST(Rt, 256); - /* - * On increased pressure the resistance (Rt) is decreasing - * so, convert values to make it looks as real pressure. - */ - if (Rt < GRTS_DEFAULT_PRESSURE_MAX) - press = GRTS_DEFAULT_PRESSURE_MAX - Rt; + if (likely(x && z1)) { + Rt = z2; + Rt -= z1; + Rt *= st->x_plate_ohms; + Rt = DIV_ROUND_CLOSEST(Rt, 16); + Rt *= x; + Rt /= z1; + Rt = DIV_ROUND_CLOSEST(Rt, 256); + /* + * On increased pressure the resistance (Rt) is + * decreasing so, convert values to make it looks as + * real pressure. + */ + if (Rt < GRTS_DEFAULT_PRESSURE_MAX) + press = GRTS_DEFAULT_PRESSURE_MAX - Rt; + } } if ((!x && !y) || (st->pressure && (press < st->pressure_min))) {