Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp394782pxj; Thu, 20 May 2021 11:48:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCN974Wt8hgfM9w71YBseXZX+KQWupws2hSxmojSSzczuLmiL6OvVSwtxLuOBLfVC6niu4 X-Received: by 2002:aa7:c782:: with SMTP id n2mr6550866eds.77.1621536492876; Thu, 20 May 2021 11:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621536492; cv=none; d=google.com; s=arc-20160816; b=bjpMpmIyFRJNf8KeCbQIXViyigC378GSxnqhNOmT1hENMLl4BN1x6XK3ZwXCpM1n2E S7gcZNLmFkE8/C6mAm95janmoC0met4lbgL2q7lEPWQXy7nNkS5c/jtQA0SIzu8TahI0 P5H6wQvLpEUHX5WZUzECE++ZTFnykpk7QH8NFaDZCbztuEeTiiyUFP23U+Gsje3fhVXH oKMh2B05v1r3aTDhfhIKrZ+XuRseAyNSj9bhok2bdQXdSEU7ZIYUFdN69rssCkq5FvGC WseVfZhmW63GoWKCfkk1AMgK4s+5b57WSfVBSeZ+vDfux4IWYkbt3xU0XQa4HTTzmThG bTwA== 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=0Yxxanhtm8V37u6I2roow+CwlamT8wc4z/TpYXkg5zU=; b=Cy1rgsgxstpXubVd9KeuASks/kl4fD4g6gUTC98spcDPYJPcN+CI0YIUTczoNd7yPq QVVNC+UloL/7m1UkWpm6XBuS0Y8E2ud1a6YpXHNG+RbvfwBNQ5rh8Jk1Bw05UuEjuD2Y k1YVY31EVMJvX6CdndPgcUqMr9zHjtFo8Ccmxt0fIuaZFXOWOOcbPY4sjs5CzMQ56I1W tvdHXx19UCijwJ1DMNJfyLtGZBHxLvAby6wnNCecRe2Nzy6YhiVGBaK5MSYu1IoD4/4q /86OX5arB4iB6ozUD41JVQkIFVitTGiyB4sriNMt2KVzGHXXQdTf2eTY/BCx/frzDXWw OIRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c+qnGTsN; 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 a9si904676ejc.442.2021.05.20.11.47.49; Thu, 20 May 2021 11:48:12 -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=c+qnGTsN; 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 S235862AbhETKVD (ORCPT + 99 others); Thu, 20 May 2021 06:21:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:42256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235282AbhETKKw (ORCPT ); Thu, 20 May 2021 06:10:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CBF461960; Thu, 20 May 2021 09:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503791; bh=bQBx1hhluqrEMh1n0EnQiGV0SX8Qp78t/8mKyq5dujU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+qnGTsNJm9UJLWWX75DyJE9QJN5fHuiJ9mbvNKOjIN2Ejpd/4xf3qJbnHRXoD3Vu 9qlpoVRca27OhZKyLMcqSiH6fFDx9qROudJI2a/uHHYpDqFko5P7tpk2fO4GQPw3To QNKMtCCL+fRV7cEP3L2s0dmWCCPTcAUcs5xP7eSA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.19 382/425] iio: tsl2583: Fix division by a zero lux_val Date: Thu, 20 May 2021 11:22:31 +0200 Message-Id: <20210520092143.956362038@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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: Colin Ian King commit af0e1871d79cfbb91f732d2c6fa7558e45c31038 upstream. The lux_val returned from tsl2583_get_lux can potentially be zero, so check for this to avoid a division by zero and an overflowed gain_trim_val. Fixes clang scan-build warning: drivers/iio/light/tsl2583.c:345:40: warning: Either the condition 'lux_val<0' is redundant or there is division by zero at line 345. [zerodivcond] Fixes: ac4f6eee8fe8 ("staging: iio: TAOS tsl258x: Device driver") Signed-off-by: Colin Ian King Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/light/tsl2583.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/iio/light/tsl2583.c +++ b/drivers/iio/light/tsl2583.c @@ -350,6 +350,14 @@ static int tsl2583_als_calibrate(struct return lux_val; } + /* Avoid division by zero of lux_value later on */ + if (lux_val == 0) { + dev_err(&chip->client->dev, + "%s: lux_val of 0 will produce out of range trim_value\n", + __func__); + return -ENODATA; + } + gain_trim_val = (unsigned int)(((chip->als_settings.als_cal_target) * chip->als_settings.als_gain_trim) / lux_val); if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {