Skip to contentSkip to conversation

mm/damon: Modify damon_rand() macro to static inline function

PATCH Applied Xin Hao 2 participants 2 messages Dec 6, 2021

Subsystems (2)
lore
Share & tools
lore

Xin Hao

author
#0 lore raw

PATCH v2 1/1 mm/damon: Modify damon_rand() macro to static inline function

The damon_rand() func can not be implemented as a macro. Example:

	damon_rand(a++, b);

The value of 'a' will be incremented twice, This is obviously unreasonable, So there fix it.

Fixes b9a6ac4e4ede ("mm/damon: adaptively adjust regions")
---
 include/linux/damon.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/damon.h +4 -1
index c6df025d8704..a58046cd45e6 100644
@@ -19,7 +19,10 @@
 #define DAMOS_MAX_SCORE		(99)
 
 /* Get a random number in [l, r) */
-#define damon_rand(l, r) (l + prandom_u32_max(r - l))
+static inline unsigned long damon_rand(unsigned long l, unsigned long r)
+{
+	return l + prandom_u32_max(r - l);
+}
 
 /**
  * struct damon_addr_range - Represents an address region of [@start, @end).

--
2.31.0

maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · On Mon, 6 Dec 2021 20:52:43 +0800 Xin Hao <[email protected]> wrote:

The damon_rand() func can not be implemented as a macro. Example:

	damon_rand(a++, b);

The value of 'a' will be incremented twice, This is obviously unreasonable, So there fix it.

Fixes b9a6ac4e4ede ("mm/damon: adaptively adjust regions")

Thanks,
SJ

Quoted 24 lines
---
 include/linux/damon.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/damon.h +4 -2
index c6df025d8704..a58046cd45e6 100644
@@ -19,7 +19,10 @@
 #define DAMOS_MAX_SCORE		(99)
 
 /* Get a random number in [l, r) */
-#define damon_rand(l, r) (l + prandom_u32_max(r - l))
+static inline unsigned long damon_rand(unsigned long l, unsigned long r)
+{
+	return l + prandom_u32_max(r - l);
+}
 
 /**
  * struct damon_addr_range - Represents an address region of [@start, @end).
--

2.31.0