From patchwork Sun Aug 9 16:32:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 11706747 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0023D618 for ; Sun, 9 Aug 2020 16:34:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCC552067C for ; Sun, 9 Aug 2020 16:34:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mIbNJp2C"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R9VKXGeY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCC552067C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=IfOT5p/apqikOuRWpj1I7QblcBpEbeDeoyDHtY6J7yM=; b=mIbNJp2CDlhy0eLxpi+Z9bNxfo dtK1F4PnIVuE1nxAshZcaLx6fKGb0kBOnthLEkne7TSuijfyMnAGRyDi9oshGNEYVsCVmBevzeHS/ 8yww4mRy+R+1VKyCeYUdEahaVpOLmKSd2YNtvSYXfgTq/BQ81vrHLK3pD4nTjhmlTzPi/zZfzlQUt CHQQuEa5lIVYCI4AKpxBX0OTgpX4WeAHutS+CMMtV4QszBZRxbRrnEIJf+eu5FmPKY63dtcGulJyk yhYif8910MrsjHCPGUaMNNUexUat2PZapsM+n4mVzOwaPbe/CUk7eNmLo9qmahyV9MAuXL/INB0wh vjUr4+eg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4oFN-00020A-S9; Sun, 09 Aug 2020 16:32:33 +0000 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4oFL-0001zU-IP for linux-arm-kernel@lists.infradead.org; Sun, 09 Aug 2020 16:32:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596990749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type; bh=PsMQY7jSXY4+oAbixnAnftAfol98FgMKGuspJ+Q9XFk=; b=R9VKXGeY/guwbHF5eVAYMoxHVp2ft8yXvPzC6WSrdkPoZjppMz2ImYrBUWfzH9GQyjLqVG dW38XrKmiyeKl+59AyFzsuG3BpUmsLR392vjDzvJvT5T0yxElzR1G2dKi/G4mpK2NqiA9G IfdmTGRNRxECVj+mWESl7dUV+E04574= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-123-14SAH-T2NdqWM2Od3QSUdw-1; Sun, 09 Aug 2020 12:32:28 -0400 X-MC-Unique: 14SAH-T2NdqWM2Od3QSUdw-1 Received: by mail-qv1-f69.google.com with SMTP id k17so5658080qvj.12 for ; Sun, 09 Aug 2020 09:32:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PsMQY7jSXY4+oAbixnAnftAfol98FgMKGuspJ+Q9XFk=; b=Z5g+bMY8b74vTcGTUGMpcr6NE0aFlvkgu6/EL7MuO2pL+omsuS6deUWV/rvQjCdxe7 455m2qua4ZX2s1LnpvB7eYIKMLQHYN2EZJ6ps7QWzL72INaTJQqNCIPIas6GGz58lkIU wzP/nEW37nh7Mzfv0g94YiyzPRitnpzIP3miEnW9XN47wWMtqsalRLEoYdxdS9GJLWWv aiNubPL2uFOayWZ0kzo9rAdkzP2ggPdDh81sBn2ZYNOzEmy5qxB4M4LXolK5EORGm8Mz 4yksDDppN+5j3dFQL3yXg3BcqJrwZjrvWC2PEGIBhV9EOL7sdG4oSyE5b66XYhjZ/iAw mRqw== X-Gm-Message-State: AOAM533yr+5mwzXxQirCUCHNxiYmUtuZVocJc+uwx0KhTvlg15bSfWSO gaBLq/zun4GLnjZzR/ifHfXWtrg4j//aG7FXnoXJAKq1sz3qnBu3m3mbge+jM9q8P2Qh6lQV+lV 4YuZ2w+N9LV70clhKWgrf4UVwd7AN9pSWf/M= X-Received: by 2002:a05:6214:290:: with SMTP id l16mr24599893qvv.187.1596990747394; Sun, 09 Aug 2020 09:32:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxma2GBDDu2oNvsxHZ9yvLuxWvPbRyHyBBHUXJQyxP4tzEslX0cuIqMV03P+K7mAvDDQKZmWw== X-Received: by 2002:a05:6214:290:: with SMTP id l16mr24599873qvv.187.1596990747159; Sun, 09 Aug 2020 09:32:27 -0700 (PDT) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id y3sm8304604qkd.132.2020.08.09.09.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 09:32:26 -0700 (PDT) From: trix@redhat.com To: sean.wang@mediatek.com, pavel@ucw.cz, dmurphy@ti.com, matthias.bgg@gmail.com, jacek.anaszewski@gmail.com Subject: [PATCH] leds: mt6323: move period calculation Date: Sun, 9 Aug 2020 09:32:21 -0700 Message-Id: <20200809163221.32413-1-trix@redhat.com> X-Mailer: git-send-email 2.18.1 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=trix@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200809_123231_672238_6948C39E X-CRM114-Status: GOOD ( 14.01 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [207.211.31.120 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [207.211.31.120 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rix , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Tom Rix clang static analysis reports this problem leds-mt6323.c:275:12: warning: Division by zero duty_hw = MT6323_CAL_HW_DUTY(*delay_on, period); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is because period can be 0. period = *delay_on + *delay_off; There is a later check that *delay_on/off are valid. if (!*delay_on && !*delay_off) { *delay_on = 500; *delay_off = 500; } Setting the delay_on/off means period needs to be recalculated anyway. So move the period statements after this check. Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC") Signed-off-by: Tom Rix --- drivers/leds/leds-mt6323.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c index 2a13e3161bf4..7b240771e45b 100644 --- a/drivers/leds/leds-mt6323.c +++ b/drivers/leds/leds-mt6323.c @@ -248,15 +248,6 @@ static int mt6323_led_set_blink(struct led_classdev *cdev, u8 duty_hw; int ret; - /* - * Units are in ms, if over the hardware able - * to support, fallback into software blink - */ - period = *delay_on + *delay_off; - - if (period > MT6323_MAX_PERIOD) - return -EINVAL; - /* * LED subsystem requires a default user * friendly blink pattern for the LED so using @@ -268,6 +259,15 @@ static int mt6323_led_set_blink(struct led_classdev *cdev, *delay_off = 500; } + /* + * Units are in ms, if over the hardware able + * to support, fallback into software blink + */ + period = *delay_on + *delay_off; + + if (period > MT6323_MAX_PERIOD) + return -EINVAL; + /* * Calculate duty_hw based on the percentage of period during * which the led is ON.