Skip to contentSkip to conversation

eal: fix unitialized data warning

PATCH Applied Stephen Hemminger 3 participants 6 messages Nov 27, 2019 – Dec 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: fix unitialized data warning

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/linux/eal/eal_interrupts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linux/eal/eal_interrupts.c +1 -1
index 1955324d3045..2cd537ba4492 100644
@@ -1045,7 +1045,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds)
 static __attribute__((noreturn)) void *
 eal_intr_thread_main(__rte_unused void *arg)
 {
-	struct epoll_event ev;
+	struct epoll_event ev = { };
 
 	/* host thread, never break out */
 	for (;;) {
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Stephen Hemminger

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/linux/eal/eal_interrupts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linux/eal/eal_interrupts.c +0 -0
index 1955324d3045..2cd537ba4492 100644

lib/librte_eal/linux/eal/eal_interrupts.c eal_intr_handle_interrupts(int pfd, unsigned totalfds) · line 1051

Quoted 8 lines
lib/librte_eal/linux/eal/eal_interrupts.c +1 -1
@@ -1045,7 +1045,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds)
 static __attribute__((noreturn)) void *
 eal_intr_thread_main(__rte_unused void *arg)
 {
-       struct epoll_event ev;
+       struct epoll_event ev = { };
 
        /* host thread, never break out */
        for (;;) {

typedef union epoll_data
{
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;

struct epoll_event
{
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
} __EPOLL_PACKED;

static __attribute__((noreturn)) void *
eal_intr_thread_main(__rte_unused void *arg)

{
        struct epoll_event ev;
[...]
                        ev.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP;
                        ev.data.fd = src->intr_handle.fd;

[...]
if (epoll_ctl(pfd, EPOLL_CTL_ADD,
src->intr_handle.fd, &ev) < 0){

So the uninitialised part is because we only set an int in the union. False positive from valgrind, but the fix is quite simple.

Signature · 1 line
David Marchand
#2 lore raw
Quoted 49 lines · On Fri, 29 Nov 2019 09:25:15 +0100 David Marchand <[email protected]>…
Quoted 16 lines · Stephen Hemminger

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/linux/eal/eal_interrupts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linux/eal/eal_interrupts.c +0 -0
index 1955324d3045..2cd537ba4492 100644

lib/librte_eal/linux/eal/eal_interrupts.c eal_intr_handle_interrupts(int pfd, unsigned totalfds) · line 1051

Quoted 8 lines
lib/librte_eal/linux/eal/eal_interrupts.c +1 -1
@@ -1045,7 +1045,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds)
 static __attribute__((noreturn)) void *
 eal_intr_thread_main(__rte_unused void *arg)
 {
-       struct epoll_event ev;
+       struct epoll_event ev = { };
 
        /* host thread, never break out */
        for (;;) {  

typedef union epoll_data
{
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;

struct epoll_event
{
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
} __EPOLL_PACKED;

static __attribute__((noreturn)) void *
eal_intr_thread_main(__rte_unused void *arg)

{
        struct epoll_event ev;
[...]
                        ev.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP;
                        ev.data.fd = src->intr_handle.fd;
Quoted 8 lines

[...]
if (epoll_ctl(pfd, EPOLL_CTL_ADD,
src->intr_handle.fd, &ev) < 0){

So the uninitialised part is because we only set an int in the union. False positive from valgrind, but the fix is quite simple.

Agreed it is a false positive because the kernel is not going to care about the unused bits in the union. But I wanted to make the application run clean under valgrind. Otherwise, it is hard to find the real warnings in surrounding noise.

Acked-by on v1 1/1 Applied
#3 lore raw
In reply to Stephen Hemminger

Fixed title s/unitialized/uninitialized/

Quoted 3 lines · Stephen Hemminger

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Added a note on it being a Valgrind false positive.

Quoted 4 lines
Fixes af75078fece3 ("first public release")

Applied, thanks.

--
David Marchand

#4 lore raw
Quoted 11 lines · David Marchand

Fixed title s/unitialized/uninitialized/

Quoted 3 lines · Stephen Hemminger

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Added a note on it being a Valgrind false positive.

Quoted 7 lines
Quoted 4 lines
Fixes af75078fece3 ("first public release")

Applied, thanks.

It breaks build on RHEL 7.6 gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36):

lib/librte_eal/linux/eal/eal_interrupts.c: In function ‘eal_intr_thread_main’:
lib/librte_eal/linux/eal/eal_interrupts.c:1048:9: error: missing initializer for field ‘events’ of ‘struct epoll_event’ [-Werror=missing-field-initializers]

   struct epoll_event ev = { };
          ^

In file included from lib/librte_eal/linu/eal/eal_interrupts.c:15:0:
/usr/include/sys/epoll.h:89:12: note: ‘events’ declared here
uint32_t events; /* Epoll events */
^

#5 lore raw
Quoted 28 lines · Andrew Rybchenko
Quoted 11 lines · David Marchand

Fixed title s/unitialized/uninitialized/

Quoted 3 lines · Stephen Hemminger

Valgrind reports that eal interrupt thread is calling epoll_ctl with uninitialized data. Trivial to fix by initializing it.

Added a note on it being a Valgrind false positive.

Quoted 7 lines
Quoted 4 lines
Fixes af75078fece3 ("first public release")

Applied, thanks.

It breaks build on RHEL 7.6 gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36):

lib/librte_eal/linux/eal/eal_interrupts.c: In function ‘eal_intr_thread_main’:
lib/librte_eal/linux/eal/eal_interrupts.c:1048:9: error: missing initializer for field ‘events’ of ‘struct epoll_event’ [-Werror=missing-field-initializers]

Quoted 6 lines
   struct epoll_event ev = { };
          ^

In file included from lib/librte_eal/linu/eal/eal_interrupts.c:15:0:
/usr/include/sys/epoll.h:89:12: note: ‘events’ declared here
uint32_t events; /* Epoll events */
^

Erf, indeed, I ran the tests on a different system than my laptop... Need more coffee, those initializers are always a pain. I'll go with a memset.

Best first commit for a release, I suppose.

--
David Marchand