Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp153569pxj; Mon, 17 May 2021 23:43:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuJpP3bhDnefkYwSM/lLHylGoagWN5H4ZdtJQo91Gp5Ceb+rlHYvkrVXzWpP5jAXSyoD5u X-Received: by 2002:a5e:a806:: with SMTP id c6mr3005585ioa.180.1621320187798; Mon, 17 May 2021 23:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621320187; cv=none; d=google.com; s=arc-20160816; b=DDNuF1dxahf6DuzNK+s9qKf4A3a9evmKSQwDzJQhvPHnnqFOSvkSuM0ptwQJ6hYisT IDYjhd1106j8H0AuX00BikwWoyfB8WlRDNwj4qrCJl/sdMB7ovQOcvwoAq0ezKGyVa74 lUa7+vbe+vyMPSQLF8Cfv1xku2eFO68c6aHQSaZba/Cr1WUuDajjcZZz2pUh/Qhxi1l8 lOUEEU01OlXv6uRTDwSjQ8UlBRVrL+ED9J6sgBYbttKduwmxXvvKE9E6HSnOimSenc+J 5uO3nJ8UeObDKamLMJST4a2Ib056xc6+/qLuoqjW8AXw5IKJstL5ij1riUpWk0fSWn5T t2JQ== 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=/UNw7obE3YlQgSXtGfECUp2ZSGCFxElRkK97swtphiA=; b=Zbu1emumncnk/8KPKO8rxcEFvbhgVQx5UHp6cA6Q1d1+O+rsPpF4f5Pi2rY/7O9/m8 hv//6/q9DwyUr1eHnEn1h/IcBG/46iE8TY8SMmaNsmnqvgXtRW16EjPs8SwCPi1iYIv9 K9enTu9Vzdf4uzGR73Lty7rVaOVNFL1ZGCa3FVSZ/NjgTcQxO/pGL+NmZoBI04f+H7+3 3C35j89r3+/fGziLqm3XjdTqUQHg4gViaXcOGgY51Od77PR0Om76DVlWMyS/c+6suObu kk+HXLI97DeKdR0uXwkqfP4tZg1FrEUEZg8dW5CCL2hDlte0jOkoKj8MVsbho2o1Od8c v4ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vcre2LQy; 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 c22si18469152ioo.82.2021.05.17.23.42.55; Mon, 17 May 2021 23:43:07 -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=Vcre2LQy; 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 S240344AbhEQOwc (ORCPT + 99 others); Mon, 17 May 2021 10:52:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:52916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241437AbhEQOpC (ORCPT ); Mon, 17 May 2021 10:45:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F9D361962; Mon, 17 May 2021 14:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261251; bh=5a0i6618Sf3aj//L1ZmO2dcxrnJP/ZYs+X1dx/dkXyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vcre2LQy/XyhB3Tu1MRdp0w8oep6up3zCXjxx2ZeQrCZTvo9RxzBJSi6YwX7+yuWe IuulqZc0LdpZ5e5tBxIrGJdqLSICtGZjHik8o7jqVvitBdvvl7IFFm68L+e85njmW8 YUOKIR5DrZL+K3XKzamb9tloKDO7tUhGlgRu3ZjM= 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 5.12 325/363] iio: tsl2583: Fix division by a zero lux_val Date: Mon, 17 May 2021 16:03:11 +0200 Message-Id: <20210517140313.596854833@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 @@ -341,6 +341,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)) {