Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)
From: ./h (hemant.mohapatra_at_gmail.com)
Date: 06/17/05
- Next message: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Previous message: Tauno Voipio: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- In reply to: Kasper Dupont: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Next in thread: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Reply: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 17 Jun 2005 07:43:19 -0700
Kasper Dupont wrote:
> We want the same thing we always want. A minimal
> piece of code, that compiles without warnings and
> demonstrates the problem.
I understand that but it was conveyed to me in ways I failed to
understand. Now that you have made it clear, I have clipped out all the
unnecessary parts of the code and the stripped down version (the bare
minumum; I cannot make it smaller than that w/o getting compiler
errors) is at the end of the email.
> If you want us to be able to help, then you have
> to do a bit of work yourself.
Once again, I have been around on usenet for more than 5 years and I
know better than that. I do _not_ want to be spoon-fed, I just wish to
be pointed at the right direction. I have done days of googling on
this, I don't mind a few days more but I need to know from more
experienced people where to look for - that's all.
Without wasting more time, here is the code. I have changed it in
places but the error still occurs at cdev_init. Also, this time I have
taken help from Roubini's book (2.6 kernel version, not the older one).
(Peter, if you'd kindly have a look too, it'd be great. I apologise for
the previous misunderstandings; this code compiles, and is the bare
minumum. However, I cannot give you the "ten lines" you needed, I am
sorry.)
<code section>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
static int Major;
static struct file_operations scull_fops = {
.owner = THIS_MODULE,
};
struct scull_cdev {
struct cdev cdev;
};
static void scull_setup(struct scull_cdev *, int );
static void
scull_setup (struct scull_cdev *sculldevice, int major)
{
int err;
int devno = MKDEV (major, 0);
cdev_init (&sculldevice->cdev, &scull_fops);
sculldevice->cdev.owner = THIS_MODULE;
sculldevice->cdev.ops = &scull_fops;
err = cdev_add (&sculldevice->cdev, devno, 1);
if (err)
printk (KERN_NOTICE "error in adding device");
}
int __init
scull_init (void)
{
dev_t dev;
int retval;
struct scull_cdev *device;
memset(device, 0, sizeof(struct scull_cdev));
retval = alloc_chrdev_region (&dev, 0, 1, "scull");
Major = MAJOR (dev);
if (retval < 0)
{
printk ("<1> Cannot get major number");
}
scull_setup (device, Major);
return 0;
}
static void __exit
scull_exit (void)
{
unregister_chrdev_region (MKDEV (Major, 0), 1);
}
module_init (scull_init);
module_exit (scull_exit);
--- <code ends> Oops report: Unable to handle kernel NULL pointer dereference at virtual address 0000003c printing eip: c015c6d9 *pde = 00000000 Oops: 0002 [#3] CPU: 0 EIP: 0060:[<c015c6d9>] Tainted: PF EFLAGS: 00010292 (2.6.4-52-default) EIP is at cdev_init+0x9/0x30
- Next message: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Previous message: Tauno Voipio: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- In reply to: Kasper Dupont: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Next in thread: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Reply: Peter T. Breuer: "Re: cdev_init() problems in char device driver (kernel 2.6.4-52) (newbie ques)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|