Open kaikaiwei opened 4 years ago
原因分析, 查看调用栈发现demodrv_release中出错,由于kfifo_free是出错原因,观测代码发现,先释放了data,后释放了data->fifo。所以调整了下先后顺序。 static int demodrv_release(struct inode inode, struct file file) { struct mydemo_private_data *data = file->private_data;
//这里,free出错了,最好先free fifo,再free data。
kfifo_free(&data->mydemo_fifo); kfree(data);
return 0;
}
谢谢,实验5-8本来就是让大家来找错,哈
只修改了device的名称
/ # mknod /dev/mydemo_err0 c 252 0 / # cd mnt /mnt # insmod miscerr.ko [ 77.235510] succeeded register char device: mydemo_err /mnt # cat /dev/mydemo_err0 & /mnt # [ 93.227125] demodrv_open: major=252, minor=0, device=mydemo_err0 [ 93.233195] demodrv_read:mydemo_err0 pid=778, going to sleep, private_data_0
/mnt # /mnt # /mnt # echo "i am study linux now" > /dev/mydemo_err0 [ 131.945397] demodrv_open: major=252, minor=0, device=mydemo_err0 [ 131.948193] wait up read queue, private_data_0 [ 131.948609] demodrv_write:mydemo_err0 pid=772, actual_write =21, ppos=0, ret=0 [ 131.950152] Unable to handle kernel paging request at virtual address c789f6c0 [ 131.950673] pgd = c47d4000 [ 131.950852] [c789f6c0] *pgd=00000000 [ 131.952042] Internal error: Oops: 5 [#1] SMP ARM [ 131.952779] Modules linked in: miscerr(O) [ 131.954508] CPU: 0 PID: 772 Comm: sh Tainted: G O 4.0.0+ #2 [ 131.955054] Hardware name: ARM-Versatile Express [ 131.956382] task: c4ab0b00 ti: c47d0000 task.ti: c47d0000 [ 131.957525] PC is at kfree+0x178/0x704 [ 131.957849] LR is at kfifo_free+0x1c/0x64 [ 131.958290] pc : [] lr : [] psr: 20000013
[ 131.958290] sp : c47d3c68 ip : 00000000 fp : beb48fbe
[ 131.958923] r10: 00000000 r9 : c47d0000 r8 : c0014ec4
[ 131.959194] r7 : 0000003f r6 : 00000000 r5 : 0021da88 r4 : c05c0fb8
[ 131.959539] r3 : c789f6c0 r2 : c789f6c0 r1 : 00000019 r0 : 6b6b6b6b
[ 131.960074] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
[ 131.960416] Control: 10c5387d Table: 647d406a DAC: 00000015
[ 131.960762] Process sh (pid: 772, stack limit = 0xc47d0210)
[ 131.961111] Stack: (0xc47d3c68 to 0xc47d4000)
[ 131.961506] 3c60: c4c3a280 6b6b6b6b 0a9b0a9b c0239350 00000000 c4c3a280
[ 131.962103] 3c80: c10f5188 c10f5188 60000013 c00c80f8 00000400 20000013 c10c378c c10c378c
[ 131.962595] 3ca0: 20000013 c10c378c 000003e0 c10c378c bcbcfdb1 00000000 0021dab8 bf000504
[ 131.963136] 3cc0: 00000000 c10f5188 c10f5188 c10f5188 c10f5188 60000013 00000004 c10f5188
[ 131.964751] 3ce0: 60000013 c10f5188 00000002 00000004 c62f4078 60000013 00000000 01000000
[ 131.967115] 3d00: c10f5188 c4ab0b00 00000000 00000000 00000000 c4ab0b00 00000000 00000042
[ 131.968103] 3d20: beb48fbe c007cc94 00000004 01000000 c5438c00 c4ab0b00 c4ba5ad0 00000002
[ 131.968833] 3d40: c47d0000 00000002 c4ab0b00 00000000 00000000 00000000 c4ab0ee4 00000004
[ 131.969416] 3d60: c5438c00 00000000 c4ab0ee4 00000004 c5438c00 c62feff8 05248000 c10b6ff8
[ 131.970017] 3d80: 00000000 00000000 00000000 00000000 05248000 c10b6ffc 00000000 00000000
[ 131.970820] 3da0: c4c3a280 c5c03cc0 00000080 c4c3a280 80010d00 c4c3a280 c4c3a280 c5c03cc0
[ 131.971726] 3dc0: c4c3a280 bf0001a8 c4c3a280 c63ca740 c789f6c0 0000000f c789f6c0 c789f6c0
[ 131.972422] 3de0: c789f6c0 0000000f c63ca740 c63ca740 c63ca740 c63ca740 00000007 00000000
[ 131.974227] 3e00: 60000013 00000000 c10f17a8 c10f17a8 6b6b6b6b c05c0fb8 c10f17a8 c10f17a8
[ 131.974868] 3e20: c4c3a280 6b6b6b6b c5d37540 c5c03cc0 c5d37548 6b6b6b6b 0000000b c05c0fb8
[ 131.976320] 3e40: c63ca740 c4c3a2c4 0000000b bf0001c4 c5438c00 c452c448 00000000 c4c3a2c4
[ 131.976861] 3e60: c4c3a2c4 c4c3a280 00000001 c0250b0c 00000000 00000000 00000002 c5438c00
[ 131.977718] 3e80: 00000001 c5d37508 00000000 00000000 00000000 00000000 00000000 c5d37540
[ 131.978780] 3ea0: 00000001 00000008 c5bf8270 c5438c08 00000008 0004001e c452c448 c5438c00
[ 131.979130] 3ec0: c5438c08 c5438c94 c5438c00 c028967c 00000000 00000000 00000001 c5438c00
[ 131.979624] 3ee0: c5438c00 c452c448 c5cf4c10 c5bf8270 00000002 c0250e30 c55da000 c5438c00
[ 131.980088] 3f00: 00000000 c5438c00 c5d37508 c007d16c 01e601e6 01e601e6 c5d37500 0000000b
[ 131.980496] 3f20: 00000004 c47d3f10 c4ab0ef8 c5438c00 c5438c00 00000000 c4ab0ee4 00000004
[ 131.981302] 3f40: 00000000 c5438c00 c4ab0ee4 00000004 00000000 c5438c00 c4ab0ee4 00000000
[ 131.981866] 3f60: 00000000 c4ab0ef8 00000000 c4ab0b00 c5438c00 c5438c00 00200200 c001c8e0
[ 131.982384] 3f80: c5438c00 c0014ec4 00000004 c47d3fb0 00000015 00000002 c47d0000 c47d3fb0
[ 131.985925] 3fa0: 00000017 c0014d40 0000000b c0014d84 00000001 00000001 0021c828 00000001
[ 131.986431] 3fc0: 0000000b 0021da88 00000000 0000003f 0021cc28 00000000 001ca858 beb48fbe
[ 131.986848] 3fe0: 00000000 beb489fc 000707d0 00011bbc 20000010 0000000b 00000000 00000000
[ 131.987406] [] (kfree) from [] ( kfifo_free+0x1c/0x64)
[ 131.988871] [] (__kfifo_free) from [] (demodrv_release+0x40/0x50 [miscerr])
[ 131.989336] [] (demodrv_release [miscerr]) from [] (fput+0x1fc/0x3f0)
[ 131.989831] [] ( fput) from [] (fput+0x20/0x2c)
[ 131.990178] [] ( fput) from [] (task_work_run+0x2ec/0x334)
[ 131.990626] [] (task_work_run) from [] (do_work_pending+0x13c/0x174)
[ 131.991237] [] (do_work_pending) from [] (work_pending+0xc/0x20)
[ 131.992238] Code: e1a032c3 e1a03103 e59d2168 e0823003 (e5932000)
[ 131.993084] ---[ end trace a12670f987276c82 ]---