From patchwork Mon Dec 6 12:41:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12658259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D546C433EF for ; Mon, 6 Dec 2021 12:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 798E06B007B; Mon, 6 Dec 2021 07:41:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 749446B007D; Mon, 6 Dec 2021 07:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 637796B007E; Mon, 6 Dec 2021 07:41:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 517306B007B for ; Mon, 6 Dec 2021 07:41:50 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 18306183E9518 for ; Mon, 6 Dec 2021 12:41:40 +0000 (UTC) X-FDA: 78887330760.21.870BC5C Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf08.hostedemail.com (Postfix) with ESMTP id B614B30000A0 for ; Mon, 6 Dec 2021 12:41:37 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UzcCAPP_1638794492; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UzcCAPP_1638794492) by smtp.aliyun-inc.com(127.0.0.1); Mon, 06 Dec 2021 20:41:33 +0800 From: Xin Hao To: sj@kernel.org Cc: xhao@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function Date: Mon, 6 Dec 2021 20:41:29 +0800 Message-Id: <7066b07ba4f89e32c5264ed1f7d71260bea8812e.1638794380.git.xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B614B30000A0 X-Stat-Signature: 6aj6sy98k8bu9gm1ddrxdmkoaew14x3q X-HE-Tag: 1638794497-965246 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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") Reported-by: Andrew Morton Signed-off-by: Xin Hao --- include/linux/damon.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.31.0 diff --git a/include/linux/damon.h b/include/linux/damon.h index c6df025d8704..bc9c8932b1e8 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -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 + (r - l); +} /** * struct damon_addr_range - Represents an address region of [@start, @end).