Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3526249pxj; Mon, 24 May 2021 08:40:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnW8TdeK5JuR1X0AZ2UbMtsCjGutUGWbQnijixXjI9OWiDV6LFAK6mli0tUAKRlYmkF9Em X-Received: by 2002:a02:cb04:: with SMTP id j4mr25181029jap.45.1621870816544; Mon, 24 May 2021 08:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621870816; cv=none; d=google.com; s=arc-20160816; b=1Fn0EArHjdkqxuXw6sYHsL3LjjKujjf/Y2LcNwBbvH4BchB6YNh1HwyG/35iaC2iAo sqJDEc4+ggcdIlXrp5PQG4Bhbo1PffwjdUPD+9AMTu7TYVHJUC1r62ljCtoT+8RqoKpu NqvjsZ8ipE6SSqIOgQoY/5BP7aNxXydeeaSkCVln33EAF0bK7soeW3UKjYx/2JSqffGZ wM8+g161qZOl84lht5/BWLK7KYvfA5PkmS/dAJxWbUGD4jfSnceQggxr0yofJxgqrLw2 ujyOM2CfVY+3v1IvkfEENW57exyISvEMoNChjRgeyHFqkSKptiaijuDstr3YZKSJ6G+c r5vA== 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=QpTP/5tlCOzktrG5+n2xA8bRCIzDC/BsXnzcB7K5M84=; b=S7ywNDgjcvseo7GVNTqZHemFPSBkmoIZGLYLS6ey/z+sh+kh76yr8ti0SG2Nwcu1Bo 8p+j9qnwepIHTAF48YY3Tl4EvONVZcO18DVGHRc5f4I13h2sen6C9g/J13JTlKXio5Fa qZQNTl0d4hyB1BdX7P8bbPfGX5pOCTsvIwJbjBR9aRq6NrR3S9Mnabq8bswhJaIuK2Pw xdFoUQRrDC/EPLABjF1H/yKzpdtWZVoxsmCfIt8Cq9d3+yYnO3/FiDgDUI8KfV2nsPMv 74oxFPszaj7jKJertDkV9p+FlCMGOA8B57tzbttXC69nH7GrcgKCgaRAXwF/dApD0g2d DGEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z7sBZnXa; 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 m12si14404231jav.104.2021.05.24.08.40.03; Mon, 24 May 2021 08:40:16 -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=z7sBZnXa; 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 S234206AbhEXPjL (ORCPT + 99 others); Mon, 24 May 2021 11:39:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233892AbhEXPgX (ORCPT ); Mon, 24 May 2021 11:36:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9CFA461414; Mon, 24 May 2021 15:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870362; bh=mbTBEpLuOGOSt73j/DVn5yuJombL/qCnen1JDX7faB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z7sBZnXaguojsLziOD2NaxL99V53qxi2pBlGmqFyK2rCQs3f687i7m/s6xhw3715x LHqMftHmY4oN6mYx1gDUnL56Gua0cmPUm0eR/DY0UZyTYo2Yqh0MzaqLvdIv0eRM1N qXDBLjhw5Ef/Eh1R1R+FPiaT1GJkqvMVgfDcRl/Y= 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 , Nobuhiro Iwamatsu Subject: [PATCH 4.9 36/36] iio: tsl2583: Fix division by a zero lux_val Date: Mon, 24 May 2021 17:25:21 +0200 Message-Id: <20210524152325.329346979@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.158146731@linuxfoundation.org> References: <20210524152324.158146731@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 [Colin Ian King: minor context adjustments for 4.9.y] Signed-off-by: Nobuhiro Iwamatsu Signed-off-by: Greg Kroah-Hartman --- drivers/staging/iio/light/tsl2583.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/staging/iio/light/tsl2583.c +++ b/drivers/staging/iio/light/tsl2583.c @@ -382,6 +382,15 @@ static int taos_als_calibrate(struct iio dev_err(&chip->client->dev, "taos_als_calibrate failed to get lux\n"); 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->taos_settings.als_cal_target) * chip->taos_settings.als_gain_trim) / lux_val);