Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp658013pxj; Tue, 18 May 2021 11:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzutx5gpbwf0hx/Rq21c3VFrYaTtTU9T4BqYW6ho+RrRO1Q+MndQ0HabUMJDToQHPw2dtxy X-Received: by 2002:a05:6638:44b:: with SMTP id r11mr5377343jap.85.1621361464787; Tue, 18 May 2021 11:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621361464; cv=none; d=google.com; s=arc-20160816; b=x5DTRU9+eX/f1HQpBSbK5TiTyKj/IlEcfUXHFzUIJ5RMDM/l1dClAgrHKzOql98jUO Bctb7wlj9Op/JYnvbxxau0ExryUdV0p4i+/+KZDh2oiwUQEX17Lukv3vmORaiQnRw7xq j65sFCwc4A4ihWhgfFO3yf0XQXpWkTwXKZiFd8FCh50UICPAjR2kVv8Mjp4ROQB9wiZ9 0RMBWga/RgIsXe/HF6RPtAzHgyK6gNFiZOAWLWHO32bIakuBA4CElq/d2O7CypqaMqyG G6SILdWD869myCT2M9X3V5YHUwT3bOWzwQBUCWc/3qrpRZKiYkGfklaLTOOb+vCsgpFc iZog== 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=badkwFWdrCSaHuWC9oL4YmqnM7Iucv/V6uDcHavkFZL71D96ptxhDNG1OVAqtkgQzx LrNYv5Ur1yefjUJKumGGYo50wCp8vk10fP4ZHQ8F4gnVWGkNc7MpmZg+eP3CaRNqlDZX MlGuaJr82/Euj2b1QRJRHz1eW+2b5UlDJ1e8N7hKpUiRA+zCBEB9mZrLgzraIRI5bq6W PDj1CpAJb9oJiDFF2kQrn1AxZpvpVXQHB2GXCWUyTfEj8KJJe9POYi0I+w1JDEqAowGm YFEYOdcrcABE+aS1aEY13eVlNroXZLyk9DmupPAT5YRyutBBQQy4PQNJy+hQMjj6vTm+ vz7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LiYS8zUt; 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 q14si22363403ilg.14.2021.05.18.11.10.52; Tue, 18 May 2021 11:11:04 -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=LiYS8zUt; 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 S1347050AbhEQQK4 (ORCPT + 99 others); Mon, 17 May 2021 12:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:36360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244030AbhEQPqZ (ORCPT ); Mon, 17 May 2021 11:46:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6FD3961959; Mon, 17 May 2021 14:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262665; bh=5a0i6618Sf3aj//L1ZmO2dcxrnJP/ZYs+X1dx/dkXyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LiYS8zUtsi5gj+CtAV2YIU2XpMDhLstAmeIwOpIVGkjzU3iKHLKQcckK7I8XV+RUX C4jH+6Oz7fE7g54LpngMKsgSEBh7JZP9IIM2qgbMFZPyG9CehhjTGSJQoM3z6oWO9o IP61veVswFkBlXS6PESX2x811JaDmg4HvnoCA7WI= 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.10 253/289] iio: tsl2583: Fix division by a zero lux_val Date: Mon, 17 May 2021 16:02:58 +0200 Message-Id: <20210517140313.665186116@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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)) {