All pastes #414266 Raw Edit

Untitled

public text v1 · immutable
#414266 ·published 2007-03-28 22:44 UTC
rendered paste body
static int arm_init(void)
{
    char* name = "arm";


    // Let us know we are up
    printk(KERN_ALERT "arm: Hello arm.\n");

    // Get a device number
    if(alloc_chrdev_region(&arm.dev, 0, COUNT, name) < 0)
    {
        printk(KERN_ALERT "arm: ERROR: alloc_chrdev FAILED.\n");
        return 0;
    }

    printk(KERN_ALERT "arm: Device number = %d.\n", MAJOR(arm.dev));

    // Register Char device
    cdev_init(&arm.cdev, &arm_fops);
    arm.cdev.owner = THIS_MODULE;
    arm.cdev.ops = &arm_fops;

    if(cdev_add(&arm.cdev, MAJOR(arm.dev), 2) < 0)
    {
        printk(KERN_ALERT "arm: ERROR: cdev_add FAILED.\n");
        // Cleanup
        unregister_chrdev_region(arm.dev, COUNT);
        return 0;
    }

    // Init ARM struct
    atomic_set(&arm.inUse, -1);

    // Create Proc Entry
    arm.pde = create_proc_read_entry("arm", 0, NULL, arm_proc_read, NULL);


    return 0;
}