驱动调试笔记

#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 2018-10-25 16:29  Hello-World3  阅读(146)  评论(0编辑  收藏  举报

导航