{"id":2223648,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223648/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415215539.92629-7-philmd@linaro.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.1/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260415215539.92629-7-philmd@linaro.org>","date":"2026-04-15T21:55:37","name":"[6/8] cocci: Do not initialize variable used by CPU_FOREACH macro","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b8f1ff49ac6d72d1c2aea7f5daa585e8fbb716b6","submitter":{"id":85046,"url":"http://patchwork.ozlabs.org/api/1.1/people/85046/?format=json","name":"Philippe Mathieu-Daudé","email":"philmd@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415215539.92629-7-philmd@linaro.org/mbox/","series":[{"id":500043,"url":"http://patchwork.ozlabs.org/api/1.1/series/500043/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500043","date":"2026-04-15T21:55:33","name":"cocci: Do not initialize variable used by *FOREACH*() macro","version":1,"mbox":"http://patchwork.ozlabs.org/series/500043/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223648/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223648/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=PjHFefcN;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fww464Bssz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 07:57:42 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wD8Dk-0002V4-Mj; Wed, 15 Apr 2026 17:56:28 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wD8Dj-0002TR-CF\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 17:56:27 -0400","from mail-wm1-x336.google.com ([2a00:1450:4864:20::336])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wD8Dh-0002oM-IP\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 17:56:27 -0400","by mail-wm1-x336.google.com with SMTP id\n 5b1f17b1804b1-488b0046078so71182165e9.1\n for <qemu-devel@nongnu.org>; Wed, 15 Apr 2026 14:56:23 -0700 (PDT)","from localhost.localdomain (88-187-86-199.subs.proxad.net.\n [88.187.86.199]) by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43ead3d5f11sm8921436f8f.18.2026.04.15.14.56.21\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Wed, 15 Apr 2026 14:56:22 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776290182; x=1776894982; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ChYobPnwj4tKATx8rDrb5+LPUUeRhqbHM1XXErD9y5Q=;\n b=PjHFefcNU0A5xS8WW5DSM5gMSt0Al2KEbo3fch2PhCodCk3H+LJgGPChpLedIMuRSh\n AdhTVENaEPI1pqqi9GvVHromZu0KMiR4wwvQO6ZUeUxgLrHOFGvAaUNVtyG8FjfZHUw5\n CXiVCJ/871g1eHozro8N4vJ0a2cKCWWJ9Y83wprVZ2zYd/Xv376h0/LOFDEoi3tETEsZ\n rToMkC27NchS7tS3psvArg1E69v6P6Npj+XkCwu4abz3u88tOogUzKCLKOz+0EqC4AAV\n 7fGRSzJC+U11DhCCCyTtiMiVZ9asiDNi+GSxCTk+hZ6jfcSv/Q8USgiqgrfsLz2Uba28\n W1kQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776290182; x=1776894982;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ChYobPnwj4tKATx8rDrb5+LPUUeRhqbHM1XXErD9y5Q=;\n b=SS9KovbxT8yUITGFGfYhazmjBgOoeDEMny+FjOO4abNTsf5oe9urm/MFXn0g9auXhL\n TCKO5XjMuMnTq+lPxW4m649NWpx+FN+wVPHmuC1ciBKzetVgcd/CjIcLjtYtGleZDZ/s\n oTOJyu/yT1v47jCShvxoeWoK/n5OugLPWCMBq3cePf24Ue8xXfdYMBK2U8HDsy01DO65\n /OmWvJSl1aQhHONYodncAsf/PSeicE2xAefgEf24R5J4hU4IiLUjXvnr1b73sQ1pf0Si\n Lto42XkQ5lswekLpLEKAdIp6fcupyKsiAi/OjWGBFMif4N7T8RMWsw5S5AdqV4ZRXriz\n f3vA==","X-Gm-Message-State":"AOJu0YxokvJm58EOk2BjPTnD6RwKCwS7kFMJrl4R/oqDLoFVKo7YthV0\n Xt7gFkDwc/8G7YSXPNGwI2WAhYhaGQvEvuD2m76J1LSGgPme6vYYblGC6ikjYd7oNtsJcyq5iMF\n 2dVL0jrI=","X-Gm-Gg":"AeBDieub7x5PdAjSGsoKDoH+yPt6e1HBKk5mNgCkC0Vk1MhVL8vmaVXSKmcCCEanW9x\n gDYTs0pLEiV2wPGqs8HNeT4VUewjuE/PE4++1JPB5fjZ1wMzJmal5ycb3qU67eJ3YZCkbe2hy+t\n qIYm1trrlsS9hq3lo2eE6JH6Ky7OVjeCuZ812tYVxU6OHPz0O5y9RXt/uRoe/oTJp+TYw7D0p3f\n lir9Ozuq219Mjtehb8oNnBxe/7GnsFWybTRI8f2EYaoZLJ3HSqTohltKMeyPud/d5gq4NJJkbtm\n osqmvM/Ts3pLmyaMPWOvQh0TEUvyXUnEEs1PwgaUopn29n57FAWlTmiGBVELT/irNfoOAQ/ogjm\n GmhbeNUwNTykt4gOnIJn6MApoYp5Gr6+lU4bCjtZDE7/SrNIyI5vRpDbRJByfAUlVavTp8oDx4G\n ChtLddG0yFjsJYoEIX5urJdhttLlsOkSvIkmsaGvzoOClP9iuO1kOWBaOmMKL1qZZ4RBT2udoF","X-Received":"by 2002:a05:600c:a415:b0:485:419c:4eba with SMTP id\n 5b1f17b1804b1-488d67bf7abmr258106465e9.1.1776290182579;\n Wed, 15 Apr 2026 14:56:22 -0700 (PDT)","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>","To":"qemu-devel@nongnu.org","Cc":"qemu-arm@nongnu.org, qemu-s390x@nongnu.org, qemu-riscv@nongnu.org,\n qemu-block@nongnu.org","Subject":"[PATCH 6/8] cocci: Do not initialize variable used by CPU_FOREACH\n macro","Date":"Wed, 15 Apr 2026 23:55:37 +0200","Message-ID":"<20260415215539.92629-7-philmd@linaro.org>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260415215539.92629-1-philmd@linaro.org>","References":"<20260415215539.92629-1-philmd@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2a00:1450:4864:20::336;\n envelope-from=philmd@linaro.org; helo=mail-wm1-x336.google.com","X-Spam_score_int":"4","X-Spam_score":"0.4","X-Spam_bar":"/","X-Spam_report":"(0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1,\n DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001,\n SPF_HELO_NONE=0.001, SPF_PASS=-0.001,\n SUSPICIOUS_RECIPS=2.51 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"The CPU_FOREACH() macro, defined in \"hw/core/cpu.h\",\nends up calling QTAILQ_FOREACH_RCU() which always\nassigns its iterator variable when entering the loop.\nRemove the pointless and possibly misleading assignment.\n\nMechanical patch using the following coccinelle spatch:\n\n  @@\n  type T;\n  identifier e;\n  iterator FOREACH_MACRO =~ \".*_FOREACH.*\";\n  statement S;\n  @@\n  -    T *e = ...;\n  +    T *e;\n       ... when != e\n       FOREACH_MACRO(e, ...) S\n\nSigned-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>\n---\n target/mips/internal.h              | 2 +-\n hw/misc/mips_cpc.c                  | 4 ++--\n target/mips/tcg/system/cp0_helper.c | 8 ++++----\n target/mips/tcg/system/tlb_helper.c | 2 +-\n 4 files changed, 8 insertions(+), 8 deletions(-)","diff":"diff --git a/target/mips/internal.h b/target/mips/internal.h\nindex 28eb28936ba..c6cf69dfb6a 100644\n--- a/target/mips/internal.h\n+++ b/target/mips/internal.h\n@@ -279,7 +279,7 @@ static inline int mips_vpe_active(CPUMIPSState *env)\n \n static inline int mips_vp_active(CPUMIPSState *env)\n {\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n \n     /* Check if the VP disabled other VPs (which means the VP is enabled) */\n     if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {\ndiff --git a/hw/misc/mips_cpc.c b/hw/misc/mips_cpc.c\nindex 924de855ee2..240ccf4d312 100644\n--- a/hw/misc/mips_cpc.c\n+++ b/hw/misc/mips_cpc.c\n@@ -44,7 +44,7 @@ static void mips_cpu_reset_async_work(CPUState *cs, run_on_cpu_data data)\n \n static void cpc_run_vp(MIPSCPCState *cpc, uint64_t vp_run)\n {\n-    CPUState *cs = first_cpu;\n+    CPUState *cs;\n \n     CPU_FOREACH(cs) {\n         uint64_t i = 1ULL << cs->cpu_index;\n@@ -62,7 +62,7 @@ static void cpc_run_vp(MIPSCPCState *cpc, uint64_t vp_run)\n \n static void cpc_stop_vp(MIPSCPCState *cpc, uint64_t vp_stop)\n {\n-    CPUState *cs = first_cpu;\n+    CPUState *cs;\n \n     CPU_FOREACH(cs) {\n         uint64_t i = 1ULL << cs->cpu_index;\ndiff --git a/target/mips/tcg/system/cp0_helper.c b/target/mips/tcg/system/cp0_helper.c\nindex b69e70d7fcf..99f43ad9e11 100644\n--- a/target/mips/tcg/system/cp0_helper.c\n+++ b/target/mips/tcg/system/cp0_helper.c\n@@ -1559,7 +1559,7 @@ target_ulong helper_emt(void)\n \n target_ulong helper_dvpe(CPUMIPSState *env)\n {\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n     target_ulong prev = env->mvp->CP0_MVPControl;\n \n     if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {\n@@ -1577,7 +1577,7 @@ target_ulong helper_dvpe(CPUMIPSState *env)\n \n target_ulong helper_evpe(CPUMIPSState *env)\n {\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n     target_ulong prev = env->mvp->CP0_MVPControl;\n \n     if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {\n@@ -1599,7 +1599,7 @@ target_ulong helper_evpe(CPUMIPSState *env)\n /* R6 Multi-threading */\n target_ulong helper_dvp(CPUMIPSState *env)\n {\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n     target_ulong prev = env->CP0_VPControl;\n \n     if (!((env->CP0_VPControl >> CP0VPCtl_DIS) & 1)) {\n@@ -1617,7 +1617,7 @@ target_ulong helper_dvp(CPUMIPSState *env)\n \n target_ulong helper_evp(CPUMIPSState *env)\n {\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n     target_ulong prev = env->CP0_VPControl;\n \n     if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {\ndiff --git a/target/mips/tcg/system/tlb_helper.c b/target/mips/tcg/system/tlb_helper.c\nindex 566924b079e..680b4da29fa 100644\n--- a/target/mips/tcg/system/tlb_helper.c\n+++ b/target/mips/tcg/system/tlb_helper.c\n@@ -346,7 +346,7 @@ void helper_ginvt(CPUMIPSState *env, target_ulong arg, uint32_t type)\n     uint32_t invMsgVPN2 = arg & (TARGET_PAGE_MASK << 1);\n     uint8_t invMsgR = 0;\n     uint32_t invMsgMMid = env->CP0_MemoryMapID;\n-    CPUState *other_cs = first_cpu;\n+    CPUState *other_cs;\n \n #ifdef TARGET_MIPS64\n     invMsgR = extract64(arg, 62, 2);\n","prefixes":["6/8"]}