Re: [PATCH 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL
From: Javi Merino
Date: Mon Mar 23 2015 - 13:04:25 EST
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.
Cheers,
Javi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/