From nobody Mon Feb 9 18:46:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621246090; cv=none; d=zohomail.com; s=zohoarc; b=OUE0nbE+NVK0LoRqhPjfejPIcx5byJpE5wZa6A1W2+NmZPfFuxz3HA4DPSI2zHwDfKcRAjiQB7Bv2iFGbWccKbDFv36qGcsWbsYsJxTDxw6fH4zJpci144hTjQH12sAylvvaiYWx/lsPCxvjc32pDlvKul38UnvZ27IVeGNbtY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621246090; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f3bgpbEohNOOBOFnBrKBrT5ery7OficY23T1F2PzmYo=; b=IS+WpvEPywwKGXGJ5iiPgAWjF+0iYlbiDMVh3jP9jv41XpmRNJPA2pT+wBm2+Akcy3nwZoS72o1rFxGeGnn4udlJvhFUm3xQ2oAjZS/lPMevt/uVrcCCNKQXFghsqLcnJ9YhtpwLh0QxS4qCMG+3E3VHw2m9p14q5S+wYzKxX0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162124609047383.62430900748814; Mon, 17 May 2021 03:08:10 -0700 (PDT) Received: from localhost ([::1]:51094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liaAT-000736-AT for importer@patchew.org; Mon, 17 May 2021 06:08:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lia8L-0004mi-0G; Mon, 17 May 2021 06:05:57 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:44858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lia8I-0001fK-1a; Mon, 17 May 2021 06:05:56 -0400 Received: by mail-ej1-x62d.google.com with SMTP id lz27so8283347ejb.11; Mon, 17 May 2021 03:05:53 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id h9sm10659926ede.93.2021.05.17.03.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 03:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f3bgpbEohNOOBOFnBrKBrT5ery7OficY23T1F2PzmYo=; b=ITMwkaOo6yy1XE3EjRD+L42V3BMweWWEGDqdC9GiGJOWk3dlEZx/2mJmYB+v9qN2ln FenIKH6D/k6gcOyskVbZGKNS3/bLWTUEp+mef4K9fZereCrxMYjdfd1rRbXVZFVBEGYR sk6ri3TVt8UszMWDVD1XlwM0IJ+y1UmjmV7GLmqispbxhhTTy/0WciES+jPOLNjrlD4c VsnKCZv/k+1SB+Pft8DcAhsqO6A2AR4BsXxKg21pRiT5lGA9mFmeBmToG6nLHtJkT6YC j8aIzrvf3WeJrNtBD6Sa2dHmmjVilRbTvMGNdzD4cIUpru0EQf8e4dewAz+XK9GeqTFv d1xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=f3bgpbEohNOOBOFnBrKBrT5ery7OficY23T1F2PzmYo=; b=EYOc3varTVbBVWuVujjM+Trbkja1z1ZQCez/dgy+GlExNuRIxGJYgPJUoETvy+AaQ7 U/OOICkzuCZNxqgAc6W8liaNkmP4aqg5qkfgIkUMAJhKoi+IZ/wjQBqUfhHKSJ54c66Q CX2oh9B76cry4yhd3HacGlt9MmJqOLefz54Ycr8t4mddDN1T6Dio9WxtZdszcOBv7ACQ UqvIZJvCLfSL+gQt+ZFyiHAIRc2796tlsX/6jXyRPLFi9+f6GqqSsMHl/mUysjd0RPNi h32g6MpppGKenCVU7Nrc4GEUqGcmK2ZXMBwJ6C+d+uA+7KoSn3cSSgqKlbakdEC+47tb gYJg== X-Gm-Message-State: AOAM531ADmJ9e5BcEt4fCNCSNpgGtspkkxq3DRogpzaKig6ywJCaaBge i8S46aQgi6c7MQmUfqL/U/8U4z5n2Elzig== X-Google-Smtp-Source: ABdhPJwX6CtdnaM+EkQn7bQq6q3DzebhFqNGdjQtrm7zJuSgut1TSgKCRHcO/067pv9c+nw3/s8kRw== X-Received: by 2002:a17:906:e210:: with SMTP id gf16mr4812659ejb.472.1621245952399; Mon, 17 May 2021 03:05:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] coroutine-sleep: disallow NULL QemuCoSleepState** argument Date: Mon, 17 May 2021 12:05:44 +0200 Message-Id: <20210517100548.28806-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517100548.28806-1-pbonzini@redhat.com> References: <20210517100548.28806-1-pbonzini@redhat.com> 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=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Simplify the code by removing conditionals. qemu_co_sleep_ns can simply point the argument to an on-stack temporary. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 5 +++-- util/qemu-coroutine-sleep.c | 18 +++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index ce5b9c6851..c5d7742989 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -295,7 +295,7 @@ typedef struct QemuCoSleepState QemuCoSleepState; =20 /** * Yield the coroutine for a given duration. During this yield, @sleep_sta= te - * (if not NULL) is set to an opaque pointer, which may be used for + * is set to an opaque pointer, which may be used for * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when = the * timer fires. Don't save the obtained value to other variables and don't= call * qemu_co_sleep_wake from another aio context. @@ -304,7 +304,8 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, QemuCoSleepState **sleep_state= ); static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { - qemu_co_sleep_ns_wakeable(type, ns, NULL); + QemuCoSleepState *unused =3D NULL; + qemu_co_sleep_ns_wakeable(type, ns, &unused); } =20 /** diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index eec6e81f3f..3f6f637e81 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -32,9 +32,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) qemu_co_sleep_ns__scheduled, NU= LL); =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - if (sleep_state->user_state_pointer) { - *sleep_state->user_state_pointer =3D NULL; - } + *sleep_state->user_state_pointer =3D NULL; timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } @@ -63,16 +61,10 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, } =20 aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); - if (sleep_state) { - *sleep_state =3D &state; - } + *sleep_state =3D &state; timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); - if (sleep_state) { - /* - * Note that *sleep_state is cleared during qemu_co_sleep_wake - * before resuming this coroutine. - */ - assert(*sleep_state =3D=3D NULL); - } + + /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ + assert(*sleep_state =3D=3D NULL); } --=20 2.31.1