Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1105812pxa; Thu, 20 Aug 2020 02:37:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymr1FalXrY/QkzAj47R8VtooQzq1rgafOoJJtOCuPCaZlTdgFhLzL8M+HDvFbPYEuZUWjr X-Received: by 2002:aa7:c358:: with SMTP id j24mr1888403edr.377.1597916274936; Thu, 20 Aug 2020 02:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916274; cv=none; d=google.com; s=arc-20160816; b=LOrmAyUZREPWFGUeDuItxdZwv2aae/F6KsEhjlUCf+QWK3OqE7j6Jg164GUlkwy+rR v58+Ee9pKHHpzaw9hibGMEM8chd+Ucot5LJc40uAOF5AzFrfbocv4Gd1mZHwu3g9Z2u2 clYG+Xxlg5M1qUw9RmTQM5EL+kBR2u0JU738h4bCX1Y9I8khxktxCCcwCQPOAwDgmDTJ e/rMaQ5WIzwrRq4IzeIyRA66z1EAHeS5mwzUfyAGK0imB/vaaOCwJoaP4pUIc+Vp4oqu 1Aj71M1fLkElEDybd80hJlgLffcTRj9eAG7dnRB+7ou6V6vxMZVZsWy6YS5D/ARzJMRX R+0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IBGnKJCa6jME8NDSYOm6SdJnjtfOyuUXqTOTaJXJ7zA=; b=pqcf/p7vgqo3Hzavslso94MALCuOQwPEGF2tWDhXFU38CDUCa8FL+QtGP7mAxsPFK3 NR7lkur1yEZqt7TIX7I9euUJzPEpRRCL6vzSdv8b8xbSGhIU2+kRZbbT1dPWIeuLBKFu SLUm5EKD7VReY1ya34hK8y6LdYylBGlcdL9jsnsMbZHk/jHH0a37Mgdx44rMOLgA0Ppa DB72nNoMcR8w4A0OyUAq6XNa5oM2MVJBr2zTFfgN5/pMOg3WCozmW9vu5gjbEvZBuXyw Jmtlwnf+VstVsJxfxStqOx5zYS5ulqdXP+GHU1XJvZPK+H5iJ+YEgOPveiirnTh0aEKS UrBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Oa+ybJEc; 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=fail (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 v14si1086358edr.467.2020.08.20.02.37.31; Thu, 20 Aug 2020 02:37:54 -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=@kernel.org header.s=default header.b=Oa+ybJEc; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727914AbgHTJes (ORCPT + 99 others); Thu, 20 Aug 2020 05:34:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:42902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727845AbgHTJbY (ORCPT ); Thu, 20 Aug 2020 05:31:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D22F20724; Thu, 20 Aug 2020 09:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915884; bh=tl+cUgc5OR6puSRkQCFPVS3w587cIlAO4ks3kHm9LrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oa+ybJEcmIl0bkYMeEdYLnxg0i3o+Tvb9WTpCgI46a+KswLsd3LzZ1V2ZlZ0bpHGF AmT7XsbHvRu7aFGhJvnYQAg28h3pzsEDxEHyjL0y/L8Dx8hftLEt8oGCu5RXg1fhQ5 C0HmcOmVUUgytEx7pEoZPH01GrRREx0twpUTkjR4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rayagonda Kokatanur , Scott Branden , Ray Jui , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Thierry Reding , Sasha Levin Subject: [PATCH 5.8 169/232] pwm: bcm-iproc: handle clk_get_rate() return Date: Thu, 20 Aug 2020 11:20:20 +0200 Message-Id: <20200820091621.001700555@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rayagonda Kokatanur [ Upstream commit 6ced5ff0be8e94871ba846dfbddf69d21363f3d7 ] Handle clk_get_rate() returning 0 to avoid possible division by zero. Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller") Signed-off-by: Rayagonda Kokatanur Signed-off-by: Scott Branden Reviewed-by: Ray Jui Reviewed-by: Uwe Kleine-König Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/pwm/pwm-bcm-iproc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c index 1f829edd8ee70..d392a828fc493 100644 --- a/drivers/pwm/pwm-bcm-iproc.c +++ b/drivers/pwm/pwm-bcm-iproc.c @@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, u64 tmp, multi, rate; u32 value, prescale; - rate = clk_get_rate(ip->clk); - value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm))) @@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, else state->polarity = PWM_POLARITY_INVERSED; + rate = clk_get_rate(ip->clk); + if (rate == 0) { + state->period = 0; + state->duty_cycle = 0; + return; + } + value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); prescale &= IPROC_PWM_PRESCALE_MAX; -- 2.25.1