PR feedback fixes

This commit is contained in:
Ken Van Hoeylandt 2026-01-30 23:34:18 +01:00
parent 1f6df739e1
commit 251fb1865b
6 changed files with 9 additions and 53 deletions

View File

@ -53,7 +53,7 @@ struct Device {
/**
* Holds a device pointer and a compatible string.
* The device must not be constructed, added or started yet.
* This is mused by the devicetree code generator and the application init sequence.
* This is used by the devicetree code generator and the application init sequence.
*/
struct CompatibleDevice {
struct Device* device;

View File

@ -97,16 +97,6 @@ bool module_is_started(struct Module* module);
*/
error_t module_stop(struct Module* module);
error_t kernel_module_parent_construct(void);
error_t kernel_module_parent_destruct(void);
/**
* @brief Get the kernel module parent. This parent is the root parent for kernel modules.
* @return the kernel module parent
*/
struct ModuleParent* get_kernel_module_parent(void);
#ifdef __cplusplus
}
#endif

View File

@ -108,14 +108,10 @@ error_t driver_destruct(Driver* driver) {
LOG_W(TAG, "Failed to remove driver from ledger: %s", driver->name);
}
// Copy the mutex so we can free the driver's memory and unlock the mutex later
struct Mutex mutex_copy;
memcpy(&mutex_copy, &get_internal(driver)->mutex, sizeof(Mutex));
driver_unlock(driver);
delete get_internal(driver);
driver->internal = nullptr;
mutex_unlock(&mutex_copy);
return ERROR_NONE;
}

View File

@ -27,6 +27,8 @@ const char* error_to_string(error_t error) {
return "out of memory";
case ERROR_NOT_SUPPORTED:
return "not supported";
case ERROR_NOT_ALLOWED:
return "not allowed";
default:
return "unknown";
}

View File

@ -98,23 +98,5 @@ error_t module_stop(struct Module* module) {
#pragma endregion
#pragma region kernel_module_parent;
static struct ModuleParent kernel_module_parent = { "kernel", { nullptr } };
error_t kernel_module_parent_construct(void) {
return module_parent_construct(&kernel_module_parent);
}
error_t kernel_module_parent_destruct(void) {
return module_parent_destruct(&kernel_module_parent);
}
struct ModuleParent* get_kernel_module_parent(void) {
return &kernel_module_parent;
}
#pragma endregion
}

View File

@ -82,8 +82,9 @@ TEST_CASE("Module parent management") {
CHECK_EQ(module_set_parent(&module, &parent1), ERROR_NONE);
CHECK_EQ(module.internal.parent, &parent1);
module_parent_destruct(&parent1);
module_parent_destruct(&parent2);
CHECK_EQ(module_set_parent(&module, nullptr), ERROR_NONE);
CHECK_EQ(module_parent_destruct(&parent1), ERROR_NONE);
CHECK_EQ(module_parent_destruct(&parent2), ERROR_NONE);
}
TEST_CASE("Module lifecycle") {
@ -154,21 +155,6 @@ TEST_CASE("Module lifecycle") {
test_stop_result = ERROR_NONE;
CHECK_EQ(module_stop(&module), ERROR_NONE);
module_parent_destruct(&parent);
}
TEST_CASE("Kernel module parent") {
// Ensure it's constructed
REQUIRE_EQ(kernel_module_parent_construct(), ERROR_NONE);
struct ModuleParent* kernel_parent = get_kernel_module_parent();
CHECK_NE(kernel_parent, nullptr);
CHECK_NE(kernel_parent->internal.data, nullptr);
// Multiple calls return the same
CHECK_EQ(get_kernel_module_parent(), kernel_parent);
// Test destruction
CHECK_EQ(kernel_module_parent_destruct(), ERROR_NONE);
CHECK_EQ(kernel_parent->internal.data, nullptr);
CHECK_EQ(module_set_parent(&module, nullptr), ERROR_NONE);
CHECK_EQ(module_parent_destruct(&parent), ERROR_NONE);
}