From e01928d186527367dc837d00bcc88e42d8558a92 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 16 Oct 2023 16:57:07 +0300 Subject: [PATCH] Kernel: Fix device identification with all bits as ones If device identification sends all ones, don't initialize the device. --- kernel/kernel/Storage/ATA/ATABus.cpp | 11 +++++++++++ kernel/kernel/Storage/ATA/ATADevice.cpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Storage/ATA/ATABus.cpp b/kernel/kernel/Storage/ATA/ATABus.cpp index eb9d28a66..cd499312e 100644 --- a/kernel/kernel/Storage/ATA/ATABus.cpp +++ b/kernel/kernel/Storage/ATA/ATABus.cpp @@ -73,6 +73,14 @@ namespace Kernel select_delay(); } + static bool identify_all_ones(BAN::Span identify_data) + { + for (size_t i = 0; i < 256; i++) + if (identify_data[i] != 0xFFFF) + return false; + return true; + } + BAN::ErrorOr ATABus::identify(bool secondary, BAN::Span buffer) { select_device(secondary); @@ -117,6 +125,9 @@ namespace Kernel ASSERT(buffer.size() >= 256); read_buffer(ATA_PORT_DATA, buffer.data(), 256); + if (identify_all_ones(buffer)) + return BAN::Error::from_errno(ENODEV); + return type; } diff --git a/kernel/kernel/Storage/ATA/ATADevice.cpp b/kernel/kernel/Storage/ATA/ATADevice.cpp index 81cced962..0eacead6c 100644 --- a/kernel/kernel/Storage/ATA/ATADevice.cpp +++ b/kernel/kernel/Storage/ATA/ATADevice.cpp @@ -71,7 +71,7 @@ namespace Kernel while (model_len > 0 && m_model[model_len - 1] == ' ') model_len--; - dprintln("Initialized disk '{}' {} MB", BAN::StringView(m_model, model_len), total_size() / 1024 / 1024); + dprintln("Initialized disk '{}' {} MiB", BAN::StringView(m_model, model_len), total_size() / 1024 / 1024); add_disk_cache();