diff --git a/TactilityKernel/Include/tactility/device.h b/TactilityKernel/Include/tactility/device.h index ef6d0f5f..64cb25f8 100644 --- a/TactilityKernel/Include/tactility/device.h +++ b/TactilityKernel/Include/tactility/device.h @@ -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; diff --git a/TactilityKernel/Include/tactility/module.h b/TactilityKernel/Include/tactility/module.h index c41a740d..45a8bb71 100644 --- a/TactilityKernel/Include/tactility/module.h +++ b/TactilityKernel/Include/tactility/module.h @@ -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 diff --git a/TactilityKernel/Source/driver.cpp b/TactilityKernel/Source/driver.cpp index 0f96ad15..9fd875cd 100644 --- a/TactilityKernel/Source/driver.cpp +++ b/TactilityKernel/Source/driver.cpp @@ -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; } diff --git a/TactilityKernel/Source/error.cpp b/TactilityKernel/Source/error.cpp index df469e89..7a6e144e 100644 --- a/TactilityKernel/Source/error.cpp +++ b/TactilityKernel/Source/error.cpp @@ -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"; } diff --git a/TactilityKernel/Source/module.cpp b/TactilityKernel/Source/module.cpp index 89747d88..da730df1 100644 --- a/TactilityKernel/Source/module.cpp +++ b/TactilityKernel/Source/module.cpp @@ -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 - } diff --git a/Tests/TactilityKernel/ModuleTest.cpp b/Tests/TactilityKernel/ModuleTest.cpp index 97651870..8af7a531 100644 --- a/Tests/TactilityKernel/ModuleTest.cpp +++ b/Tests/TactilityKernel/ModuleTest.cpp @@ -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); }