From nobody Wed Apr 1 22:13:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1775037686; cv=none; d=zohomail.com; s=zohoarc; b=J9bNgLORRiaHlLx+zmHwSRsTcf3pyefBf8lrdcd1eGWTdleZpjmREf12PO5FEC4j6HMKAQ+ytbfZY1rc5pOXoNMJGrWQsvVzxRSCN+l7KWVMvytvuu6Ldc0TIP+2ocXnl51/t96Cq/VCOcDBGLbwKHMybCMla0mVLJsPzPj+7tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775037686; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9bFZlLNwTFbooIfTwwN58QYLgiJuJrKDiz3NLMytJF0=; b=fidUuKjc56iRB6SCRtBiqIb+syYFPoRmJFjErwuZ7V1L3HReyosQOchPgNHXORBeClvRieJgw3Y+5AwTS1foRN9i7qr2stSRDDIXu4HdOmQQUp8idYqyFG2kstniZoCnqE+vRdFAVK/s8OLAF26+/pVuS1bU6eQWUKPF55FIM+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775037686739141.4893097130638; Wed, 1 Apr 2026 03:01:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w7sNN-0005Wg-V5; Wed, 01 Apr 2026 06:00:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w7sNJ-0005UQ-Nh for qemu-devel@nongnu.org; Wed, 01 Apr 2026 06:00:38 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w7sNC-0001vh-Ux for qemu-devel@nongnu.org; Wed, 01 Apr 2026 06:00:37 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X0AcEy1_1775037605 cluster:ay36) by smtp.aliyun-inc.com; Wed, 01 Apr 2026 18:00:12 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1775037613; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=9bFZlLNwTFbooIfTwwN58QYLgiJuJrKDiz3NLMytJF0=; b=VgRbRPxO7D//UFgY8pl1nRm3K2Lb1mT5PJM7CLsEDufQUJqKORXqGQIJJRhEerk3hOryKproITlAI6jlH9JuluI0ubh2En81WtMpHjcIZhaS/UeAS5EvNiEO7euhHzJeqMrj51OPUW0BuEh1rkpib8R9ejDAj17eFj33LPaWzU0= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R351e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=5; SR=0; TI=SMTPD_---0X0AcEy1_1775037605; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, richard.henderson@linaro.org, philmd@linaro.org, pbonzini@redhat.com Subject: [PATCH] physmem: Simplify dirty memory type checks with loop Date: Wed, 1 Apr 2026 18:00:05 +0800 Message-ID: <20260401100005.20651-1-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=115.124.30.130; envelope-from=guobin@linux.alibaba.com; helo=out30-130.freemail.mail.aliyun.com X-Spam_score_int: -154 X-Spam_score: -15.5 X-Spam_bar: --------------- X-Spam_report: (-15.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1775037689120154100 Content-Type: text/plain; charset="utf-8" In physical_memory_range_includes_clean(), we have three nearly identical if-statements checking different DIRTY_MEMORY types (VGA, CODE, MIGRATION). This code duplication makes maintenance harder and increases the risk of inconsistencies when adding new dirty memory types. Replace the repetitive checks with a simple loop that iterates through all DIRTY_MEMORY_NUM types, checking only those specified in the mask. This reduces code size and makes it easier to add new dirty memory types in the future. Signed-off-by: Bin Guo Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- system/physmem.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 4e26f1a1d4..c58d940e80 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -981,17 +981,11 @@ uint8_t physical_memory_range_includes_clean(ram_addr= _t start, { uint8_t ret =3D 0; =20 - if (mask & (1 << DIRTY_MEMORY_VGA) && - !physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) { - ret |=3D (1 << DIRTY_MEMORY_VGA); - } - if (mask & (1 << DIRTY_MEMORY_CODE) && - !physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) { - ret |=3D (1 << DIRTY_MEMORY_CODE); - } - if (mask & (1 << DIRTY_MEMORY_MIGRATION) && - !physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION))= { - ret |=3D (1 << DIRTY_MEMORY_MIGRATION); + for (int i =3D 0; i < DIRTY_MEMORY_NUM; i++) { + if ((mask & (1 << i)) && + !physical_memory_all_dirty(start, length, i)) { + ret |=3D (1 << i); + } } return ret; } --=20 2.50.1 (Apple Git-155)