每次rmmod driver的时候内核就crash,求大神看看代码有啥问题

去如是 2020-05-16 07:52:32
char_device.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>

struct platform_device chardev = {
.name = "chrdevbase",
.id = -1,
};

static int char_device_init(void){

printk("char device init\n");
return platform_device_register(&chardev);
}

static void char_device_exit(void){
printk("char device exit\n");
}

MODULE_LICENSE("GPL");
module_init(char_device_init);
module_exit(char_device_exit);


char_driver.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>

int char_dev_probe(struct platform_device *dev){
printk("platform driver probe\n");
return 0;
}

int char_dev_remove(struct platform_device *dev){
printk("platform driver remove\n");
return 0;
}

struct platform_driver chardri = {
.driver={
.owner = THIS_MODULE,
.name = "chrdevbase",
},
.probe = char_dev_probe,
.remove = char_dev_remove,
};

static int char_driver_init(void){

printk("platform driver init\n");
return platform_driver_register(&chardri);
}

static void char_driver_exit(void){
platform_driver_unregister(&chardri);
printk("platform driver exit\n");
}

MODULE_LICENSE("GPL");
module_init(char_driver_init);
module_exit(char_driver_exit);


makefile:

obj-m:=char_device.o char_driver.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.symvers *.cmd *.cmd.o



dmesg:
[ 2380.724760] char device init
[ 2390.660401] platform driver init
[ 2390.660422] platform driver probe
[ 2421.906509] platform driver remove
[ 2421.906534] ------------[ cut here ]------------
[ 2421.906534] Device 'chrdevbase' does not have a release() function, it is broken and must be fixed.
[ 2421.906545] WARNING: CPU: 1 PID: 4594 at /build/linux-CbANGF/linux-4.15.0/drivers/base/core.c:895 device_release+0x80/0x90
[ 2421.906545] Modules linked in: char_driver(OE) char_device(OE-) ip6table_filter ip6_tables iptable_filter pci_stub vboxpci(OE) vboxnetadp(OE) vboxnetflt(OE) vboxdrv(OE) ccm nls_iso8859_1 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hda_core snd_hwdep intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp snd_pcm kvm_intel 8250_dw snd_seq_midi snd_seq_midi_event snd_rawmidi kvm arc4 mxm_wmi irqbypass snd_seq crct10dif_pclmul crc32_pclmul snd_seq_device ghash_clmulni_intel snd_timer iwldvm pcbc mac80211 aesni_intel aes_x86_64 crypto_simd glue_helper cryptd iwlwifi intel_cstate snd intel_rapl_perf cfg80211 serio_raw shpchp soundcore input_leds i915 joydev mei_me mei drm_kms_helper idma64 virt_dma intel_pch_thermal drm i2c_algo_bit intel_lpss_pci fb_sys_fops
[ 2421.906589] syscopyarea sysfillrect intel_lpss sysimgblt mac_hid wmi video acpi_pad sch_fq_codel parport_pc ppdev lp parport ip_tables x_tables autofs4 hid_generic usbhid hid ahci psmouse libahci r8169 mii pinctrl_sunrisepoint
[ 2421.906597] CPU: 1 PID: 4594 Comm: rmmod Tainted: G OE 4.15.0-99-generic #100-Ubuntu
[ 2421.906597] Hardware name: MSI MS-7996/B150M PRO-VH (MS-7996), BIOS 1.80 07/27/2016
[ 2421.906599] RIP: 0010:device_release+0x80/0x90
[ 2421.906600] RSP: 0018:ffffbdb400ddbe30 EFLAGS: 00010282
[ 2421.906601] RAX: 0000000000000000 RBX: ffffffffc0a7c020 RCX: 0000000000000006
[ 2421.906601] RDX: 0000000000000007 RSI: 0000000000000092 RDI: ffff9dd3eec96490
[ 2421.906602] RBP: ffffbdb400ddbe48 R08: 000000000000035b R09: 0000000000000004
[ 2421.906602] R10: fffff8cf87518e00 R11: ffffffff8755c80d R12: ffffffffc0a7c010
[ 2421.906603] R13: ffff9dd3df52ff00 R14: ffff9dd3d2353ae0 R15: 0000000000000000
[ 2421.906604] FS: 00007f222dc87540(0000) GS:ffff9dd3eec80000(0000) knlGS:0000000000000000
[ 2421.906604] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 2421.906605] CR2: 0000563fea1e3f08 CR3: 0000000181d14005 CR4: 00000000003606e0
[ 2421.906605] Call Trace:
[ 2421.906610] kobject_release+0x6a/0x180
[ 2421.906611] kobject_put+0x28/0x50
[ 2421.906612] put_device+0x17/0x20
[ 2421.906614] platform_device_unregister+0x20/0x30
[ 2421.906628] char_device_exit+0x15/0xfd0 [char_device]
[ 2421.906630] SyS_delete_module+0x1ab/0x2d0
[ 2421.906632] do_syscall_64+0x73/0x130
[ 2421.906634] entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[ 2421.906635] RIP: 0033:0x7f222d7ab1b7
[ 2421.906636] RSP: 002b:00007fff171fbb48 EFLAGS: 00000206 ORIG_RAX: 00000000000000b0
[ 2421.906637] RAX: ffffffffffffffda RBX: 00007fff171fbba8 RCX: 00007f222d7ab1b7
[ 2421.906652] RDX: 000000000000000a RSI: 0000000000000800 RDI: 0000563fea1d97e8
[ 2421.906652] RBP: 0000563fea1d9780 R08: 00007fff171faac1 R09: 0000000000000000
[ 2421.906653] R10: 00007f222d827cc0 R11: 0000000000000206 R12: 00007fff171fbd70
[ 2421.906653] R13: 00007fff171fd7b7 R14: 0000563fea1d9260 R15: 0000563fea1d9780
[ 2421.906654] Code: d7 48 8b 83 98 02 00 00 48 85 c0 74 09 48 8b 40 40 48 85 c0 75 c2 48 8b 73 40 48 85 f6 74 10 48 c7 c7 a0 22 d5 86 e8 70 0d a3 ff <0f> 0b eb b1 48 8b 33 eb eb 0f 1f 80 00 00 00 00 0f 1f 44 00 00
[ 2421.906666] ---[ end trace f74bec0af92db7bd ]---
[ 2421.906667] char device exit
[ 2428.681699] platform driver exit

