From d47f00e291ae9a54d4b9c3e1f2e930d518b69c7b Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 5 Aug 2008 14:43:40 +0000 Subject: [PATCH] Parameters of device_create() changed in 2.6.27-rc1, so call compatibility macro COMEDI_DEVICE_CREATE() instead. --- comedi/comedi_fops.c | 4 ++-- comedi/drivers.c | 4 ++-- include/linux/device.h | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 0568951b..914c9a80 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1914,8 +1914,8 @@ static int __init comedi_init(void) for (i = 0; i < COMEDI_NDEVICES; i++) { struct device *csdev; comedi_devices[i].minor = i; - csdev = device_create(comedi_class, 0, MKDEV(COMEDI_MAJOR, i), - "comedi%i", i); + csdev = COMEDI_DEVICE_CREATE(comedi_class, 0, + MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i", i); if (!IS_ERR(csdev)) comedi_devices[i].class_dev = csdev; spin_lock_init(&comedi_devices[i].spinlock); diff --git a/comedi/drivers.c b/comedi/drivers.c index 625c9413..36cbf4b9 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -291,8 +291,8 @@ static int postconfig(comedi_device * dev) } minor = comedi_construct_minor_for_subdevice(dev, i); devt = MKDEV(COMEDI_MAJOR, minor); - csdev = device_create(comedi_class, - dev->class_dev, devt, "comedi%i_sub%i", + csdev = COMEDI_DEVICE_CREATE(comedi_class, + dev->class_dev, devt, NULL, "comedi%i_sub%i", dev->minor, i); if (!IS_ERR(csdev)) s->class_dev = csdev; diff --git a/include/linux/device.h b/include/linux/device.h index 4ee44548..7ed524df 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -39,6 +39,13 @@ * The main limitation is that we cannot use a *real* 'struct device *' as * the parent parameter of device_create(), only a pointer from a previous * call to device_create(). + * + * Call COMEDI_DEVICE_CREATE() instead of device_create() for compatibility + * with kernel versions prior to 2.6.27. + * + * We do not currently support 'dev_get_drvdata()' and 'dev_set_drvdata()' + * for kernel versions prior to 2.6.26, so the 'drvdata' parameter of + * COMEDI_DEVICE_CREATE() is pretty useless. */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) @@ -61,7 +68,7 @@ static inline void class_destroy(struct class *cs) } static inline struct device *device_create(struct class *cls, - struct device *parent, dev_t devt, char *fmt, ...) + struct device *parent, dev_t devt, void *drvdata, char *fmt, ...) { return NULL; } @@ -80,7 +87,7 @@ static inline void device_destroy(struct class *cs, dev_t devt) (struct class *)class_simple_create(owner, name) #define class_destroy(cs) \ class_simple_destroy((struct class_simple *)(cs)) -#define device_create(cs, parent, devt, fmt...) \ +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ (struct device *)class_simple_device_add((struct class_simple *)(cs), \ devt, NULL, fmt) #define device_destroy(cs, devt) \ @@ -90,7 +97,7 @@ static inline void device_destroy(struct class *cs, dev_t devt) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) -#define device_create(cs, parent, devt, fmt...) \ +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ (struct device *)class_device_create(cs, devt, NULL, fmt) #define device_destroy(cs, devt) \ class_device_destroy(cs, devt) @@ -99,12 +106,35 @@ static inline void device_destroy(struct class *cs, dev_t devt) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) -#define device_create(cs, parent, devt, fmt...) \ +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ (struct device *)class_device_create( \ cs, (struct class_device *)parent, devt, NULL, fmt) #define device_destroy(cs, devt) \ class_device_destroy(cs, devt) +#else + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) + +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ + device_create(cs, parent, devt, fmt) + +#else + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) + +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ + device_create_drvdata(cs, parent, devt, drvdata, fmt) + +#else + +#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \ + device_create(cs, parent, devt, drvdata, fmt) + +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) + +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) + #endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) #endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) -- 2.26.2