我正在开发嵌入式 Linux (kernel-5.10.24)。
当我尝试卸载 RTC 驱动程序模块时遇到错误,它是:
# lsmod
rtc_test 6490 1 - Live 0xc02f5000
# modprobe -r rtc_test
modprobe: remove 'rtc_test': Resource temporarily unavailable
我认为是从module->refcnt
is 1开始的,但是我不知道为什么refcnt是1。我这里得到的是增加引用计数的调用跟踪,如下,
[ 34.016653] Call Trace:
[ 34.019181] [<80020318>] show_stack+0x94/0x12c
[ 34.023772] [<808536e0>] dump_stack+0xac/0xe8
[ 34.028271] [<800d8f30>] try_module_get.part.65+0xf8/0x100
[ 34.033938] [<800c7040>] alarmtimer_rtc_add_device+0x13c/0x188
[ 34.039958] [<80380370>] device_add+0x578/0x810
[ 34.044631] [<80141c58>] cdev_device_add+0x54/0xb0
[ 34.049575] [<8048750c>] __rtc_register_device+0x108/0x3c8
[ 34.055234] [<80488000>] devm_rtc_device_register+0x3c/0x5c
[ 34.060997] [<c02f5914>] test_rtc_probe+0x190/0x5d4 [rtc_test]
[ 34.067561] [<803886e0>] platform_drv_probe+0x58/0xbc
[ 34.072777] [<80385a98>] really_probe+0x14c/0x578
[ 34.077629] [<803860e4>] driver_probe_device+0x80/0x25c
[ 34.083022] [<8038659c>] device_driver_attach+0x7c/0xa8
[ 34.088412] [<803866ac>] __driver_attach+0xe4/0x188
[ 34.093448] [<803835fc>] bus_for_each_dev+0x78/0xd0
[ 34.098480] [<80384b50>] bus_add_driver+0x1a4/0x230
[ 34.103514] [<80387080>] driver_register+0x84/0x154
[ 34.108544] [<80388e50>] __platform_driver_probe+0x74/0x150
[ 34.114294] [<800106d8>] do_one_initcall+0x50/0x1d8
[ 34.119328] [<80852d48>] do_init_module+0x70/0x208
[ 34.124272] [<800dc3c4>] load_module+0x219c/0x259c
[ 34.129214] [<800dca30>] sys_finit_module+0xd4/0x130
[ 34.134335] [<8002b798>] syscall_common+0x34/0x58
rtc_test.ko的基本逻辑如下:
int test_rtc_probe(....)
{
devm_clk_get(...);
platform_get_irq(...);
platform_get_resource(pdev, IORESOURCE_MEM, 0);
request_mem_region(....);
ioremap(...);
devm_rtc_device_register(...);
request_irq(...);
}
static struct platform_driver test_rtc_driver = {
.driver = {
.name = "rtc_test",
.of_match_table = dummy_rtc_of_ids,
},
.remove = __exit_p(test_rtc_remove),
.suspend = NULL,
.resume = NULL,
};
触发devm_rtc_device_register()
了上面的调用堆栈,其中增加了module->refcnt
(它添加了一个闹钟设备)。
refcnt 的增量导致模块卸载失败。
我检查了Linux内核中的其他RTC驱动程序,没有发现任何大的差异来解决问题。