From nobody Mon Feb 9 11:06:20 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=1630566069; cv=none; d=zohomail.com; s=zohoarc; b=oG1FfHT3ra1ATXj3j9MHEgoaZUUtSLs/SAhHKoUF2kQCV099Q9Z6tKAroQmOvdhyURGWNzqX71n0H5KzY1HZ/0VjKI9k420yXjFFAXNHer8L1U/DRTGbk7BZLrB63m5tAcrkoxn/nGCmazsWHuMui36nyzG2PlZoI7NIc4GHzgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630566069; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0uOWhp+saqCNjYYeu2/7aRiyZ5BV70RG+ybspQ5dAak=; b=BoNisHTYQ3259KsPGr6VM25p++pB3iE5dquNftPwgugfw4ttpUWzTdVlO0dXmtPvIsH3kSeKzrZ9V8ZDg9WJGMA/g0avwCaj5lUxmvF/KGNEVG4CunRI8BcD4q9gSeGyLZehUtKHwIPkV1yQJko/nZA2OIZyx3u4+19hB3BL/Qw= 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 1630566069092119.7568950775941; Thu, 2 Sep 2021 00:01:09 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-465-Tush8DbEMMetgarvDd8x1g-1; Thu, 02 Sep 2021 03:01:05 -0400 Received: by mail-wm1-f70.google.com with SMTP id p11-20020a05600c204b00b002f05aff1663so349867wmg.2 for ; Thu, 02 Sep 2021 00:01:04 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id w9sm748568wmc.19.2021.09.02.00.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 00:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630566068; 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=0uOWhp+saqCNjYYeu2/7aRiyZ5BV70RG+ybspQ5dAak=; b=JPAUbQhch2EKJOPR9sx0lTCjUEOcEpYwLS7PT4GKWnsEOw+UNzS+NdbQUaj7KnirjmZ3ra 4WZHABj3Sp+sl3hpPrNAqgd1nuSOxTvxgBRxu3agbu43QQS4VxoeTZzHWSFCitpa75s+V3 8c1jQtZC3Up5nrVVMSJrXGAEPWP/nqY= X-MC-Unique: Tush8DbEMMetgarvDd8x1g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0uOWhp+saqCNjYYeu2/7aRiyZ5BV70RG+ybspQ5dAak=; b=JTelwrMlE1Cjk1Y+r8WfSpVmIQcdEXAdJ9ctqGjdj9upaGIee1Py4M/EQyjQBYdotL gBcb0/x1qUd3shUORyVuDIo1Mb98WrSUWza3T+EaLQTv2CwTsOu6ONhYrrpwgVovWjoI RzbKCZGRBUrn1wQvHYrHqnelDq2EthHJqe04MhQLRPatRxWpWhS7rCsN6zKnrWsI1ceQ wKY5zOap3rNOLWKyaOvnXIf+PjoGv66MSaGpedPyzSIrymr70q7NshOIxz3T8ShlTGHQ vdVXXTN1UGnB6GX+9UxdXAJfumR1FPm3iuK17s/X/E7n3Mnc/NWEDsxu1T1FUllF8DHH SM8w== X-Gm-Message-State: AOAM531tablTIGBn1TnQymB+C4X7PFtV5FBCqt5Yf3C3bUIPYr48Y0kk wUZmWo54FTWkyjDeFn7XLj0YWyhy/duy2RSRUyNbhJJhIUb1jmMN6z3i6vSLEouylr6v+8LaWs5 y2PBGqxqc4cgw7Q== X-Received: by 2002:a1c:4686:: with SMTP id t128mr1478488wma.183.1630566063699; Thu, 02 Sep 2021 00:01:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7uRnvl5NMiCgo8fd31zdmpgDUNAKhX/1UQ81e7SxZUCKxXZXSyeA8FZuRhep03yUFE+Oi4g== X-Received: by 2002:a1c:4686:: with SMTP id t128mr1478470wma.183.1630566063545; Thu, 02 Sep 2021 00:01:03 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Klaus Jensen , Hanna Reitz , Auger Eric , qemu-block@nongnu.org, Stefan Hajnoczi Subject: [PATCH v3 08/11] util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova Date: Thu, 2 Sep 2021 09:00:22 +0200 Message-Id: <20210902070025.197072-9-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902070025.197072-1-philmd@redhat.com> References: <20210902070025.197072-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: 1630566071109100001 Both qemu_vfio_find_fixed_iova() and qemu_vfio_find_temp_iova() return an errno which is unused (or overwritten). Have them propagate eventual errors to callers, returning a boolean (which is what the Error API recommends, see commit e3fe3988d78 "error: Document Error API usage rules" for rationale). Suggested-by: Klaus Jensen Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- util/vfio-helpers.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 306b5a83e48..b93a3d35787 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -677,8 +677,8 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s) return true; } =20 -static int -qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova) +static bool qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, + uint64_t *iova, Error **errp) { int i; =20 @@ -693,14 +693,16 @@ qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t si= ze, uint64_t *iova) s->usable_iova_ranges[i].end - s->low_water_mark + 1 =3D=3D 0)= { *iova =3D s->low_water_mark; s->low_water_mark +=3D size; - return 0; + return true; } } - return -ENOMEM; + error_setg(errp, "fixed iova range not found"); + + return false; } =20 -static int -qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova) +static bool qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, + uint64_t *iova, Error **errp) { int i; =20 @@ -715,10 +717,12 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t siz= e, uint64_t *iova) s->high_water_mark - s->usable_iova_ranges[i].start + 1 =3D=3D= 0) { *iova =3D s->high_water_mark - size; s->high_water_mark =3D *iova; - return 0; + return true; } } - return -ENOMEM; + error_setg(errp, "temporary iova range not found"); + + return false; } =20 /** @@ -762,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, goto out; } if (!temporary) { - if (qemu_vfio_find_fixed_iova(s, size, &iova0)) { + if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) { ret =3D -ENOMEM; goto out; } @@ -776,7 +780,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, } qemu_vfio_dump_mappings(s); } else { - if (qemu_vfio_find_temp_iova(s, size, &iova0)) { + if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) { ret =3D -ENOMEM; goto out; } --=20 2.31.1