From mboxrd@z Thu Jan 1 00:00:00 1970 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 2EDA7C433EF for ; Thu, 2 Dec 2021 23:12:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5730A6B0072; Thu, 2 Dec 2021 18:12:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5228C6B0074; Thu, 2 Dec 2021 18:12:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 411AA6B0075; Thu, 2 Dec 2021 18:12:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 2C7676B0072 for ; Thu, 2 Dec 2021 18:12:28 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D944C181B10CD for ; Thu, 2 Dec 2021 23:12:17 +0000 (UTC) X-FDA: 78874404756.24.FF06ADF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 8437CB0000A2 for ; Thu, 2 Dec 2021 23:12:17 +0000 (UTC) Received: from mail.kernel.org (unknown [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D26A6287A; Thu, 2 Dec 2021 23:12:16 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id B1626604AC; Thu, 2 Dec 2021 23:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1638486735; bh=DRD1qhyfdURHJ4AsAhOH6i7DOxCBkCGrkCjxjX5eqdk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HEvI+wcsBE/muLl9E2CdtsLJVUun+zLPs6VwoNcKMIgCH1nYIcR6hifvPDCVNFqnZ TXCVJDUD+O+/e8vy6tqbGrpvZmzCWltptMM6xZgrYMkuL/wIsRG9IRvgwDlvLf05cB KbkVdMhAq4T6i39u90akBTjh+Uqc3WPcv1VONv78= Date: Thu, 2 Dec 2021 15:12:13 -0800 From: Andrew Morton To: Xin Hao Cc: sj@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND MERGE REQUEST] mm/damon: move damon_rand() definition into damon.h Message-Id: <20211202151213.6ec830863342220da4141bc5@linux-foundation.org> In-Reply-To: <20211202075859.51341-1-xhao@linux.alibaba.com> References: <20211202075859.51341-1-xhao@linux.alibaba.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: pyo6mb37ozim6qgua39iqd9zurix5omt Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=HEvI+wcs; dmarc=none; spf=pass (imf24.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8437CB0000A2 X-HE-Tag: 1638486737-994293 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: On Thu, 2 Dec 2021 15:58:59 +0800 Xin Hao 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). In particular, this expression references `l' twice, so calling damon_rand(a++, b); will increment `a' twice, surprise surprise. Can someone please send a followup patch to convert this (and any similar damon macros) into (probably static inlined) C functions?