~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/char/raw.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <linux/mutex.h>
22
22
#include <linux/gfp.h>
23
23
#include <linux/compat.h>
 
24
#include <linux/vmalloc.h>
24
25
 
25
26
#include <asm/uaccess.h>
26
27
 
30
31
};
31
32
 
32
33
static struct class *raw_class;
33
 
static struct raw_device_data raw_devices[MAX_RAW_MINORS];
 
34
static struct raw_device_data *raw_devices;
34
35
static DEFINE_MUTEX(raw_mutex);
35
36
static const struct file_operations raw_ctl_fops; /* forward declaration */
36
37
 
 
38
static int max_raw_minors = MAX_RAW_MINORS;
 
39
 
 
40
module_param(max_raw_minors, int, 0);
 
41
MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
 
42
 
37
43
/*
38
44
 * Open/close code for raw IO.
39
45
 *
125
131
        struct raw_device_data *rawdev;
126
132
        int err = 0;
127
133
 
128
 
        if (number <= 0 || number >= MAX_RAW_MINORS)
 
134
        if (number <= 0 || number >= max_raw_minors)
129
135
                return -EINVAL;
130
136
 
131
137
        if (MAJOR(dev) != major || MINOR(dev) != minor)
312
318
        dev_t dev = MKDEV(RAW_MAJOR, 0);
313
319
        int ret;
314
320
 
315
 
        ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
 
321
        if (max_raw_minors < 1 || max_raw_minors > 65536) {
 
322
                printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
 
323
                        " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
 
324
                max_raw_minors = MAX_RAW_MINORS;
 
325
        }
 
326
 
 
327
        raw_devices = vmalloc(sizeof(struct raw_device_data) * max_raw_minors);
 
328
        if (!raw_devices) {
 
329
                printk(KERN_ERR "Not enough memory for raw device structures\n");
 
330
                ret = -ENOMEM;
 
331
                goto error;
 
332
        }
 
333
        memset(raw_devices, 0, sizeof(struct raw_device_data) * max_raw_minors);
 
334
 
 
335
        ret = register_chrdev_region(dev, max_raw_minors, "raw");
316
336
        if (ret)
317
337
                goto error;
318
338
 
319
339
        cdev_init(&raw_cdev, &raw_fops);
320
 
        ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
 
340
        ret = cdev_add(&raw_cdev, dev, max_raw_minors);
321
341
        if (ret) {
322
 
                kobject_put(&raw_cdev.kobj);
323
342
                goto error_region;
324
343
        }
325
344
 
336
355
        return 0;
337
356
 
338
357
error_region:
339
 
        unregister_chrdev_region(dev, MAX_RAW_MINORS);
 
358
        unregister_chrdev_region(dev, max_raw_minors);
340
359
error:
 
360
        vfree(raw_devices);
341
361
        return ret;
342
362
}
343
363
 
346
366
        device_destroy(raw_class, MKDEV(RAW_MAJOR, 0));
347
367
        class_destroy(raw_class);
348
368
        cdev_del(&raw_cdev);
349
 
        unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS);
 
369
        unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), max_raw_minors);
350
370
}
351
371
 
352
372
module_init(raw_init);