Skip to content

Commit 94fbcde

Browse files
committed
Driver core: change misc class_devices to be real devices
This also ment that some of the misc drivers had to also be fixed up as they were assuming the device was a class_device. Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent cd15422 commit 94fbcde

5 files changed

Lines changed: 27 additions & 33 deletions

File tree

‎drivers/char/hw_random/core.c‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ static struct miscdevice rng_miscdev = {
162162
};
163163

164164

165-
static ssize_t hwrng_attr_current_store(struct class_device *class,
165+
static ssize_t hwrng_attr_current_store(struct device *dev,
166+
struct device_attribute *attr,
166167
const char *buf, size_t len)
167168
{
168169
int err;
@@ -192,7 +193,8 @@ static ssize_t hwrng_attr_current_store(struct class_device *class,
192193
return err ? : len;
193194
}
194195

195-
static ssize_t hwrng_attr_current_show(struct class_device *class,
196+
static ssize_t hwrng_attr_current_show(struct device *dev,
197+
struct device_attribute *attr,
196198
char *buf)
197199
{
198200
int err;
@@ -210,7 +212,8 @@ static ssize_t hwrng_attr_current_show(struct class_device *class,
210212
return ret;
211213
}
212214

213-
static ssize_t hwrng_attr_available_show(struct class_device *class,
215+
static ssize_t hwrng_attr_available_show(struct device *dev,
216+
struct device_attribute *attr,
214217
char *buf)
215218
{
216219
int err;
@@ -234,20 +237,18 @@ static ssize_t hwrng_attr_available_show(struct class_device *class,
234237
return ret;
235238
}
236239

237-
static CLASS_DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR,
238-
hwrng_attr_current_show,
239-
hwrng_attr_current_store);
240-
static CLASS_DEVICE_ATTR(rng_available, S_IRUGO,
241-
hwrng_attr_available_show,
242-
NULL);
240+
static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR,
241+
hwrng_attr_current_show,
242+
hwrng_attr_current_store);
243+
static DEVICE_ATTR(rng_available, S_IRUGO,
244+
hwrng_attr_available_show,
245+
NULL);
243246

244247

245248
static void unregister_miscdev(void)
246249
{
247-
class_device_remove_file(rng_miscdev.class,
248-
&class_device_attr_rng_available);
249-
class_device_remove_file(rng_miscdev.class,
250-
&class_device_attr_rng_current);
250+
device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available);
251+
device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
251252
misc_deregister(&rng_miscdev);
252253
}
253254

@@ -258,20 +259,19 @@ static int register_miscdev(void)
258259
err = misc_register(&rng_miscdev);
259260
if (err)
260261
goto out;
261-
err = class_device_create_file(rng_miscdev.class,
262-
&class_device_attr_rng_current);
262+
err = device_create_file(rng_miscdev.this_device,
263+
&dev_attr_rng_current);
263264
if (err)
264265
goto err_misc_dereg;
265-
err = class_device_create_file(rng_miscdev.class,
266-
&class_device_attr_rng_available);
266+
err = device_create_file(rng_miscdev.this_device,
267+
&dev_attr_rng_available);
267268
if (err)
268269
goto err_remove_current;
269270
out:
270271
return err;
271272

272273
err_remove_current:
273-
class_device_remove_file(rng_miscdev.class,
274-
&class_device_attr_rng_current);
274+
device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
275275
err_misc_dereg:
276276
misc_deregister(&rng_miscdev);
277277
goto out;

‎drivers/char/misc.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ static int misc_open(struct inode * inode, struct file * file)
169169
return err;
170170
}
171171

172-
/*
173-
* TODO for 2.7:
174-
* - add a struct kref to struct miscdevice and make all usages of
175-
* them dynamic.
176-
*/
177172
static struct class *misc_class;
178173

179174
static const struct file_operations misc_fops = {
@@ -228,10 +223,10 @@ int misc_register(struct miscdevice * misc)
228223
misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
229224
dev = MKDEV(MISC_MAJOR, misc->minor);
230225

231-
misc->class = class_device_create(misc_class, NULL, dev, misc->dev,
226+
misc->this_device = device_create(misc_class, misc->parent, dev,
232227
"%s", misc->name);
233-
if (IS_ERR(misc->class)) {
234-
err = PTR_ERR(misc->class);
228+
if (IS_ERR(misc->this_device)) {
229+
err = PTR_ERR(misc->this_device);
235230
goto out;
236231
}
237232

@@ -264,7 +259,7 @@ int misc_deregister(struct miscdevice * misc)
264259

265260
down(&misc_sem);
266261
list_del(&misc->list);
267-
class_device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
262+
device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
268263
if (i < DYNAMIC_MINORS && i>0) {
269264
misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
270265
}

‎drivers/char/tpm/tpm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
11301130
scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
11311131
chip->vendor.miscdev.name = devname;
11321132

1133-
chip->vendor.miscdev.dev = dev;
1133+
chip->vendor.miscdev.parent = dev;
11341134
chip->dev = get_device(dev);
11351135

11361136
if (misc_register(&chip->vendor.miscdev)) {

‎drivers/input/serio/serio_raw.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
297297

298298
serio_raw->dev.minor = PSMOUSE_MINOR;
299299
serio_raw->dev.name = serio_raw->name;
300-
serio_raw->dev.dev = &serio->dev;
300+
serio_raw->dev.parent = &serio->dev;
301301
serio_raw->dev.fops = &serio_raw_fops;
302302

303303
err = misc_register(&serio_raw->dev);

‎include/linux/miscdevice.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@
3131
#define HPET_MINOR 228
3232

3333
struct device;
34-
struct class_device;
3534

3635
struct miscdevice {
3736
int minor;
3837
const char *name;
3938
const struct file_operations *fops;
4039
struct list_head list;
41-
struct device *dev;
42-
struct class_device *class;
40+
struct device *parent;
41+
struct device *this_device;
4342
};
4443

4544
extern int misc_register(struct miscdevice * misc);

0 commit comments

Comments
 (0)