lkml.org 
[lkml]   [2021]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH RESEND MERGE REQUEST] mm/damon: move damon_rand() definition into damon.h
Date
On Thu, 2 Dec 2021 15:12:13 -0800 Andrew Morton <akpm@linux-foundation.org> wrote:

> On Thu, 2 Dec 2021 15:58:59 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:
>
> > damon_rand() is called in three files:damon/core.c, damon/
> > paddr.c, damon/vaddr.c, i think there is no need to redefine
> > this twice, So move it to damon.h will be a good choice.
>
> Fair enough.
>
> > +/* Get a random number in [l, r) */
> > +#define damon_rand(l, r) (l + prandom_u32_max(r - l))
>
> This shouldn't be implemented as a macro, for all the usual reasons
> (typechecking, side-effects, ugliness, code-documentation site, etc).

Yes, agreed.

>
> In particular, this expression references `l' twice, so calling
>
> damon_rand(a++, b);
>
> will increment `a' twice, surprise surprise.

Thank you for this nice explanation.

>
> Can someone please send a followup patch to convert this (and any
> similar damon macros) into (probably static inlined) C functions?

Sure, I will do, unless someone shows interest here.


Thanks,
SJ

\
 
 \ /
  Last update: 2021-12-03 10:20    [W:0.059 / U:0.212 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site