Skip to content

Commit 0daa7a0

Browse files
tiwaigregkh
authored andcommitted
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>
1 parent bd73599 commit 0daa7a0

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

‎drivers/char/hw_random/core.c‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,14 @@ static const struct file_operations rng_chrdev_ops = {
299299
.llseek = noop_llseek,
300300
};
301301

302+
static const struct attribute_group *rng_dev_groups[];
303+
302304
static struct miscdevice rng_miscdev = {
303305
.minor = RNG_MISCDEV_MINOR,
304306
.name = RNG_MODULE_NAME,
305307
.nodename = "hwrng",
306308
.fops = &rng_chrdev_ops,
309+
.groups = rng_dev_groups,
307310
};
308311

309312

@@ -376,37 +379,22 @@ static DEVICE_ATTR(rng_available, S_IRUGO,
376379
hwrng_attr_available_show,
377380
NULL);
378381

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);
379389

380390
static void __exit unregister_miscdev(void)
381391
{
382-
device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available);
383-
device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
384392
misc_deregister(&rng_miscdev);
385393
}
386394

387395
static int __init register_miscdev(void)
388396
{
389-
int err;
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;
397+
return misc_register(&rng_miscdev);
410398
}
411399

412400
static int hwrng_fillfn(void *unused)

0 commit comments

Comments
 (0)