From nobody Mon Feb 9 09:29:48 2026 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=1620398642; cv=none; d=zohomail.com; s=zohoarc; b=ZywxJ9QS63aSPokbvScSKYcTcd//ukuc6EfrNY4ttV5Ml4TlQz/n+OdaBxu6j6NrOL/5PTxNHf+ujyKfRpVvH8ambCRzxUE1Sa7CFVKwVGKJ1Vy9/qof0S4wmy4aCk7ywMo4J6DoEr3FtX2eu2a4i1pqeytxiHCYhwshYxbMSrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620398642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0aEFCYf2HLWMKyL3vu/hasMYJfVES1sketKqALkOn8E=; b=nkRipTfEcaMzKVqeeA+B5G2lo06fZcbAOX5Ud/bb0vhoMnsqfdgcsu9cN9+MNiZMSRedJBfBFNWCDy32uYG7rdFidM2jn8YPdA4jKoECKnokpvmDCBo0g/eguI/F/JPFLqnW7Zemyh8+I95AkYs4h/ArAlKJkvJ47HPRhHFmYEY= 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 1620398642212975.2462757887454; Fri, 7 May 2021 07:44:02 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-37EddMzOOgGKwZCb9J6YlQ-1; Fri, 07 May 2021 10:43:57 -0400 Received: by mail-wr1-f70.google.com with SMTP id d20-20020adfc3d40000b029010e1a640bbfso3692720wrg.21 for ; Fri, 07 May 2021 07:43:56 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id q12sm9079882wrx.17.2021.05.07.07.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398640; 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=0aEFCYf2HLWMKyL3vu/hasMYJfVES1sketKqALkOn8E=; b=FRnr4im3S2xBtHFd49O9DhNEsMYlkEOzBgA/MsRyX3ulC0BD30mdDMHR5uaafLvAkNJmqL AeJIcs1/mb8l/Pw2kezoDDnZo/xmWllroTpauu8OyYcob2TbRgHFX7KFw3nlj9RtNDxt4l l6bNwuE4K6wc4aAdpYZlKCBo3i4xzi4= X-MC-Unique: 37EddMzOOgGKwZCb9J6YlQ-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=0aEFCYf2HLWMKyL3vu/hasMYJfVES1sketKqALkOn8E=; b=dOmIUHtfNZmqGpGKFeXbQxxoM/t+27lzNCjLEEstzxcKBG5fdDpICHoSQ8B0siUQXY 0kxkaRQfLW5RoUZ75CyxYc4xEQ9wdvHVv6DK1LJmlDVTdfL0aRMKUoZKx5XfCzWFZv5h aOVbaD6aVw7fDHyQqVwSzamSWqnWVm26gRuGm8/dMJ/rtO0ry5xP5od7fvRTwavH+j// KdAEExj9aIIyhoE2y5GiAXvskeFfOhWEOgCeuIWL6IBja2Q++9JFOSV34eIu6+T3gyOi HY+btDwEnPCxp3oa0o6ENvmHu0+OifmEuMdm6osZcavRSixTcNAUgGZijOsU2UXYyh1Z nX8w== X-Gm-Message-State: AOAM5339r+ZiTGdwxrUfcnFGmSHTJNQIEchrzSc9iPJJLgMJIwUsP6B1 x3iivD+iLBkEIG0C6nmwupnfqpgR2CPzFFg1WjdqC+70YMMDzWo9ukWcd5YWTAqXsJvCqBlly3t OXeddkhCAAwUM2g== X-Received: by 2002:a1c:e912:: with SMTP id q18mr21780857wmc.59.1620398635880; Fri, 07 May 2021 07:43:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuxDw+Z5ejCnnQGzrscKMxB38QYBMH5R95NR75yg2DPkosJ/eaQfVzqQPNjxuH9z1wWTJ1gA== X-Received: by 2002:a1c:e912:: with SMTP id q18mr21780843wmc.59.1620398635604; Fri, 07 May 2021 07:43:55 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , qemu-ppc@nongnu.org, Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_locked() Date: Fri, 7 May 2021 16:43:06 +0200 Message-Id: <20210507144315.1994337-9-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-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) Avoid initializing variables too early, since there is 2 possible failure points before they get used. Move them after the lock_iovec() call. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/syscall.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7c5c821f48d..593241362a9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3379,15 +3379,8 @@ static abi_long do_sendrecvmsg_locked(int fd, struct= target_msghdr *msgp, msg.msg_name =3D NULL; msg.msg_namelen =3D 0; } - msg.msg_controllen =3D 2 * tswapal(msgp->msg_controllen); - msg.msg_control =3D alloca(msg.msg_controllen); - memset(msg.msg_control, 0, msg.msg_controllen); - - msg.msg_flags =3D tswap32(msgp->msg_flags); =20 count =3D tswapal(msgp->msg_iovlen); - target_vec =3D tswapal(msgp->msg_iov); - if (count > IOV_MAX) { /* sendrcvmsg returns a different errno for this condition than * readv/writev, so we must catch it here before lock_iovec() does. @@ -3396,14 +3389,20 @@ static abi_long do_sendrecvmsg_locked(int fd, struc= t target_msghdr *msgp, goto out2; } =20 + target_vec =3D tswapal(msgp->msg_iov); vec =3D lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, target_vec, count, send); if (vec =3D=3D NULL) { ret =3D -host_to_target_errno(errno); goto out2; } + msg.msg_iovlen =3D count; msg.msg_iov =3D vec; + msg.msg_flags =3D tswap32(msgp->msg_flags); + msg.msg_controllen =3D 2 * tswapal(msgp->msg_controllen); + msg.msg_control =3D alloca(msg.msg_controllen); + memset(msg.msg_control, 0, msg.msg_controllen); =20 if (send) { if (fd_trans_target_to_host_data(fd)) { --=20 2.26.3