From 1dde71db7a44ba4c7f57430dd3523913705d5837 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 15 Jul 2008 12:24:02 +0000 Subject: [PATCH] 'struct class_device' removed from 2.6.26 kernel, so use 'device_create()' and 'device_destroy()' instead of 'class_device_create()' and class_device_destroy()'. --- comedi/comedi_fops.c | 12 +++++------ comedi/drivers.c | 10 +++++---- include/linux/comedidev.h | 4 ++-- include/linux/device.h | 43 +++++++++++++++++++++++---------------- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 886ed7a1..0568951b 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1912,12 +1912,12 @@ static int __init comedi_init(void) comedi_proc_init(); for (i = 0; i < COMEDI_NDEVICES; i++) { - char name[20]; - sprintf(name, "comedi%d", i); + struct device *csdev; comedi_devices[i].minor = i; - comedi_devices[i].class_dev = - COMEDI_CLASS_DEVICE_CREATE(comedi_class, 0, - MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i", i); + csdev = device_create(comedi_class, 0, MKDEV(COMEDI_MAJOR, i), + "comedi%i", i); + if (!IS_ERR(csdev)) + comedi_devices[i].class_dev = csdev; spin_lock_init(&comedi_devices[i].spinlock); mutex_init(&comedi_devices[i].mutex); } @@ -1942,7 +1942,7 @@ static void __exit comedi_cleanup(void) comedi_device_detach(dev); mutex_unlock(&dev->mutex); mutex_destroy(&dev->mutex); - class_device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, i)); + device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, i)); } class_destroy(comedi_class); cdev_del(&comedi_cdev); diff --git a/comedi/drivers.c b/comedi/drivers.c index 84ceb896..625c9413 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -76,7 +76,7 @@ static void cleanup_device(comedi_device * dev) comedi_construct_minor_for_subdevice (dev, i); dev_t devt = MKDEV(COMEDI_MAJOR, minor); - class_device_destroy(comedi_class, devt); + device_destroy(comedi_class, devt); } if (s->async) { comedi_buf_alloc(dev, s, 0); @@ -258,6 +258,7 @@ static int postconfig(comedi_device * dev) if (s->do_cmd) { unsigned minor; dev_t devt; + struct device *csdev; BUG_ON((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0); @@ -290,10 +291,11 @@ static int postconfig(comedi_device * dev) } minor = comedi_construct_minor_for_subdevice(dev, i); devt = MKDEV(COMEDI_MAJOR, minor); - s->class_dev = - COMEDI_CLASS_DEVICE_CREATE(comedi_class, - dev->class_dev, devt, NULL, "comedi%i_sub%i", + csdev = device_create(comedi_class, + dev->class_dev, devt, "comedi%i_sub%i", dev->minor, i); + if (!IS_ERR(csdev)) + s->class_dev = csdev; } if (!s->range_table && !s->range_table_list) diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 5a73f1a6..796e00bb 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -150,7 +150,7 @@ struct comedi_subdevice_struct { unsigned int state; - struct class_device *class_dev; + struct device *class_dev; }; struct comedi_buf_page { @@ -222,7 +222,7 @@ struct comedi_device_struct { comedi_driver *driver; void *private; - struct class_device *class_dev; + struct device *class_dev; unsigned minor; /* hw_dev is passed to dma_alloc_coherent when allocating async buffers for subdevices that have async_dma_dir set to something other than DMA_NONE */ diff --git a/include/linux/device.h b/include/linux/device.h index 5a384cd5..5b4b2368 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -33,28 +33,26 @@ struct device_driver { }; struct class; -struct class_device; struct device; static inline struct class *class_create(struct module *owner, char *name) { return NULL; -}; +} static inline void class_destroy(struct class *cs) { -}; +} -static inline struct class_device *COMEDI_CLASS_DEVICE_CREATE(struct class *cls, - struct class_device *parent, dev_t devt, struct device *device, - char *fmt, ...) +static inline struct device *device_create(struct class *cls, + struct device *parent, dev_t devt, char *fmt, ...) { return NULL; -}; +} -static inline void class_device_destroy(struct class *cs, dev_t dev) +static inline void device_destroy(struct class *cs, dev_t devt) { -}; +} #else @@ -66,23 +64,32 @@ static inline void class_device_destroy(struct class *cs, dev_t dev) (struct class *)class_simple_create(owner, name) #define class_destroy(cs) \ class_simple_destroy((struct class_simple *)(cs)) -#define COMEDI_CLASS_DEVICE_CREATE(cs, parent, dev, device, fmt...) \ - class_simple_device_add((struct class_simple *)(cs), \ - dev, device, fmt) -#define class_device_destroy(cs, dev) \ - class_simple_device_remove(dev) +#define device_create(cs, parent, devt, fmt...) \ + (struct device *)class_simple_device_add((struct class_simple *)(cs), \ + devt, NULL, fmt) +#define device_destroy(cs, devt) \ + class_simple_device_remove(devt) #else #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) -#define COMEDI_CLASS_DEVICE_CREATE(cs, parent, dev, device, fmt...) \ - class_device_create(cs, dev, device, fmt) +#define device_create(cs, parent, devt, fmt...) \ + (struct device *)class_device_create(cs, devt, NULL, fmt) +#define device_destroy(cs, devt) \ + class_device_destroy(cs, devt) #else -#define COMEDI_CLASS_DEVICE_CREATE(cs, parent, dev, device, fmt...) \ - class_device_create(cs, parent, dev, device, fmt) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) + +#define device_create(cs, parent, devt, fmt...) \ + (struct device *)class_device_create( \ + cs, (struct class_device *)parent, devt, NULL, fmt) +#define device_destroy(cs, devt) \ + class_device_destroy(cs, devt) + +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) #endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) -- 2.26.2