lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 6 Apr 2023 14:44:45 +0100
From:   Conor Dooley <conor.dooley@...rochip.com>
To:     Thierry Reding <thierry.reding@...il.com>
CC:     Conor Dooley <conor@...nel.org>,
        Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>,
        Daire McNamara <daire.mcnamara@...rochip.com>,
        <linux-kernel@...r.kernel.org>, <linux-pwm@...r.kernel.org>,
        <linux-riscv@...ts.infradead.org>
Subject: Re: [PATCH v15 1/2] pwm: add microchip soft ip corePWM driver

On Thu, Apr 06, 2023 at 03:17:45PM +0200, Thierry Reding wrote:
> On Sat, Apr 01, 2023 at 09:50:47PM +0100, Conor Dooley wrote:
> > On Thu, Mar 30, 2023 at 08:12:03AM +0100, Conor Dooley wrote:
> > 
> > > +	/*
> > > +	 * Because 0xff is not a permitted value some error will seep into the
> > > +	 * calculation of prescale as prescale grows. Specifically, this error
> > > +	 * occurs where the remainder of the prescale calculation is less than
> > > +	 * prescale.
> > > +	 * For small values of prescale, only a handful of values will need
> > > +	 * correction, but overall this applies to almost half of the valid
> > > +	 * values for tmp.
> > > +	 *
> > > +	 * To keep the algorithm's decision making consistent, this case is
> > > +	 * checked for and the simple solution is to, in these cases,
> > > +	 * decrement prescale and check that the resulting value of period_steps
> > > +	 * is valid.
> > > +	 *
> > > +	 * period_steps can be computed from prescale:
> > > +	 *                      period * clk_rate
> > > +	 * period_steps = ----------------------------- - 1
> > > +	 *                NSEC_PER_SEC * (prescale + 1)
> > > +	 *
> > > +	 */
> > > +	if (tmp % (MCHPCOREPWM_PERIOD_STEPS_MAX + 1) < *prescale) {
> > 
> > Hmm, looks like 32-bit doesn't like this modulus.
> > I pushed things out for LKP to test before sending as I felt I'd not be
> > allowed to do that operation, but got a build success email from it.
> > I'm not sure why the mail wasn't sent as a reply to this, but
> > <202304020410.A86IBNES-lkp@...el.com> complains:
> > pwm-microchip-core.c:(.text+0x20a): undefined reference to `__aeabi_uldivmod'
> > 
> > I know that tmp < 65536 at this point, so if the general approach is
> > fine, I can always cast it to a non 64-bit type without losing any
> > information.
> 
> Since you already use some of the helpers from linux/math64.h, perhaps
> you can use something like div_u64_rem() here?

I had actually initially tried to do that, before I added changed the
calculation of prescale to use DIV64_U64_ROUND_UP():
| *prescale = DIV64_U64_ROUND_UP(tmp, MCHPCOREPWM_PERIOD_STEPS_MAX + 1) - 1;

I could I suppose add an additional:
| div_u64_rem(tmp, MCHPCOREPWM_PERIOD_STEPS_MAX + 1, &remainder);

and then just use the value of remainder in the if statement.
Not the prettiest thing in the world I suppose, but should be 32-bit
safe...

Thanks for the suggestion, I'm just surprised that LKP didn't complain
when it built my tree...

Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