Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp628416pxj; Thu, 20 May 2021 18:21:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuJ9by0PnPrWS5XwrnjgiYbOoy80OAkkoop4Wawix8M+FJ/+yuCBqnA2BB4Fqh0MLJAfPF X-Received: by 2002:a50:ed13:: with SMTP id j19mr7994623eds.190.1621560092670; Thu, 20 May 2021 18:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621560092; cv=none; d=google.com; s=arc-20160816; b=Z3teF/IkvLUeuKkqfVFrd7dPLl3S8QUDMIm00TTEnRPRO5VJGN7Ak0+HM+8+cY4apK LA08Qt5u/pyV162geA8bsOMq2IuRhOwt0OscNeOR6hgIAp8EEpL+ooG1/IMQJJvGUVKg 3s6ObNWTPP58Otfr2GeGnj8dePyyB10bWA/A9fVQYinsow0eDPl8uk82J8JcS42gE2eM +zQr7npQ97x98sk9nKtAa9cMECQJF7fZrb4ZCo/kICO9c/FiyHdhZB3yNzGdDjvT8JI9 3VrB7Gl/4xHfF4W0+4umKampwZ4yNTqIEYA6p2jK4bN7Bbg56GK9avYxcP6U097X3BJf C1Gw== 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=sQLdGG7L7UyQNsdjM4qLw7bFMJOfMOXXQRL3S8BSrWc=; b=QP8ScIGpuqESrMX+6wHLv6GbapupDGPXQ3d7rp2r5+uXkT2NRzA9XGKrYWMo0V1tAf 8R0BzE3/v/AQWE5EC2XTupfMlkRkTiPbUZAu20XcL4CfU5Y8YzqrSaIy+heiBbyc/O+7 HzetK5vnuJUp0EIypgmYFRdb+vIG3leIRI3g3g2uLZptqt26Jv8aq8sqXljHzh3HQb4V 7vLtwlH77xjCuREL9EnbF5UUo4w3gih0hkicQW+e1V+EWdpuIAP+FfKgL7jC2ZQyVFQC 3/HdOaouHyUnJ5asoWhbizjf41Yqfr8c6VwZ2B0bR7YfakIrMu/D6UzlWwfL3QYzKTYD PtAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QdTPn6HN; 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 h25si4054710eja.400.2021.05.20.18.21.08; Thu, 20 May 2021 18:21:32 -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=QdTPn6HN; 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 S242545AbhETLrX (ORCPT + 99 others); Thu, 20 May 2021 07:47:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:44410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241656AbhETLZR (ORCPT ); Thu, 20 May 2021 07:25:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CB0DC61DA1; Thu, 20 May 2021 10:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505575; bh=YpRFGTAE4g5Za+BUms+4PFtNjTmWeJ/ILzmlQjeRLlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QdTPn6HNFE74W0nnU4Cr6Fvh70tNL+984HkNArhEBv5K6dwjBGJoGXsPobqRM8AO3 UggqJ62YC5qNeLT19YYJWgLWkbeoODNMG6Hiz3BieAkmwhh63sOsj+C+qqYKVpLPnx cYSKRtHdqrHI6MLerKYFie57SR41kJAPTCh1nxyE= 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.4 190/190] iio: tsl2583: Fix division by a zero lux_val Date: Thu, 20 May 2021 11:24:14 +0200 Message-Id: <20210520092108.447707916@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 [iwamatsu: Change file path.] 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 @@ -378,6 +378,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);