Video4Linux driver developement

From: pierre (kpierre_at_rambler.ru)
Date: 01/24/05


Date: 23 Jan 2005 22:42:43 -0800

Can you help me?

I wrote the "driver template" for V4L, it loads normally, but kernel
(v2.6.9) reports "segmentation fault" while trying to rmmod it.

I didn't found the modern V4L specification anywhere, so this code is
based on the Videoloopback driver.

Sorry for my terrible english, please...

The code is:

---------------------------

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/videodev.h>

MODULE_DESCRIPTION("Palm camera module");
MODULE_AUTHOR("pierre (kpierre@rambler.ru)");
MODULE_LICENSE("GPL");

static struct video_device palm_camera;

/*static int init(struct inode * inod, struct file * f)
{
    //struct palm_camera *pdev=(struct palm_camera *)video_devdata(f);
    return 0;
}

static int unload(struct inode * inod, struct file * f)
{
    return 0;
}*/

static int palmcam_close(struct inode * inod, struct file * f)
{
    struct video_device *vdev=f->private_data;
    struct palm_camera *pm = video_get_drvdata(vdev);
    kfree(pm);
    pm = NULL;
    
    f->private_data=NULL;
    return 0;
}

static int palmcam_open(struct inode * inod, struct file * f)
{
    return 0;
}

static int palmcam_read(struct inode * inod, struct file * f)
{
    return 0;
}

static int palmcam_mmap(struct inode * inod, struct file * f)
{
    return 0;
}

static int palmcam_ioctl(struct inode * inod, struct file * f)
{
    return 0;
}

static int palmcam_llseek(struct inode * inod, struct file * f)
{
    return 0;
}

static struct file_operations palm_fops = {
        .owner = THIS_MODULE,
        .open = palmcam_open,
        .release = palmcam_close,
        .read = palmcam_read,
        .mmap = palmcam_mmap,
        .ioctl = palmcam_ioctl,
        .llseek = palmcam_llseek,
};

static struct video_device palm_camera =
{
        .owner = THIS_MODULE,
        .name = "Palm Camera",
        .type = VID_TYPE_CAPTURE,
        .release = video_device_release,
        .fops = &palm_fops
};

static int init_v4l(void)
{
        video_register_device(&palm_camera,VFL_TYPE_GRABBER,-1);
        return 0;
}

static int close_v4l(void)
{
        video_unregister_device(&palm_camera); // here kernel fails
        return 0;
}

static int palmcam_init_module(void)
{
        init_v4l();
        printk( "Module palmcam init\n" );
        return 0;
}

static void palmcam_exit_module(void)
{
        close_v4l();
        printk( "Module palmcam exit\n" );
}

module_init(palmcam_init_module);
module_exit(palmcam_exit_module);

--------------------------------

Great thanks for your help!



Relevant Pages