K 10 svn:author V 2 mw K 8 svn:date V 27 2023-07-31T12:57:25.196439Z K 7 svn:log V 1180 ena: Initialize statistics before the interface is available In [1], the FBSD community exposed a bug in the fbsd/ena driver. Bug description: ---------------- Current function call order is as follows: 1. ena_attach() 1.1. ena_setup_ifnet() 1.1.1. Registration of ena_get_counter() 1.1.2. ether_ifattach(ifp, adapter->mac_addr); 1.2. Statistics allocation and initialization. At point 1.1.2, when ether_ifattach() returns, the interface is available, and stats can be read before they are allocated, leading to kernel panic. Also fixed a potential memory leak by freeing the stats since they were not freed in case the following calls failed. Fix: ---- This commit moves the statistics allocation and initialization to happen before ena_setup_ifnet() [1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=268934 Fixes: 9b8d05b8ac78 ("Add support for Amazon Elastic Network Adapter (ENA) NIC") Fixes: 30217e2dff10 ("Rework counting of hardware statistics in ENA driver") MFC after: 2 weeks Sponsored by: Amazon, Inc. (cherry picked from commit b9e80b5280b75f2c641d680245df44b8ff26a7b0) Git Hash: 383cf7052a29ab3f4d1bdffb888696546e4f0fe4 Git Author: osamaabb@amazon.com END