Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2322146ybh; Fri, 17 Jul 2020 15:29:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtxdXf7o63KKUJ0JwhAsh29R8q9Vj7hjp2kTv24Sm7xU4PJh5nN6lu2/yRaXozHbuaZFbS X-Received: by 2002:a17:906:a058:: with SMTP id bg24mr11067547ejb.370.1595024946337; Fri, 17 Jul 2020 15:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595024946; cv=none; d=google.com; s=arc-20160816; b=X+DSJTKTNfwukbQ2BIu55kV572PH7ZLlFCm8/Z3j4dYkdCP35E86aEN8NQk6WmyiUB vcaa3umph/HiKPjlSSsaxPFh7wCFhA5YnJ/bvpuOUh2WSr+nVHf7QXiQrRqjzU8tI9NF wXwqD5NA5pBWCyPb3s1xHu5E99qwv1+xrl+tjPY4a++A0pdC5yqDqOId4MB4xWon9XQZ HSyd53F7VtemrrKbSdsjnruu2Xna6zmuHwtOsVhjvNGLJk0lxxq9o/UUXZ4Kf7QkTWZc iq4uu6lJvdjXoQYCMQW1FZ4qUpzWeTZF4B3YKuYEEaAgDOaOur+KQ3K1+lNEiM8oWNUP xkwQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=EvZfM7tSlBvQupdfYs+4sQhtafmRlnSnH6RQB9/57lE=; b=TzBG6zw+iNhydu4fpLaA7A/rTLd5WSZ7L1POupX4QjFz/+fxAeNN7lbHy6HytkFDfV VipQiFTvEuHnLVeKFN3MrkJPwlcQQIRcEizTsQoh+nS4/Esalu52s4UvPU1tSwOvi7LS CVnU3JSM7KHQdtL9/bP0K01Mjg/zgKKENhSc1uQoEZP9If72kqjx3aXMtFY6oSpfKmab 00D+IpeWdEiC03xB23pt3UAKxDzx0TdsASA3lNPAIkxZBEbl7esUNyZsR0X5PNVb3yoT kSIKcTdPe3Ge/N+RBwkLRpqiMDIPzy4xMvUDehfL1tfVGG22UmDeHlLzBTyOmmU/UUCn gvsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=BALRBWDK; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lm17si5781193ejb.366.2020.07.17.15.28.28; Fri, 17 Jul 2020 15:29:06 -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=@broadcom.com header.s=google header.b=BALRBWDK; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726629AbgGQW11 (ORCPT + 99 others); Fri, 17 Jul 2020 18:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbgGQW10 (ORCPT ); Fri, 17 Jul 2020 18:27:26 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B583C0619D2 for ; Fri, 17 Jul 2020 15:27:26 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z15so12600178wrl.8 for ; Fri, 17 Jul 2020 15:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=EvZfM7tSlBvQupdfYs+4sQhtafmRlnSnH6RQB9/57lE=; b=BALRBWDK3OFtn2VmJ5nZHTR9pM51ksljccFyTBcyyX7bpgsd19EjLqCBWtl9kKUX0Y 4w8epWV9R2HFpGWlCx1dzLRDdnLdYREVQM8r6L74qPC44o8FZH2+Bc+XQEumOKfBQ7qB 8SffiaN/Prgk7fuWau8BRzfpotRm4p67pf/zw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=EvZfM7tSlBvQupdfYs+4sQhtafmRlnSnH6RQB9/57lE=; b=lILoi70H2+2YJvBZNEtgIC4stAG5ccOk9IXpzWRXApMXPpZODmJgb3ar+o2ciKmMl+ Z+gyAMOvduTiq4fd2BuAiJsdEsIbpgPc0ANlgDIMqMVlZ2nLH3BMsLx2/AC0Eg/U8y8g XDSeLJMcsNQqGlb/VneJPhIma4n+llSwQ7Nflcx9j5lyCwpdpDtMenubTKAZy1Ud8dXS W1BpSLR3Qmg5RgvqKs4Crmubscm+Qpalk7ca2IKOV9nDy3OEdq2qBMenZlw//4k1pbxC kORMY+QgYBDHPkBVzrWZz2jNrAnOKthIB6rN7E4JHpLTZBtLWBRp6I67+MJY0JXHVOqw 3Yow== X-Gm-Message-State: AOAM5336JwFhqf3SjjuGJhboNLeXhqaJIS3axMdQRCKg0u32LAx9r0A8 IiH+7sQIb5zjmC1bmfFe/aDSarUiBtK7TWh3 X-Received: by 2002:a5d:4b4f:: with SMTP id w15mr11924497wrs.84.1595024844553; Fri, 17 Jul 2020 15:27:24 -0700 (PDT) Received: from [10.230.182.181] ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id c17sm821888wrc.42.2020.07.17.15.27.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2020 15:27:23 -0700 (PDT) Subject: Re: [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return To: Scott Branden , Thierry Reding , Lee Jones Cc: =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , BCM Kernel Feedback , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Rayagonda Kokatanur References: <20200717182512.26001-1-scott.branden@broadcom.com> From: Ray Jui Message-ID: Date: Fri, 17 Jul 2020 15:27:19 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200717182512.26001-1-scott.branden@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/17/2020 11:25 AM, Scott Branden wrote: > From: Rayagonda Kokatanur > > Handle clk_get_rate() returning <= 0 condition 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 > > --- > Changes from v1: ensure 'polarity' and 'enabled' are populated > when clk_get_rate is 0. > --- > 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 1f829edd8ee7..d392a828fc49 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; > This patch looks good to me. Thanks! Reviewed-by: Ray Jui