summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@colorado.edu>2020-11-16 17:41:46 -0700
committerAndreas Kling <kling@serenityos.org>2020-11-20 21:18:14 +0100
commitbdf3baa8ac76ebdabd7826a8453fefe07f3f9dc9 (patch)
treee821970b71b01b661cfe58efb6da15ea62522499 /Kernel
parent700fe315cf18836452c9157d004e4b869f7f2ae3 (diff)
downloadserenity-bdf3baa8ac76ebdabd7826a8453fefe07f3f9dc9.zip
MACAddress: AK::Array as member variable instead of C-array
Problem: - C-style arrays do not automatically provide bounds checking and are less type safe overall. - `__builtin_memcmp` is not a constant expression in the current gcc. Solution: - Change private m_data to be AK::Array. - Eliminate constructor from C-style array. - Change users of the C-style array constructor to use the default constructor. - Change `operator==()` to be a hand-written comparison loop and let the optimizer figure out to use `memcmp`.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Net/E1000NetworkAdapter.cpp3
-rw-r--r--Kernel/Net/RTL8139NetworkAdapter.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp
index e884e297c3..8f0e8aef84 100644
--- a/Kernel/Net/E1000NetworkAdapter.cpp
+++ b/Kernel/Net/E1000NetworkAdapter.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <AK/MACAddress.h>
#include <Kernel/IO.h>
#include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Thread.h>
@@ -258,7 +259,7 @@ u32 E1000NetworkAdapter::read_eeprom(u8 address)
void E1000NetworkAdapter::read_mac_address()
{
if (m_has_eeprom) {
- u8 mac[6];
+ MACAddress mac {};
u32 tmp = read_eeprom(0);
mac[0] = tmp & 0xff;
mac[1] = tmp >> 8;
diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp
index efb26fdb92..f0faa21cd8 100644
--- a/Kernel/Net/RTL8139NetworkAdapter.cpp
+++ b/Kernel/Net/RTL8139NetworkAdapter.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <AK/MACAddress.h>
#include <Kernel/IO.h>
#include <Kernel/Net/RTL8139NetworkAdapter.h>
@@ -284,7 +285,7 @@ void RTL8139NetworkAdapter::reset()
void RTL8139NetworkAdapter::read_mac_address()
{
- u8 mac[6];
+ MACAddress mac {};
for (int i = 0; i < 6; i++)
mac[i] = in8(REG_MAC + i);
set_mac_address(mac);