diff mbox series

[ovs-dev] lib: Avoid maybe unitialized for found_value variable.

Message ID 20260114112500.2835459-1-amusil@redhat.com
State Accepted
Delegated to: Kevin Traynor
Headers show
Series [ovs-dev] lib: Avoid maybe unitialized for found_value variable. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/cirrus-robot success cirrus build: passed
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Ales Musil Jan. 14, 2026, 11:25 a.m. UTC
The GCC with -fno-omit-frame-pointer -fno-common started to report
the following warning:

In function 'construct_dpdk_mutex_options',
    inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
    inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
    inlined from 'dpdk_init' at lib/dpdk.c:534:23:
lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized [-Werror=maybe-uninitialized]
  220 |             svec_add(args, found_value);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/dpdk.c: In function 'dpdk_init':
lib/dpdk.c:189:21: note: 'found_value' was declared here
  189 |         const char *found_value;
      |                     ^~~~~~~~~~~
cc1: all warnings being treated as errors

Assign NULL to the variable to avoid this warning.

Signed-off-by: Ales Musil <amusil@redhat.com>
---
 lib/dpdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kevin Traynor Jan. 21, 2026, 5:33 p.m. UTC | #1
On 14/01/2026 11:25, Ales Musil via dev wrote:
> The GCC with -fno-omit-frame-pointer -fno-common started to report
> the following warning:
> 
> In function 'construct_dpdk_mutex_options',
>     inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
>     inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
>     inlined from 'dpdk_init' at lib/dpdk.c:534:23:
> lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized [-Werror=maybe-uninitialized]
>   220 |             svec_add(args, found_value);
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> lib/dpdk.c: In function 'dpdk_init':
> lib/dpdk.c:189:21: note: 'found_value' was declared here
>   189 |         const char *found_value;
>       |                     ^~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Assign NULL to the variable to avoid this warning.
> 

Hi Ales,

The patch looks fine. The warning seems to be a false positive as it
would have a value for found_value or continued.

I couldn't reproduce this with GCC 15 or 16, which version of GCC were
you using and did you have any other flags set ?

thanks,
Kevin.

