Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2148804ybh; Fri, 17 Jul 2020 10:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz21U+DbovKQ77JqyLCOq2UDz7JcXTgQ7NJiGar8I2CDmwcx1yQxj6FhsKVU45jCE84RC95 X-Received: by 2002:aa7:c655:: with SMTP id z21mr10250603edr.330.1595006620775; Fri, 17 Jul 2020 10:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595006620; cv=none; d=google.com; s=arc-20160816; b=Rfyfj1wXzHM2thWCuRy85Vwa6AHgLzJ8fpHZnTyj6UToKGJUhCdsn5z6dbzRZI+bD+ 2ICXb8Lx/DvhvtQOKI/OCMPJ9dp5DbZSWx1O5aUadNNtupVwRyshFWuyTQa3J3upDIWJ DLbYORXg0Oudxxrxd1weW/2az1hDA5153QYpTpNB+zNdcw5KoyFocU/KtnMW/tlWLdEu H72o/iVeTbJKOBpXFkqC+M5zhpIb4n+0otROJzGAOPmsKNdwqlGoYnaFq5pBmDIM/Kxt 2l5xm7y01lB4ziumYjx6f8V8cL8MoMOsCP6QjAwrKJuV9ucSYkwwpw5F2DY1wtot5Njw rOwg== 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=AoGGlbrqDdPdAt7SZnkfIe6cI/q8MK4oBz8zz9M/acQ=; b=ZU4hLCxxhk9l69XoeVZcIP4U4y1iIHJj5luQQoByNK362Wn/fZrdLLtjV9i2qc5o18 M6/9Kh4xpP6F5f1jZ6hHtENGfIwHyoT5PvpJJ8R5OQNaVa5sMiErYhwfU8dnAwJSo+JU YMnaN4wwhRGvFzv6FnsLfGnX7qLlDaCzYyh25JdI2Rwc47bHa1hn/BqvmyMPQwo08bj8 pzyqvJrga6Qx7JJpCXm6x4UdFxOOvNvAnG3k/ncCITf/AdyztQ+i8LEy0xwzzaDrwIFU WKzoee64LqRLfWr5tQE9xOySUIgGTxkKcup3o0D3D/XY//kejobi6Z6uxdc+9xPfhCjh WbBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=eBRo3SW0; 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 bi2si5481097ejb.531.2020.07.17.10.23.18; Fri, 17 Jul 2020 10:23:40 -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=eBRo3SW0; 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 S1726636AbgGQRWV (ORCPT + 99 others); Fri, 17 Jul 2020 13:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbgGQRWV (ORCPT ); Fri, 17 Jul 2020 13:22:21 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEA4BC0619D3 for ; Fri, 17 Jul 2020 10:22:20 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id j18so16087165wmi.3 for ; Fri, 17 Jul 2020 10:22:20 -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=AoGGlbrqDdPdAt7SZnkfIe6cI/q8MK4oBz8zz9M/acQ=; b=eBRo3SW05EhHdbRiObyZVkdToB+SfnAgfcwfG1UziRDO9imQP66XiFEiflsyu7G768 FmF/sg++nQJp84LORbbmQkWzuXcpIJyVD/dBxXCSOTueCiV5pr6ULXJoxaOpjCogUSbo liKDKgBvilIpKfw9Z9uzB7iI6If0J1WJpzaWg= 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=AoGGlbrqDdPdAt7SZnkfIe6cI/q8MK4oBz8zz9M/acQ=; b=hKEH76BbcAYfqyG6DKD5/WmC/X6FZNBojM4k/qsiyI9kDGHfGAB29naX8zkCZnITCg DbiyM9EfdNHt52CLzmQyu+coONsLnYp3R6HUv6lMo5hMFNOPgFb8GyN846nhUY3c5IEB iUlf+Ag7E0qWDXzOt6J7gvD07DNw8J5siwrgdMjv4tdtvHt0LuxVne2S1ZWz3sV6SAJE B4opD+0hQKmBwHZtyGbWZB0e5KykXbP5mZwvaQsysiqfA9AKLX4+Juj5qI+NhpIl8Fzw 9DSkRy0pERCO/hvbGm3ttgciRJgQ4iyRVQ1y0xmzs1L/vHsoWDOUDVJXmy9bdKHKQufl xcpQ== X-Gm-Message-State: AOAM533fdGDI9L+eak8p0rIXUroKc1TSu3oakdufZgw+Q2TggC2NWSB0 wp/Aua6ouD9Ffj4pQrcsZH/E3Q== X-Received: by 2002:a7b:cb98:: with SMTP id m24mr10210755wmi.98.1595006539117; Fri, 17 Jul 2020 10:22:19 -0700 (PDT) Received: from [10.230.182.181] ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id g13sm15986896wro.84.2020.07.17.10.22.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2020 10:22:18 -0700 (PDT) Subject: Re: [PATCH] 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: <20200717170743.25466-1-scott.branden@broadcom.com> From: Ray Jui Message-ID: <94f2aed1-d88d-3ee0-6e57-917f665951f2@broadcom.com> Date: Fri, 17 Jul 2020 10:22:13 -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: <20200717170743.25466-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 10:07 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 > --- > drivers/pwm/pwm-bcm-iproc.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c > index 1f829edd8ee7..72a8607b6c8d 100644 > --- a/drivers/pwm/pwm-bcm-iproc.c > +++ b/drivers/pwm/pwm-bcm-iproc.c > @@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > u32 value, prescale; > > rate = clk_get_rate(ip->clk); > + if (rate == 0) { > + state->period = 0; > + state->duty_cycle = 0; > + return; > + } Based on the pwm core code, 'get_state' expects the following fields to be populated: 'polarity', 'enabled', 'period', and 'duty cycle'. The above logic will leave 'polarity' and 'enabled' completely unpopulated when clock rate is zero. > > value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); > >