Re: creating a character device using device_create is failing.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 28, 2008 at 12:02:26AM +0530, Prasad Joshi wrote:
> Hi All,
> 
> I want register the character device with sysfs and want a device file to be
> created. The function device_create() does the same, but it seems to be
> failing in my case.
> 
> Here is the part of the code
> 
> #define MYMAJOR 200
> 
> struct mydevice {
>     struct device *parent;
>     struct device *this_device;
>     dev_t dev;
>     char name[20];
> };
> 
> struct mydevice my_misc = {
>     .name = "myzero",
>     .parent = NULL,
> };
> 
> struct class *my_class;
> struct mydevice zdev;
> 
> static int __init myudev_init(void)
> {
>     int err = 0;
>     zdev.dev = MKDEV(MYMAJOR, 10);

Did you already register this major/minor?

>     my_class = class_create (THIS_MODULE, "mymisc");
>     err = PTR_ERR(my_class);
>     if (IS_ERR(my_class))
>         goto class_err;
> 
>     zdev.this_device = device_create(my_class, zdev.parent, zdev.dev, "%s",
> zdev.name);

You are passing NULL, or some garbage for the parent here, do you really
want that?


>     err = PTR_ERR(zdev.this_device);
>     if (IS_ERR(zdev.this_device))
>         goto device_err;
> 
>     return 0;
> device_err:
>     class_destroy(my_class);
> class_err:
>     return err;
> }
> 
> 
> While debugging the code, I could findout that device_add() is the failing
> 
> int device_add(struct device *dev)
> {
>     struct device *parent = NULL;
>     struct class_interface *class_intf;
>     int error;
> 
>     dev = get_device(dev);             <<<<<<<<<<<<<<<<<<< here the code is
> failing

What kernel version are you using?

thanks,

greg k-h

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux