Page MenuHomeFreeBSD

netmap: silence -Wdefault-const-init-field-unsafe warning
AcceptedPublic

Authored by arichardson on Sep 16 2025, 5:32 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 12, 6:59 PM
Unknown Object (File)
Fri, Oct 10, 8:41 PM
Unknown Object (File)
Fri, Oct 10, 8:19 AM
Unknown Object (File)
Tue, Sep 30, 7:53 AM
Unknown Object (File)
Mon, Sep 29, 6:55 AM
Unknown Object (File)
Mon, Sep 22, 3:21 PM
Unknown Object (File)
Sun, Sep 21, 3:41 PM
Unknown Object (File)
Sep 16 2025, 5:16 PM
Subscribers

Details

Reviewers
vmaffione
jhb
Summary

The netmap_ring struct starts with various const members and rencent
clang warns about leaving them uninitialized. Having them const in the
first place is highly suspicious since they are updated with various
macros but using hand-coded __DECONST(). But fixing that is a more
invasive change that I am unable to test.

.../freebsd/sys/dev/netmap/netmap_kloop.c:320:21: error: default initialization of an object of type 'struct netmap_ring' with const member leaves the object uninitialized [-Werror,-Wdefault-const-init-field-unsafe]
  320 |         struct netmap_ring shadow_ring; /* shadow copy of the netmap_ring */
      |                            ^
.../freebsd/sys/net/netmap.h:290:16: note: member 'buf_ofs' declared 'const' here
  290 |         const int64_t   buf_ofs;
      |                         ^
Test Plan

Compiles

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 67071
Build 63954: arc lint + arc unit

Event Timeline

Thanks.

The fields are const because we want to prevent changes after they are initialized. Of course you need to drop the const to initialize them.
They are not meant to be updated.

This revision is now accepted and ready to land.Wed, Sep 17, 9:57 PM