From patchwork Thu Apr 4 17:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 139105 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A202B43DFB; Thu, 4 Apr 2024 19:15:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B40CF40A6E; Thu, 4 Apr 2024 19:15:20 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 105FB4064A for ; Thu, 4 Apr 2024 19:15:15 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 63C3A20E97C1; Thu, 4 Apr 2024 10:15:14 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 63C3A20E97C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1712250914; bh=rD+L0VBEA4ijIJdqdd449HN9OEIpZijzzM7uh0U3AQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qrnREoKVqff0DtjBVN7ryRKKIj3Yj3IKzzmZmLHi1J/fhN9E50nqWjQHZXeexfm3C 1XVUskKQaMPawK8I688aQVpFBysb1rp5mv9tjftuVcJxnhyKMtWSP8U4fjF3hWtOJY Tw9KaNbCNxhTIH3rCvsILpUKmCXHeotaQCvaU6ME= From: Tyler Retzlaff To: dev@dpdk.org Cc: Bruce Richardson , Stephen Hemminger , Thomas Monjalon , =?utf-8?q?Morten_Br=C3=B8rup?= , Tyler Retzlaff Subject: [PATCH 3/4] vhost: use alloca instead of vla sizeof Date: Thu, 4 Apr 2024 10:15:12 -0700 Message-Id: <1712250913-1977-4-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1712250913-1977-1-git-send-email-roretzla@linux.microsoft.com> References: <20231107193220.GA15232@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <1712250913-1977-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org RFC sample illustrating conversion of VLA to alloca() where sizeof(array) was in use. Signed-off-by: Tyler Retzlaff --- lib/vhost/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 96b3ab5..cedcfb2 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -110,7 +110,8 @@ struct vhost_user { { struct iovec iov; struct msghdr msgh; - char control[CMSG_SPACE(max_fds * sizeof(int))]; + const size_t control_sz = sizeof(char) * CMSG_SPACE(max_fds * sizeof(int)); + char *control = alloca(control_sz); struct cmsghdr *cmsg; int got_fds = 0; int ret; @@ -124,7 +125,7 @@ struct vhost_user { msgh.msg_iov = &iov; msgh.msg_iovlen = 1; msgh.msg_control = control; - msgh.msg_controllen = sizeof(control); + msgh.msg_controllen = control_sz; ret = recvmsg(sockfd, &msgh, 0); if (ret <= 0) {