From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5B7DC43331 for ; Tue, 31 Mar 2020 20:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8437120757 for ; Tue, 31 Mar 2020 20:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730642AbgCaUVA (ORCPT ); Tue, 31 Mar 2020 16:21:00 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:31635 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727708AbgCaUVA (ORCPT ); Tue, 31 Mar 2020 16:21:00 -0400 Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 31 Mar 2020 13:20:59 -0700 Received: from gurus-linux.qualcomm.com ([10.46.162.81]) by ironmsg04-sd.qualcomm.com with ESMTP; 31 Mar 2020 13:20:58 -0700 Received: by gurus-linux.qualcomm.com (Postfix, from userid 383780) id C20AA4BC2; Tue, 31 Mar 2020 13:20:58 -0700 (PDT) Date: Tue, 31 Mar 2020 13:20:58 -0700 From: Guru Das Srinagesh To: Arnd Bergmann Cc: Linux PWM List , Thierry Reding , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Subbaraman Narayanamurthy , "linux-kernel@vger.kernel.org" , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: Re: [PATCH v11 06/12] pwm: imx27: Use 64-bit division macro and function Message-ID: <20200331202058.GB25781@codeaurora.org> References: <5aae102e21c0e63ad2588ae1e174b48b06d25e96.1584667964.git.gurus@codeaurora.org> <20200330204359.GB5107@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 31, 2020 at 05:24:52PM +0200, Arnd Bergmann wrote: > On Mon, Mar 30, 2020 at 10:44 PM Guru Das Srinagesh > wrote: > > > > On Fri, Mar 20, 2020 at 06:09:39PM +0100, Arnd Bergmann wrote: > > > On Fri, Mar 20, 2020 at 2:42 AM Guru Das Srinagesh wrote: > > > > > > > @@ -240,8 +240,7 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > > > > > > > period_cycles /= prescale; > > > > c = (unsigned long long)period_cycles * state->duty_cycle; > > > > - do_div(c, state->period); > > > > - duty_cycles = c; > > > > + duty_cycles = div64_u64(c, state->period); > > > > > > > > > > This change looks fine, but I wonder if the code directly above it > > > > > > c = clk_get_rate(imx->clk_per); > > > c *= state->period; > > > do_div(c, 1000000000); > > > period_cycles = c; > > > > > > might run into an overflow when both the clock rate and the period > > > are large numbers. > > > > Hmm. Seems to me like addressing this would be outside the scope of this > > patch series. > > I think it should be part of the same series, addressing bugs that > were introduced > by the change to 64-bit period. If it's not getting fixed along with > the other regressions, > I fear nobody is going to go back and fix it later. Makes sense, I agree. Would this be an acceptable fix? Instead of multiplying c and state->period first and then dividing by 10^9, first divide state->period by 10^9 and then multiply the quotient of that division with c and assign it to period_cycles. Like so: c = clk_get_rate(imx->clk_per); c *= div_u64(state->period, 1000000000); period_cycles = c; This should take care of overflow not happening because state->period is converted from nanoseconds to seconds early on and so becomes a small number. Thank you. Guru Das.