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


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


Relevant Pages

  • Re: porting problems encountered
    ... Tru64 compiles long variables to size 8 bytes while VMS and HP-UX ... platform, the size of the structure would be 12 bytes. ... when it got to the AS/400 with 128 bit pointers. ... Using the struct from before: ...
    (comp.os.vms)
  • Re: Features and standards
    ... to the ANSI-C standard, compiles under 'gcc' but not under Sun Studio. ... struct name { ... and then did some tricky allocation to make the namestr array ...
    (comp.lang.c)
  • Re: No casting of void* ???
    ... I seem to have accomplished a solution that compiles and satisfies the ... Having said, this, to create base structures so to condense identical ... typedef struct tag_table_links ...
    (microsoft.public.vc.language)
  • Re: Type convertsion from string
    ... compiles new assembly containing additional properties which ... the best approach is actually a generics-trick, ... private static void SomeBodyOfCode ... // can use all EntityBase properties & ...
    (microsoft.public.dotnet.languages.csharp)
  • typename and sizeof
    ... static member. ... this compiles in Comeau compiler online: ... template ...
    (microsoft.public.vc.language)

Loading