跪求大神帮忙看看代码有啥问题?万分感谢
...全文
50175 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
LBJ676 2020-12-29
  • 打赏
  • 举报
回复
学习学习学习学习
Kyph 2020-12-22
  • 打赏
  • 举报
回复
我的理解是,你缺少platform_device。
先有platform_device,然后再有对应的platform_driver。
星空语 2020-12-18
  • 打赏
  • 举报
回复
第一个char_device.c的退出接口函数
static void char_device_exit(void){
printk("char device exit\n");
}少了
platform_device_unregister(&chardev);
悟道之路 2020-12-15
  • 打赏
  • 举报
回复
第一个文件的退出函数没有执行对应的unregister函数
JZHANG35 2020-12-14
  • 打赏
  • 举报
回复
看清楚打印的错误类型,楼上正解
萌主墩墩 2020-07-17
  • 打赏
  • 举报
回复
自己实现一个空的release函数就可以了
Darknightpk 2020-06-22
  • 打赏
  • 举报
回复
trace里不提示的很清楚。。。。
scutth 2020-05-17
  • 打赏
  • 举报
回复
1. 这个不是crash,只是warning。 2. struct platform_device chardev = { .name = "chrdevbase", .id = -1, }; 这里需要实现release callback。
去如是 2020-05-17
  • 打赏
  • 举报
回复
自己顶一下,大神赶快来

1,317

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