int sculld_init(void) { int result, i; dev_t dev = MKDEV(sculld_major, 0); /* * Register your major, and accept a dynamic number. */ if (sculld_major) result = register_chrdev_region(dev, sculld_devs, "sculld"); else { result = alloc_chrdev_region(&dev, 0, sculld_devs, "sculld"); sculld_major = MAJOR(dev); } if (result < 0) return result; /* * Register with the driver core. */ register_ldd_driver(&sculld_driver); /* * allocate the devices -- we can't have them static, as the number * can be specified at load time */ sculld_devices = kmalloc(sculld_devs*sizeof (struct sculld_dev), GFP_KERNEL); if (!sculld_devices) { result = -ENOMEM; goto fail_malloc; } memset(sculld_devices, 0, sculld_devs*sizeof (struct sculld_dev)); for (i = 0; i < sculld_devs; i++) { sculld_devices[i].order = sculld_order; sculld_devices[i].qset = sculld_qset; sema_init (&sculld_devices[i].sem, 1); sculld_setup_cdev(sculld_devices + i, i); sculld_register_dev(sculld_devices + i, i); } #ifdef SCULLD_USE_PROC /* only when available */ create_proc_read_entry("sculldmem", 0, NULL, sculld_read_procmem, NULL); #endif return 0; /* succeed */ fail_malloc: unregister_chrdev_region(dev, sculld_devs); return result; }
static int __init mini_init(void) { register_ldd_device(&mini_device); return register_ldd_driver(&mini_driver); }