> Signed-off-by: Ales Musil <amusil@redhat.com>
> ---
>  lib/dpdk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/dpdk.c b/lib/dpdk.c
> index 077bdfc09..128098ec2 100644
> --- a/lib/dpdk.c
> +++ b/lib/dpdk.c
> @@ -186,7 +186,7 @@ construct_dpdk_mutex_options(const struct smap *ovs_other_config,
>      int i;
>      for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
>          int found_opts = 0, scan, found_pos = -1;
> -        const char *found_value;
> +        const char *found_value = NULL;
>          struct dpdk_exclusive_options_map *popt = &excl_opts[i];
>  
>          for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
Ales Musil Jan. 22, 2026, 6:59 a.m. UTC | #2
On Wed, Jan 21, 2026 at 6:33 PM Kevin Traynor <ktraynor@redhat.com> wrote:

> On 14/01/2026 11:25, Ales Musil via dev wrote:
> > The GCC with -fno-omit-frame-pointer -fno-common started to report
> > the following warning:
> >
> > In function 'construct_dpdk_mutex_options',
> >     inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
> >     inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
> >     inlined from 'dpdk_init' at lib/dpdk.c:534:23:
> > lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized
> [-Werror=maybe-uninitialized]
> >   220 |             svec_add(args, found_value);
> >       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> > lib/dpdk.c: In function 'dpdk_init':
> > lib/dpdk.c:189:21: note: 'found_value' was declared here
> >   189 |         const char *found_value;
> >       |                     ^~~~~~~~~~~
> > cc1: all warnings being treated as errors
> >
> > Assign NULL to the variable to avoid this warning.
> >
>
> Hi Ales,
>

Hi Kevin,


>
> The patch looks fine. The warning seems to be a false positive as it
> would have a value for found_value or continued.
>

Yes the warning is a false positive.


>
> I couldn't reproduce this with GCC 15 or 16, which version of GCC were
> you using and did you have any other flags set ?
>

# gcc --version
gcc (GCC) 15.2.1 20251211 (Red Hat 15.2.1-5)

And the flags used:
./configure 'CFLAGS= -O1 -fno-omit-frame-pointer -fno-common -g'
--with-dpdk=static --enable-Werror --enable-sparse


>
> thanks,
> Kevin.
>

Regards,
Ales


>
> > Signed-off-by: Ales Musil <amusil@redhat.com>
> > ---
> >  lib/dpdk.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/dpdk.c b/lib/dpdk.c
> > index 077bdfc09..128098ec2 100644
> > --- a/lib/dpdk.c
> > +++ b/lib/dpdk.c
> > @@ -186,7 +186,7 @@ construct_dpdk_mutex_options(const struct smap
> *ovs_other_config,
> >      int i;
> >      for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
> >          int found_opts = 0, scan, found_pos = -1;
> > -        const char *found_value;
> > +        const char *found_value = NULL;
> >          struct dpdk_exclusive_options_map *popt = &excl_opts[i];
> >
> >          for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
>
>
Kevin Traynor Jan. 22, 2026, 11 a.m. UTC | #3
On 22/01/2026 06:59, Ales Musil wrote:
> On Wed, Jan 21, 2026 at 6:33 PM Kevin Traynor <ktraynor@redhat.com> wrote:
> 
>> On 14/01/2026 11:25, Ales Musil via dev wrote:
>>> The GCC with -fno-omit-frame-pointer -fno-common started to report
>>> the following warning:
>>>
>>> In function 'construct_dpdk_mutex_options',
>>>     inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
>>>     inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
>>>     inlined from 'dpdk_init' at lib/dpdk.c:534:23:
>>> lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized
>> [-Werror=maybe-uninitialized]
>>>   220 |             svec_add(args, found_value);
>>>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> lib/dpdk.c: In function 'dpdk_init':
>>> lib/dpdk.c:189:21: note: 'found_value' was declared here
>>>   189 |         const char *found_value;
>>>       |                     ^~~~~~~~~~~
>>> cc1: all warnings being treated as errors
>>>
>>> Assign NULL to the variable to avoid this warning.
>>>
>>
>> Hi Ales,
>>
> 
> Hi Kevin,
> 
> 
>>
>> The patch looks fine. The warning seems to be a false positive as it
>> would have a value for found_value or continued.
>>
> 
> Yes the warning is a false positive.
> 
> 
>>
>> I couldn't reproduce this with GCC 15 or 16, which version of GCC were
>> you using and did you have any other flags set ?
>>
> 
> # gcc --version
> gcc (GCC) 15.2.1 20251211 (Red Hat 15.2.1-5)
> 
> And the flags used:
> ./configure 'CFLAGS= -O1 -fno-omit-frame-pointer -fno-common -g'
> --with-dpdk=static --enable-Werror --enable-sparse
> 

Ah ok, it needs the -O1, it doesn't show up at other optimization
levels. Maybe we should mention that in the commit message. I can add it
on apply if it's fine for you.

thanks,
Kevin.

> 
>>
>> thanks,
>> Kevin.
>>
> 
> Regards,
> Ales
> 
> 
>>
>>> Signed-off-by: Ales Musil <amusil@redhat.com>
>>> ---
>>>  lib/dpdk.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/lib/dpdk.c b/lib/dpdk.c
>>> index 077bdfc09..128098ec2 100644
>>> --- a/lib/dpdk.c
>>> +++ b/lib/dpdk.c
>>> @@ -186,7 +186,7 @@ construct_dpdk_mutex_options(const struct smap
>> *ovs_other_config,
>>>      int i;
>>>      for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
>>>          int found_opts = 0, scan, found_pos = -1;
>>> -        const char *found_value;
>>> +        const char *found_value = NULL;
>>>          struct dpdk_exclusive_options_map *popt = &excl_opts[i];
>>>
>>>          for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
>>
>>
>
Ales Musil Jan. 22, 2026, 11:02 a.m. UTC | #4
On Thu, Jan 22, 2026 at 12:00 PM Kevin Traynor <ktraynor@redhat.com> wrote:

> On 22/01/2026 06:59, Ales Musil wrote:
> > On Wed, Jan 21, 2026 at 6:33 PM Kevin Traynor <ktraynor@redhat.com>
> wrote:
> >
> >> On 14/01/2026 11:25, Ales Musil via dev wrote:
> >>> The GCC with -fno-omit-frame-pointer -fno-common started to report
> >>> the following warning:
> >>>
> >>> In function 'construct_dpdk_mutex_options',
> >>>     inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
> >>>     inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
> >>>     inlined from 'dpdk_init' at lib/dpdk.c:534:23:
> >>> lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized
> >> [-Werror=maybe-uninitialized]
> >>>   220 |             svec_add(args, found_value);
> >>>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>> lib/dpdk.c: In function 'dpdk_init':
> >>> lib/dpdk.c:189:21: note: 'found_value' was declared here
> >>>   189 |         const char *found_value;
> >>>       |                     ^~~~~~~~~~~
> >>> cc1: all warnings being treated as errors
> >>>
> >>> Assign NULL to the variable to avoid this warning.
> >>>
> >>
> >> Hi Ales,
> >>
> >
> > Hi Kevin,
> >
> >
> >>
> >> The patch looks fine. The warning seems to be a false positive as it
> >> would have a value for found_value or continued.
> >>
> >
> > Yes the warning is a false positive.
> >
> >
> >>
> >> I couldn't reproduce this with GCC 15 or 16, which version of GCC were
> >> you using and did you have any other flags set ?
> >>
> >
> > # gcc --version
> > gcc (GCC) 15.2.1 20251211 (Red Hat 15.2.1-5)
> >
> > And the flags used:
> > ./configure 'CFLAGS= -O1 -fno-omit-frame-pointer -fno-common -g'
> > --with-dpdk=static --enable-Werror --enable-sparse
> >
>
> Ah ok, it needs the -O1, it doesn't show up at other optimization
> levels. Maybe we should mention that in the commit message. I can add it
> on apply if it's fine for you.
>

I didn't realize the -O1 is needed, yes I'm fine with that, thanks.


>
> thanks,
> Kevin.
>
> >
> >>
> >> thanks,
> >> Kevin.
> >>
> >
> > Regards,
> > Ales
> >
> >
> >>
> >>> Signed-off-by: Ales Musil <amusil@redhat.com>
> >>> ---
> >>>  lib/dpdk.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/lib/dpdk.c b/lib/dpdk.c
> >>> index 077bdfc09..128098ec2 100644
> >>> --- a/lib/dpdk.c
> >>> +++ b/lib/dpdk.c
> >>> @@ -186,7 +186,7 @@ construct_dpdk_mutex_options(const struct smap
> >> *ovs_other_config,
> >>>      int i;
> >>>      for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
> >>>          int found_opts = 0, scan, found_pos = -1;
> >>> -        const char *found_value;
> >>> +        const char *found_value = NULL;
> >>>          struct dpdk_exclusive_options_map *popt = &excl_opts[i];
> >>>
> >>>          for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
> >>
> >>
> >
>
>
Kevin Traynor Jan. 22, 2026, 2:05 p.m. UTC | #5
On 14/01/2026 11:25, Ales Musil via dev wrote:
> The GCC with -fno-omit-frame-pointer -fno-common started to report
> the following warning:
> 
> In function 'construct_dpdk_mutex_options',
>     inlined from 'construct_dpdk_args' at lib/dpdk.c:238:5,
>     inlined from 'dpdk_init__' at lib/dpdk.c:393:5,
>     inlined from 'dpdk_init' at lib/dpdk.c:534:23:
> lib/dpdk.c:220:13: error: 'found_value' may be used uninitialized [-Werror=maybe-uninitialized]
>   220 |             svec_add(args, found_value);
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> lib/dpdk.c: In function 'dpdk_init':
> lib/dpdk.c:189:21: note: 'found_value' was declared here
>   189 |         const char *found_value;
>       |                     ^~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Assign NULL to the variable to avoid this warning.
> 
> Signed-off-by: Ales Musil <amusil@redhat.com>
> ---
>  lib/dpdk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Updated the commit area (dpdk:), fixed a typo (uninitialized) and added
-O1 to the commit message, as per below:

"
dpdk: Avoid maybe uninitialized for found_value variable.

The GCC with -O1 -fno-omit-frame-pointer -fno-common started to report
the following warning:
"

I pushed to main and backported as far as branch-3.3. Thanks Ales!
diff mbox series

Patch

diff --git a/lib/dpdk.c b/lib/dpdk.c
index 077bdfc09..128098ec2 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -186,7 +186,7 @@  construct_dpdk_mutex_options(const struct smap *ovs_other_config,
     int i;
     for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
         int found_opts = 0, scan, found_pos = -1;
-        const char *found_value;
+        const char *found_value = NULL;
         struct dpdk_exclusive_options_map *popt = &excl_opts[i];
 
         for (scan = 0; scan < MAX_DPDK_EXCL_OPTS