驱动调试笔记

复制代码
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/gpio/consumer.h>
#include <asm-generic/gpio.h>
#include <linux/gpio/consumer.h>

static int __init my_gpio_init(void){
    int ret = 0;
    char *p = NULL;
    printk(KERN_ERR"==hello: enter my_gpio_init==\n");
    p = kcalloc(0xff, 0, GFP_KERNEL);
    if (!p) {
        printk(KERN_ERR"==hello: p==NULL==\n");
    } else {
        printk(KERN_ERR"==hello: p==%p\n", p);
        p[0] = 5;
        printk(KERN_ERR"==hello: p[0]==%d\n", p[0]);
    }

    kfree(p);
    
    return 0;
}

static void __exit my_gpio_exit(void){
    printk(KERN_ERR"==enter my_gpio_exit==\n");
}

module_init(my_gpio_init);
module_exit(my_gpio_exit);
MODULE_LICENSE("GPL");
复制代码

 

insmod插入时打印如下:

root@ggs:/mytest# insmod test.ko 
[ 1040.877617] ==hello: enter my_gpio_init==
[ 1040.881570] ==hello: p==0000000000000010
[ 1040.885381] Unable to handle kernel NULL pointer dereference at virtual address 00000010

返回的地址竟然不是NULL!!,而是10

 

posted on   Hello-World3  阅读(148)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2017-10-25 Git常用有用命令

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示