[v14,03/81] eal/common: remove use of VLAs

Message ID 1736540620-21764-4-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series remove use of VLAs for Windows |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie Jan. 10, 2025, 8:22 p.m. UTC
From: Konstantin Ananyev <konstantin.ananyev@huawei.com>

1) ../lib/eal/common/eal_common_proc.c:695:15
    : warning: variable length array used

As msg->num_fds should not exceed RTE_MP_MAX_FD_NUM, replaced
it with fixed size array.

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_proc.c | 5 +++--
 lib/eal/meson.build              | 8 ++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger Jan. 11, 2025, 1:14 a.m. UTC | #1
On Fri, 10 Jan 2025 12:22:22 -0800
Andre Muezerie <andremue@linux.microsoft.com> wrote:

> diff --git a/lib/eal/meson.build b/lib/eal/meson.build
> index e1d6c4cf17..352db049e9 100644
> --- a/lib/eal/meson.build
> +++ b/lib/eal/meson.build
> @@ -31,3 +31,11 @@ endif
>  if is_freebsd
>      annotate_locks = false
>  endif
> +
> +warning_flags = ['-Wvla']
> +
> +foreach arg: warning_flags
> +    if cc.has_argument(arg)
> +        cflags += arg
> +    endif
> +endforeach
> -- 

Could we enable it for all libs and only turn it off as required?
  
Andre Muezerie Jan. 13, 2025, 9:30 p.m. UTC | #2
On Fri, Jan 10, 2025 at 05:14:05PM -0800, Stephen Hemminger wrote:
> On Fri, 10 Jan 2025 12:22:22 -0800
> Andre Muezerie <andremue@linux.microsoft.com> wrote:
> 
> > diff --git a/lib/eal/meson.build b/lib/eal/meson.build
> > index e1d6c4cf17..352db049e9 100644
> > --- a/lib/eal/meson.build
> > +++ b/lib/eal/meson.build
> > @@ -31,3 +31,11 @@ endif
> >  if is_freebsd
> >      annotate_locks = false
> >  endif
> > +
> > +warning_flags = ['-Wvla']
> > +
> > +foreach arg: warning_flags
> > +    if cc.has_argument(arg)
> > +        cflags += arg
> > +    endif
> > +endforeach
> > -- 
> 
> Could we enable it for all libs and only turn it off as required?

Yes. Although the data types in meson are additive only, we can
add -Wno-vla to cancel a -Wvla already present. Let me send out a
new series with this change.
  
Andre Muezerie Jan. 14, 2025, 2:57 p.m. UTC | #3
On Mon, Jan 13, 2025 at 01:30:12PM -0800, Andre Muezerie wrote:
> On Fri, Jan 10, 2025 at 05:14:05PM -0800, Stephen Hemminger wrote:
> > On Fri, 10 Jan 2025 12:22:22 -0800
> > Andre Muezerie <andremue@linux.microsoft.com> wrote:
> > 
> > > diff --git a/lib/eal/meson.build b/lib/eal/meson.build
> > > index e1d6c4cf17..352db049e9 100644
> > > --- a/lib/eal/meson.build
> > > +++ b/lib/eal/meson.build
> > > @@ -31,3 +31,11 @@ endif
> > >  if is_freebsd
> > >      annotate_locks = false
> > >  endif
> > > +
> > > +warning_flags = ['-Wvla']
> > > +
> > > +foreach arg: warning_flags
> > > +    if cc.has_argument(arg)
> > > +        cflags += arg
> > > +    endif
> > > +endforeach
> > > -- 
> > 
> > Could we enable it for all libs and only turn it off as required?
> 
> Yes. Although the data types in meson are additive only, we can
> add -Wno-vla to cancel a -Wvla already present. Let me send out a
> new series with this change.

Series v16 has the changes proposed.

There was only one failure reported now, which seems infra-related:
"The requested resource was not found on this server":
https://mails.dpdk.org/archives/test-report/2025-January/842300.html

Let me know if any action is needed from my side.

Thanks,

Andre Muezerie
  

Patch

diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
index d24093937c..201973c5db 100644
--- a/lib/eal/common/eal_common_proc.c
+++ b/lib/eal/common/eal_common_proc.c
@@ -692,7 +692,8 @@  send_msg(const char *dst_path, struct rte_mp_msg *msg, int type)
 	struct sockaddr_un dst;
 	struct mp_msg_internal m;
 	int fd_size = msg->num_fds * sizeof(int);
-	char control[CMSG_SPACE(fd_size)];
+	const int32_t control_sz = CMSG_SPACE(fd_size);
+	char control[CMSG_SPACE(sizeof(msg->fds))];
 
 	m.type = type;
 	memcpy(&m.msg, msg, sizeof(*msg));
@@ -712,7 +713,7 @@  send_msg(const char *dst_path, struct rte_mp_msg *msg, int type)
 	msgh.msg_iov = &iov;
 	msgh.msg_iovlen = 1;
 	msgh.msg_control = control;
-	msgh.msg_controllen = sizeof(control);
+	msgh.msg_controllen = control_sz;
 
 	cmsg = CMSG_FIRSTHDR(&msgh);
 	cmsg->cmsg_len = CMSG_LEN(fd_size);
diff --git a/lib/eal/meson.build b/lib/eal/meson.build
index e1d6c4cf17..352db049e9 100644
--- a/lib/eal/meson.build
+++ b/lib/eal/meson.build
@@ -31,3 +31,11 @@  endif
 if is_freebsd
     annotate_locks = false
 endif
+
+warning_flags = ['-Wvla']
+
+foreach arg: warning_flags
+    if cc.has_argument(arg)
+        cflags += arg
+    endif
+endforeach