diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-02 09:44:55 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-25 06:44:53 -0400 |
commit | 0daa7a0afd0fa7aad83cbde0fb341d7fbeac952c (patch) | |
tree | 6fc189518d606e169abe9a936a1f4703ec620496 /drivers/char/hw_random | |
parent | bd735995308b553cc3c7f6a975aa284b270c7e2c (diff) |
hwrng: Avoid manual device_create_file() calls
Use the new group field of struct miscdevice for managing the sysfs
entries instead of manually adding/removing via device_create_file()
and device_remove_file(). This simplifies the code a lot and fixes
the possible races.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char/hw_random')
-rw-r--r-- | drivers/char/hw_random/core.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 32a8a867f7f8..0a8194525baf 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
@@ -299,11 +299,14 @@ static const struct file_operations rng_chrdev_ops = { | |||
299 | .llseek = noop_llseek, | 299 | .llseek = noop_llseek, |
300 | }; | 300 | }; |
301 | 301 | ||
302 | static const struct attribute_group *rng_dev_groups[]; | ||
303 | |||
302 | static struct miscdevice rng_miscdev = { | 304 | static struct miscdevice rng_miscdev = { |
303 | .minor = RNG_MISCDEV_MINOR, | 305 | .minor = RNG_MISCDEV_MINOR, |
304 | .name = RNG_MODULE_NAME, | 306 | .name = RNG_MODULE_NAME, |
305 | .nodename = "hwrng", | 307 | .nodename = "hwrng", |
306 | .fops = &rng_chrdev_ops, | 308 | .fops = &rng_chrdev_ops, |
309 | .groups = rng_dev_groups, | ||
307 | }; | 310 | }; |
308 | 311 | ||
309 | 312 | ||
@@ -376,37 +379,22 @@ static DEVICE_ATTR(rng_available, S_IRUGO, | |||
376 | hwrng_attr_available_show, | 379 | hwrng_attr_available_show, |
377 | NULL); | 380 | NULL); |
378 | 381 | ||
382 | static struct attribute *rng_dev_attrs[] = { | ||
383 | &dev_attr_rng_current.attr, | ||
384 | &dev_attr_rng_available.attr, | ||
385 | NULL | ||
386 | }; | ||
387 | |||
388 | ATTRIBUTE_GROUPS(rng_dev); | ||
379 | 389 | ||
380 | static void __exit unregister_miscdev(void) | 390 | static void __exit unregister_miscdev(void) |
381 | { | 391 | { |
382 | device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available); | ||
383 | device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current); | ||
384 | misc_deregister(&rng_miscdev); | 392 | misc_deregister(&rng_miscdev); |
385 | } | 393 | } |
386 | 394 | ||
387 | static int __init register_miscdev(void) | 395 | static int __init register_miscdev(void) |
388 | { | 396 | { |
389 | int err; | 397 | return misc_register(&rng_miscdev); |
390 | |||
391 | err = misc_register(&rng_miscdev); | ||
392 | if (err) | ||
393 | goto out; | ||
394 | err = device_create_file(rng_miscdev.this_device, | ||
395 | &dev_attr_rng_current); | ||
396 | if (err) | ||
397 | goto err_misc_dereg; | ||
398 | err = device_create_file(rng_miscdev.this_device, | ||
399 | &dev_attr_rng_available); | ||
400 | if (err) | ||
401 | goto err_remove_current; | ||
402 | out: | ||
403 | return err; | ||
404 | |||
405 | err_remove_current: | ||
406 | device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current); | ||
407 | err_misc_dereg: | ||
408 | misc_deregister(&rng_miscdev); | ||
409 | goto out; | ||
410 | } | 398 | } |
411 | 399 | ||
412 | static int hwrng_fillfn(void *unused) | 400 | static int hwrng_fillfn(void *unused) |