From nobody Mon Feb 9 08:12:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633538980; cv=none; d=zohomail.com; s=zohoarc; b=Jtipg4trkwaPJcKprK6DHbHVO1j4DW12KwKiSuwCNcaFPtLmtrddcuqHDgQXcie3W7p0Bjgm805r0ltGbvy9hCJV2XK9A31gxZCUrUYKSUl9UlgjkL9lkERxUT19bpKhuRRPI9Yg4Hg1Ss80wVRkYyHh3FSJIrTMByitp09tQLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633538980; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=QsqIwIPw/aVEJU0wObqpgT58/H42wXO8s028ilnH1FKDi3tZArJ86A23Knv4B1uxjkFLRNMwjnHrR0FVhA/1sb05CoElFmNVZpJQ4PPK0osPuxc82EEm7iIJFd5lX/aRwD16PbivHXAh8ujve/FneFPIagzpUHyFAypNXofdKe8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633538980865478.44129227079895; Wed, 6 Oct 2021 09:49:40 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-TOzzEVtONFuub8PX-1VLNA-1; Wed, 06 Oct 2021 12:49:38 -0400 Received: by mail-wr1-f71.google.com with SMTP id l6-20020adfa386000000b00160c4c1866eso2549167wrb.4 for ; Wed, 06 Oct 2021 09:49:38 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id x26sm2286144wmi.30.2021.10.06.09.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 09:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633538979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=ZqdcR6lzKmBDBtI9sdUm96VM20XGVfgUNIXIACMkLZKQXMK1sx+XWAeEZteBC/2HOnDSlV du5vIikmlawC6Fu8ALxIJpKPi4KcII6EmTRKpjp/3wCyDlZYk7NUoPNFEHSWn9Fq24PIj0 CHK5kXipHlq/sDVAGN/wLnAlzDuQk+8= X-MC-Unique: TOzzEVtONFuub8PX-1VLNA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d0wXTRVmpQOHIPz9zqGtnv0qzZsKc85iVogQEdlDyD0=; b=72Id7+K36uB9GuqokOqeRk8/R+zNQQDuWXXIIM8mmgWTzWzWPmRi9DRz+3uS6b0QWD MP/m0LfsEvLfeWlUVxY2P9kLz+5FJJ8rZHaMVqY05esGHNBDtWv638tV6emovEXf+PlT /tLTl3IVE0gTC3n1/3Yx/EdM69DnHmTC1s0LkVu0oi5Hp8lq5843fGhGS4yq5L31QbrY fAYU9JBMFEknRNrqBXLdrlo+JMbpdlZBisEcBP8qlYc3nl5rLl+CYDVfv/gjrONYceLa op3sBTjv07Phd47U/lcirDOp6madUphlB+bAYlLfsx/6TjF+TY2SEFm+fIEatS1KdX/U IBHA== X-Gm-Message-State: AOAM5312+WPfZzreN5pLnMp9szrQimze37vlkuUsu+eaASdLp8g3pMTI HvGARAFQL/QE/p3AaxgoEfz9adJ+Deb4wsWHWNymS7XDbKrDbQdwrsv9XJ+XSe/KJR2CR/vf0/n o+XGwVZdTJ7Ho3Q== X-Received: by 2002:a1c:f402:: with SMTP id z2mr11082178wma.53.1633538977670; Wed, 06 Oct 2021 09:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydeu1JlGJw2kKXfKAKwoIL9nQM05DbKetFZYl2QntNWdBATWFh+MyLoMXbF+gdHWtDcjzPMg== X-Received: by 2002:a1c:f402:: with SMTP id z2mr11082166wma.53.1633538977538; Wed, 06 Oct 2021 09:49:37 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Max Reitz Subject: [PATCH 1/5] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE Date: Wed, 6 Oct 2021 18:49:27 +0200 Message-Id: <20211006164931.172349-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006164931.172349-1-philmd@redhat.com> References: <20211006164931.172349-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633538982148100001 Since commit 4d324c0bf65 ("introduce QEMU_AUTO_VFREE") buffers allocated by qemu_memalign() can automatically freed when using the QEMU_AUTO_VFREE macro. Use it to simplify a bit. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 1cc7b62bb4b..fefcc04abe6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -514,10 +514,10 @@ static bool nvme_identify(BlockDriverState *bs, int n= amespace, Error **errp) { BDRVNVMeState *s =3D bs->opaque; bool ret =3D false; - union { + QEMU_AUTO_VFREE union { NvmeIdCtrl ctrl; NvmeIdNs ns; - } *id; + } *id =3D NULL; NvmeLBAF *lbaf; uint16_t oncs; int r; @@ -595,7 +595,6 @@ static bool nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) s->blkshift =3D lbaf->ds; out: qemu_vfio_dma_unmap(s->vfio, id); - qemu_vfree(id); =20 return ret; } @@ -1219,7 +1218,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, { BDRVNVMeState *s =3D bs->opaque; int r; - uint8_t *buf =3D NULL; + QEMU_AUTO_VFREE uint8_t *buf =3D NULL; QEMUIOVector local_qiov; size_t len =3D QEMU_ALIGN_UP(bytes, qemu_real_host_page_size); assert(QEMU_IS_ALIGNED(offset, s->page_size)); @@ -1246,7 +1245,6 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, if (!r && !is_write) { qemu_iovec_from_buf(qiov, 0, buf, bytes); } - qemu_vfree(buf); return r; } =20 @@ -1365,7 +1363,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, BDRVNVMeState *s =3D bs->opaque; NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; - NvmeDsmRange *buf; + QEMU_AUTO_VFREE NvmeDsmRange *buf =3D NULL; QEMUIOVector local_qiov; int ret; =20 @@ -1440,7 +1438,6 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, trace_nvme_dsm_done(s, offset, bytes, ret); out: qemu_iovec_destroy(&local_qiov); - qemu_vfree(buf); return ret; =20 } --=20 2.31.1