lkml.org 
[lkml]   [2015]   [Mar]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL
On Mon, Mar 23, 2015 at 05:04:16PM +0000, Javi Merino wrote:
> On Mon, Mar 23, 2015 at 12:34:04PM +0000, Jeff Epler wrote:
> > On Fri, Mar 20, 2015 at 11:14:40AM +0000, Javi Merino wrote:
> > > +/*
> > > + * Same as above but for u64 dividends. divisor must be a 32-bit
> > > + * number.
> > > + */
> > > +#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
> > > +{ \
> > > + unsigned long long _tmp = (x) + (divisor) / 2; \
> > > + do_div(_tmp, divisor); \
> > > + _tmp; \
> > > +} \
> > > +)
> >
> > The macro evaluates 'divisor' twice.
>
> Good catch. That needs to be fixed. I could do the typeof trick that
> DIV_ROUND_CLOSEST() does but it's probably better to just create a
> static function as Alex Elder suggests. I'll send a v2 tomorrow with
> a static function instead.

Nah, thinking about it and seeing the other macros in this file
(esp. DIV_ROUND_UP() and DIV_ROUND_UP_ULL()) I don't think a static
function gives you anything. I'll just modify the macro to look similar
to DIV_ROUND_CLOSEST()

Cheers,
Javi



\
 
 \ /
  Last update: 2015-03-24 13:01    [W:1.161 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site