v4l2框架的虚拟视频驱动程序详解

来源:互联网 发布:淘宝网禁止有毒化学物 编辑:程序博客网 时间:2024/05/06 17:43

dc2h_driver.c :

static int __init dc2h_init(void){    int ret;    struct dc2h_device *dev;    struct video_device *vdev;     struct v4l2_ctrl_handler *hdl;     struct vb2_queue *q;    printk(KERN_EMERG "\n\n\n\n *****************    dc2h init module  *********************\n\n\n\n");    //printk(KERN_EMERG"@@@@@ddc2h_init start@@@@\n");    dev = kzalloc(sizeof(*dev), GFP_KERNEL);    if(!dev)    {           printk(KERN_EMERG "@@@@@dev is null @@@@\n");        return -ENOMEM;    }    strcpy(dev->v4l2_dev.name, "/dev/dc2h_video");    ret = v4l2_device_register(NULL, &dev->v4l2_dev);/*register the v4l2_device*/    if( ret )    {        printk(KERN_EMERG "@@@@@v4l2_device_register fail@@@@\n");        goto free_dev;    }else{        printk(KERN_EMERG "@@@@@v4l2_device_register success!@@@@\n");    }    /* initialize locks */     spin_lock_init(&dev->slock);    mutex_init(&dev->mutex);     /* before register the video_device, init the video_device data*/     ret = -ENOMEM;     vdev = video_device_alloc();     if(!vdev)     {        printk(KERN_EMERG "@@@@@video_device_alloc fail@@@@\n");        goto unreg_dev;     }else{        printk(KERN_EMERG "@@@@@video_device_alloc success!@@@@\n");    }    *vdev = d2ch_tmplate; /* the most important struct */    vdev->v4l2_dev = &dev->v4l2_dev; /* here set the v4l2_device, you have already registered it */    //set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);      vdev->lock = &dev->mutex;/*Provide a mutex to v4l2 core to protect all fops and v4l2 ioctls*/    vdev->testflag = 123; //just test;!@#    ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);    if (ret < 0)     {        printk(KERN_EMERG "@@@@@video_register_device fail@@@@\n");        goto rel_vdev;    }else{        printk(KERN_EMERG "@@@@@video_register_device success!@@@@\n");    }    printk(KERN_EMERG " @@@@@vdev->testflag-before =  %d\n", vdev->testflag);    video_set_drvdata(vdev, dev);//!@#   set driver data    dev->vdev = vdev; /*assoiate video_device and dc2h_device*/    printk(KERN_EMERG " @@@@@vdev->testflag-after1 =  %d\n", vdev->testflag);    /* the debug message*/     v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", video_device_node_name(vdev));    return 0; //  result : Unable to handle kernel NULL pointer dereference at virtual address 00000000    //video_device_node_namerel_vdev:    video_device_release(vdev);unreg_dev:    v4l2_ctrl_handler_free(hdl);    v4l2_device_unregister(&dev->v4l2_dev);free_dev:    kfree(dev);    printk(KERN_EMERG " @@@@@vdev->testflag-after1 =  %d\n", vdev->testflag);    return ret;}
0 0
原创粉丝点击