From nobody Wed Nov 19 10:09:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1615392142; cv=none; d=zohomail.com; s=zohoarc; b=ka6qgS9iIB/zf9J3n6rw+Q+j4k2Sk/u3L+7EzHvK75jTSExXkW6f8AZ3cASxlrWKO9M6zzBvbvnBDExFCsthYubixZYQnkGfoOiRUod6RcbS9ZPLo/vZ/G5bqJ4BI6Sv186VcwtRHP24liAoj9MJNrA7V6258u5eEbnFZMTbGuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392142; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=WFbueJ8FUHrdrO7+H4P+SHVPl9vqzYVQ2TavS6IWeR6BYm4y1usrSRsLucSho8SebauWWWNlTUBvlNEVaVFUKo9C3SGA4CFdh+ga0AmGFLI6nrhPGlgP62gFBYFM3PIwNXg58iepeMFXte76w9vy8poab5qN1y8OYstxERlEhU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 161539214242571.26859321989377; Wed, 10 Mar 2021 08:02:22 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-iiAc5UWXMEq-XohSlowNDw-1; Wed, 10 Mar 2021 11:02:19 -0500 Received: by mail-ed1-f69.google.com with SMTP id v27so8597268edx.1 for ; Wed, 10 Mar 2021 08:02:19 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id p9sm1225756eds.66.2021.03.10.08.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:02:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392140; 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=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=GaSJnrLGNPRo0kgDQDohq/cQR3xHOJCHiE6hfsvmv2Xz1GCi63A9fNbjIhz54WkFsJ8f+w T2ZI+pW39xZ8ZIrIdjYKPbnuIDD0OEqfVHI0SK/KFEoQL7wNnQIMrgFjNjt8tApKK8uzqP JId61JCyblf6ChYSIAXwy/yNWPB6oQw= X-MC-Unique: iiAc5UWXMEq-XohSlowNDw-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=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=gHiJciOFUwIzrXXDq4Alt2OCTOFUjrsKKVhbJQx4Ts++dGUOBZnJQgLUQ+oPno3smY cYK1zC7YzMB3iYygGF9NrV1wPrHXnU+O3om6y+QhgZzHZH0AmIiqKLqI+oFsCob98irQ P2Bym0BSvHIB+SgrLiuyzhQqoNP7s62ofoRLI8Vn5VX4KYMlPM0LSVg4cfNIm8TKT3ep bIbtN3o98lqB3ww/EKsaEP6aCpzSNwwGSyNtP293PX5mtDY/Hmm7fgKgziA6WBkcjy9f bzfFpvwmpTSYME6lRXBIr/5P8M/qN5oz4Yhqada+uZjNG2fqFrK4BZ56ei41LsbrkybJ wCKA== X-Gm-Message-State: AOAM530dUHLUhHoqcIS5Ysh2kaL4cSfeTsZ4xHVVdIFob+aw8/GoTzgU /6QfqHciDYgCKHNlEuh2hcv8ivHq5wmFp3RejqcyBd97JSAft1qAV1lBzcz+glul3W6bTfERd4E xzeWczQ7DhVhbWA== X-Received: by 2002:a17:906:5797:: with SMTP id k23mr4526768ejq.515.1615392135681; Wed, 10 Mar 2021 08:02:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyodObdZLcjX2jXPfIqYovta4vHSS15YC8kxw0WH9M25h2VAUIToiumsK9emk+Cwym6tF58WA== X-Received: by 2002:a17:906:5797:: with SMTP id k23mr4526749ejq.515.1615392135546; Wed, 10 Mar 2021 08:02:15 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 7/7] net/eth: Add an assert() and invert if() statement to simplify code Date: Wed, 10 Mar 2021 17:01:35 +0100 Message-Id: <20210310160135.1148272-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) To simplify the function body, invert the if() statement, returning earlier. Since we already checked there is enough data in the iovec buffer, simply add an assert() call to consume the bytes_read variable. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- net/eth.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/eth.c b/net/eth.c index b150d73c13a..c0a5ca12be2 100644 --- a/net/eth.c +++ b/net/eth.c @@ -416,16 +416,14 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int= pkt_frags, bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset, &rt_hdr, sizeof(rt_hdr)); assert(bytes_read =3D=3D sizeof(rt_hdr)); - - if ((rt_hdr.rtype =3D=3D 2) && (rt_hdr.segleft =3D=3D 1)) { - bytes_read =3D iov_to_buf(pkt, pkt_frags, - ext_hdr_offset + sizeof(*ext_hdr), - dst_addr, sizeof(*dst_addr)); - - return bytes_read =3D=3D sizeof(*dst_addr); + if ((rt_hdr.rtype !=3D 2) || (rt_hdr.segleft !=3D 1)) { + return false; } + bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset + sizeof(rt_h= dr), + dst_addr, sizeof(*dst_addr)); + assert(bytes_read =3D=3D sizeof(*dst_addr)); =20 - return false; + return true; } =20 static bool --=20 2.26.2