Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp465398pxj; Thu, 20 May 2021 13:37:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlvLrdnGDc+fLSQOFUjM/2oDq6iCqGnwK5HPtAEt32iK4uy9X7JAWGQ7m8AnfoPvBnHQ95 X-Received: by 2002:a05:6e02:1c87:: with SMTP id w7mr7848769ill.25.1621543032393; Thu, 20 May 2021 13:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621543032; cv=none; d=google.com; s=arc-20160816; b=LNZuNsz8Ahnki6F35uAP7WQ8SIV3QMiwenmDjzWn2DnYsLjW8huJC+VsMO9Exef6bX /npOSdgZK4709ld77yPiEJ+q4GCwa9LtAsmFq22oYcsah+2XVkDXw+JkdGpMmfS8Gth2 z0TkX/AHKiV+/ly/Eu9iXZqf0c+tJ/YTNwwl9aRsg1LRn2QWcjrn2qFC34DDV2FBn/+/ 5SBEIERdvOmcFy3YzU0n0aTlfBFgT3ceP9FzpWixT3eZeBQtZJsd1I9tZC15A/JdMu1a cglRCyX0nNNC06S49fs1P2rVbFQXU2XucSA9/+k38n95vbQngLoePtWGJeL1TjtRFEf3 WiUQ== 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=x/sH2xeX0hoRWMJeUcEEIGqy/toFv5E/A2v7Bb5MQgCFA2n3BgXBQ+VU+eu1RBJgAq PR3eQ979QEqYywXt05iaRjTomRRkjEdVmekBxG8tZIz3VDOnUoC3/NsWgbvMpfTYEGwq D+7XIxW0b8N8sQ9USuofLVSi2woI8J0T2PpByC97exhPXTpHb7lwkGLZaXhB5eZbvaHW Lru6FCh17nRkUdWQKFT6w44QA3+UpAdVL+t8tRS4EQ+PBMv5atAZER2SiwcMl8ouEQRG cgv0V1g5MkUZXBReH6toKxpsz1VNxSzcbwtd05Ov1EglquclC+5kWgg7eIH+ZQB7lao+ q0ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qjumzUsZ; 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 w17si1353396jad.108.2021.05.20.13.36.59; Thu, 20 May 2021 13:37: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=qjumzUsZ; 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 S238472AbhETK4A (ORCPT + 99 others); Thu, 20 May 2021 06:56:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236894AbhETKkV (ORCPT ); Thu, 20 May 2021 06:40:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45B2C61C73; Thu, 20 May 2021 09:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504536; bh=bQBx1hhluqrEMh1n0EnQiGV0SX8Qp78t/8mKyq5dujU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjumzUsZxaqpzxWVGgj6diLMHRyjM8mzO5DDi1dZrpnWvZR2fkku1BxgfJjFIVRH5 r84rQ1X6MotHgDg5Surm1i8w55mADXQeSH3aD/wEzbuUece8948xM+8lZpVxJuL9GR IbHuRqBySv56hB7YeC7mMMogfp4bs5/hijxLUWKM= 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.14 291/323] iio: tsl2583: Fix division by a zero lux_val Date: Thu, 20 May 2021 11:23:03 +0200 Message-Id: <20210520092130.183745673@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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)) {