Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3494753ybb; Mon, 23 Mar 2020 02:06:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtUo85QivsM+zohO4W4qsTuACBoAl/I580HtmCuNEKHVlt3eX/YBWlyaZmaa2mnyKAfW/Ns X-Received: by 2002:a05:6830:4b1:: with SMTP id l17mr17111570otd.275.1584954393504; Mon, 23 Mar 2020 02:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584954393; cv=none; d=google.com; s=arc-20160816; b=Tjnjzon6CXqdF8MjjT3f3O3lzplSjtQnK4ybxhkD42LRLMhGFYyQRQDKnUfhYtFrnG obe6Ag9ukNa1fCvWrgF3W8r9XJ39WTCQm6RfPgO0Aum+d6KCMvFBQCb1bBYBSaDBJSRI mrhsy1uuiEIXXAEl6WbG9ysdL5UT//hHHzqDtRBFhCGqiWeyqw8711vhBm46X/YO4b5L gZpK5r6+7XZ6ePB2+wAV8FkgY/sltStj2nRBKkp+ZziMLJFdVZ46Psh7CtSrTm55Ex0B BOlEXSUh7gTcurBCCgqWJ4eRa0Q/YNbYR4i4d+X1mkONwQX2JiMUWjPgwJ88oE2yVGH8 Ujtg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UeQUAcdMZxn26RtbUmldtq49KvGfHbMzwTxg6ahzu8Q=; b=FgyHmqE31b5M6XqsRF4OFEj/UPNi8cBXBnO218AFRBAaYuowUldFdJOqnHR23AFsC5 oBQiAI7TJtvkiQMGNw7FUgX7RXALplFbYe1R2FyzSauY2IdOrbdZJbYxPKftOHMlHRXX dCp3V4WGTvZ2aLPdzSJVdKD0xWFpANv+eTSUOw0Yqhyme8yG6XP7vH06YR6nkkLRJk3L HA6oY+63VXrDmd9Za1xLTm8jPm0gvIdtOi/Fy1Ss+fxPb+XbMUe4FXu6FWwtGyxQPEkD wu5dSyM/Uhm3cw6fEhx2CqffP8Sn8q3SbtyI6c8zbIIc8KZuVY1Q1g8NcbtjJJDv5MQO nj/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=gj67rIhc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o18si7592791otk.80.2020.03.23.02.06.20; Mon, 23 Mar 2020 02:06:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=gj67rIhc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727650AbgCWJFm (ORCPT + 99 others); Mon, 23 Mar 2020 05:05:42 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35476 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbgCWJFm (ORCPT ); Mon, 23 Mar 2020 05:05:42 -0400 Received: by mail-lj1-f194.google.com with SMTP id u12so13655653ljo.2 for ; Mon, 23 Mar 2020 02:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UeQUAcdMZxn26RtbUmldtq49KvGfHbMzwTxg6ahzu8Q=; b=gj67rIhc9xmtkaXHqF2aKuKpPzYsq6nRprfC6gX/IIfe2bFxncqRx4LENZfh1WRp3Q OD6IItiqpkArFZmgK3PCQKt0vuhkduXH9aRT1J30TeWACtsHmjVjB+jefTtkmyXe/svS IUOwswoEXf+4gP8/NR1KJqeG6PZs1vnX1Q6KI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UeQUAcdMZxn26RtbUmldtq49KvGfHbMzwTxg6ahzu8Q=; b=GtaqNozDWSmsLoAXvMgHQ34RJ7jqPAyMs1AAohrqfzfgjE2+fay/hu5DJji/v8rQKX pyN4/nK22FM2cn21fCk0C6TO+uixZWEv4PEDXbN+JOcw+jLqLHVTPJBlqf+2lYdzuPP0 OngV4esZquZxpTpPx0GUM+nQgPdNlCnC7bo9bTTJmbsduzJZ8jnFWaodgaerGluzz3Gz dAx4QnS8E62cM0vWi2B6lRf6u03TKA1YMp6JU9O+pHBXOUWbZsJ+1FCoW9TF7gYnwCjk DXF/jl7f7c61WNVvTEye9ZwhHf7o+CBYvkC/UT3pYQzteBOZIq04n4wNXmfC2wU/QRQK wi9w== X-Gm-Message-State: ANhLgQ1dkyWDDL7CI2w1StJw8MrSjTYTOO84Tc5A+ykl/UDODldWYwy2 fMoQKcwIPNm6EtdDrVdFgESxamvhvcFu9RGqWPYOTg== X-Received: by 2002:a2e:a483:: with SMTP id h3mr8739201lji.264.1584954338871; Mon, 23 Mar 2020 02:05:38 -0700 (PDT) MIME-Version: 1.0 References: <20200323065318.16533-1-rayagonda.kokatanur@broadcom.com> <20200323065318.16533-2-rayagonda.kokatanur@broadcom.com> <20200323082540.2gvbbxtwadvzeeos@pengutronix.de> In-Reply-To: <20200323082540.2gvbbxtwadvzeeos@pengutronix.de> From: Rayagonda Kokatanur Date: Mon, 23 Mar 2020 14:35:27 +0530 Message-ID: Subject: Re: [PATCH v1 1/2] pwm: bcm-iproc: handle clk_get_rate() return To: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= Cc: Thierry Reding , Ray Jui , Scott Branden , BCM Kernel Feedback , Yendapally Reddy Dhananjaya Reddy , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 1:55 PM Uwe Kleine-K=C3=B6nig wrote: > > On Mon, Mar 23, 2020 at 12:23:17PM +0530, Rayagonda Kokatanur wrote: > > Handle clk_get_rate() returning <=3D 0 condition to avoid > > possible division by zero. > > Was this noticed during a review and is more theoretic. Or does this > (depending on pre-boot state) result in a kernel crash? This is reported by internal coverity tool. > > > Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controlle= r") > > Signed-off-by: Rayagonda Kokatanur > > --- > > drivers/pwm/pwm-bcm-iproc.c | 32 +++++++++++++++++++------------- > > 1 file changed, 19 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c > > index 1f829edd8ee7..8bbd2a04fead 100644 > > --- a/drivers/pwm/pwm-bcm-iproc.c > > +++ b/drivers/pwm/pwm-bcm-iproc.c > > @@ -99,19 +99,25 @@ static void iproc_pwmc_get_state(struct pwm_chip *c= hip, struct pwm_device *pwm, > > else > > state->polarity =3D PWM_POLARITY_INVERSED; > > > > - value =3D readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); > > - prescale =3D value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); > > - prescale &=3D IPROC_PWM_PRESCALE_MAX; > > - > > - multi =3D NSEC_PER_SEC * (prescale + 1); > > - > > - value =3D readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm)); > > - tmp =3D (value & IPROC_PWM_PERIOD_MAX) * multi; > > - state->period =3D div64_u64(tmp, rate); > > - > > - value =3D readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm= )); > > - tmp =3D (value & IPROC_PWM_PERIOD_MAX) * multi; > > - state->duty_cycle =3D div64_u64(tmp, rate); > > + if (rate =3D=3D 0) { > > + state->period =3D 0; > > + state->duty_cycle =3D 0; > > + } else { > > + value =3D readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); > > + prescale =3D value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm= ); > > + prescale &=3D IPROC_PWM_PRESCALE_MAX; > > + > > + multi =3D NSEC_PER_SEC * (prescale + 1); > > + > > + value =3D readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->h= wpwm)); > > + tmp =3D (value & IPROC_PWM_PERIOD_MAX) * multi; > > + state->period =3D div64_u64(tmp, rate); > > + > > + value =3D readl(ip->base + > > + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm)); > > + tmp =3D (value & IPROC_PWM_PERIOD_MAX) * multi; > > + state->duty_cycle =3D div64_u64(tmp, rate); > > + } > > The change looks fine. > > Best regards > Uwe > > -- > Pengutronix e.K. | Uwe Kleine-K=C3=B6nig = | > Industrial Linux Solutions | https://www.pengutronix.de/ = |