On 6/5/2026 12:09 PM, Ilya Maximets wrote:
> On 6/4/26 11:51 PM, Pierrick Bouvier wrote:
>> Seems like a false positive, easily fix by explicitly initializing
>> variable to NULL.
>>
>> In function ‘af_xdp_read_poll’,
>> inlined from ‘net_init_af_xdp’ at ../net/af-xdp.c:546:5:
>> ../net/af-xdp.c:78:10: error: ‘s’ may be used uninitialized
>> [-Werror=maybe-uninitialized]
>> 78 | if (s->read_poll != enable) {
>> | ~^~~~~~~~~~~
>> ../net/af-xdp.c: In function ‘net_init_af_xdp’:
>> ../net/af-xdp.c:461:17: note: ‘s’ was declared here
>> 461 | AFXDPState *s;
>> |
>>
>
> I guess the 'nc0 && !inhibit' check is what making things confusing.
> I'd suggest to remove the nc0 check and move the upcast out of the
> if statement. Then maybe collapse the two if statements into one.
>
> It seems cleaner than just silencing the warning.
>
> Will that solve the problem?
>
Such patch?
```
diff --git a/net/af-xdp.c b/net/af-xdp.c
index 72d75748c6d..b25c7e69d7e 100644
--- a/net/af-xdp.c
+++ b/net/af-xdp.c
@@ -458,7 +458,7 @@ int net_init_af_xdp(const Netdev *netdev,
g_autofree int *sock_fds = NULL;
int i, queues;
Error *err = NULL;
- AFXDPState *s = NULL;
+ AFXDPState *s;
bool inhibit;
ifindex = if_nametoindex(opts->ifname);
@@ -533,8 +533,9 @@ int net_init_af_xdp(const Netdev *netdev,
}
}
- if (nc0 && !inhibit) {
- s = DO_UPCAST(AFXDPState, nc, nc0);
+ s = DO_UPCAST(AFXDPState, nc, nc0);
+
+ if (!inhibit) {
if (bpf_xdp_query_id(s->ifindex, s->xdp_flags, &prog_id) ||
!prog_id) {
error_setg_errno(&err, errno,
"no XDP program loaded on '%s', ifindex: %d",
```
It solves the issue indeed, and we are guaranteed it's correct since
queues >= 1. Another thing that work also, and is more concise is:
```
@@ -533,6 +533,8 @@ int net_init_af_xdp(const Netdev *netdev,
}
}
+ g_assert(queues > 0);
+
if (nc0 && !inhibit) {
s = DO_UPCAST(AFXDPState, nc, nc0);
if (bpf_xdp_query_id(s->ifindex, s->xdp_flags, &prog_id) ||
!prog_id) {
```
Which version do you prefer?
> Best regards, Ilya Maximets.
>
>> Signed-off-by: Pierrick Bouvier <[email protected]>
>> ---
>> net/af-xdp.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/af-xdp.c b/net/af-xdp.c
>> index 1ffd6363a8c..72d75748c6d 100644
>> --- a/net/af-xdp.c
>> +++ b/net/af-xdp.c
>> @@ -458,7 +458,7 @@ int net_init_af_xdp(const Netdev *netdev,
>> g_autofree int *sock_fds = NULL;
>> int i, queues;
>> Error *err = NULL;
>> - AFXDPState *s;
>> + AFXDPState *s = NULL;
>> bool inhibit;
>>
>> ifindex = if_nametoindex(opts->ifname);
>
Regards,
Pierrick