1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2002-2023 6f08c3bdfSopenharmony_ci * Author: Madhu T L <madhu.tarikere@wipro.com> 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/*\ 10f08c3bdfSopenharmony_ci * [Description] 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Basic test for delete_module(2). 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * Install dummy_del_mod.ko and delete it with delete_module(2). 15f08c3bdfSopenharmony_ci */ 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci#include "tst_module.h" 19f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#define MODULE_NAME "dummy_del_mod" 22f08c3bdfSopenharmony_ci#define MODULE_NAME_KO MODULE_NAME ".ko" 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic int module_loaded; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_cistatic void do_delete_module(void) 27f08c3bdfSopenharmony_ci{ 28f08c3bdfSopenharmony_ci if (!module_loaded) { 29f08c3bdfSopenharmony_ci tst_module_load(MODULE_NAME_KO, NULL); 30f08c3bdfSopenharmony_ci module_loaded = 1; 31f08c3bdfSopenharmony_ci } 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_delete_module, MODULE_NAME, 0)); 34f08c3bdfSopenharmony_ci if (TST_RET == -1) { 35f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, 36f08c3bdfSopenharmony_ci "delete_module() failed to remove module entry for %s", 37f08c3bdfSopenharmony_ci MODULE_NAME); 38f08c3bdfSopenharmony_ci return; 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci tst_res(TPASS, "delete_module() successful"); 42f08c3bdfSopenharmony_ci module_loaded = 0; 43f08c3bdfSopenharmony_ci} 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_cistatic void cleanup(void) 46f08c3bdfSopenharmony_ci{ 47f08c3bdfSopenharmony_ci if (module_loaded) 48f08c3bdfSopenharmony_ci tst_module_unload(MODULE_NAME_KO); 49f08c3bdfSopenharmony_ci} 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_cistatic struct tst_test test = { 52f08c3bdfSopenharmony_ci .needs_root = 1, 53f08c3bdfSopenharmony_ci /* lockdown and SecureBoot requires signed modules */ 54f08c3bdfSopenharmony_ci .skip_in_lockdown = 1, 55f08c3bdfSopenharmony_ci .skip_in_secureboot = 1, 56f08c3bdfSopenharmony_ci .cleanup = cleanup, 57f08c3bdfSopenharmony_ci .test_all = do_delete_module, 58f08c3bdfSopenharmony_ci}; 59