Commit 43691da4cefcf0d0dd6432f9e7e0dba902b59597

Authored by Greg Kroah-Hartman
1 parent 54d29ad33e

UIO: fix race in device_create

There is a race from when a device is created with device_create() and
then the drvdata is set with a call to dev_set_drvdata() in which a
sysfs file could be open, yet the drvdata will be NULL, causing all
sorts of bad things to happen.

This patch fixes the problem by using the new function,
device_create_drvdata().

Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 3 additions and 4 deletions Side-by-side Diff

... ... @@ -649,15 +649,14 @@
649 649 if (ret)
650 650 goto err_get_minor;
651 651  
652   - idev->dev = device_create(uio_class->class, parent,
653   - MKDEV(uio_major, idev->minor),
654   - "uio%d", idev->minor);
  652 + idev->dev = device_create_drvdata(uio_class->class, parent,
  653 + MKDEV(uio_major, idev->minor), idev,
  654 + "uio%d", idev->minor);
655 655 if (IS_ERR(idev->dev)) {
656 656 printk(KERN_ERR "UIO: device register failed\n");
657 657 ret = PTR_ERR(idev->dev);
658 658 goto err_device_create;
659 659 }
660   - dev_set_drvdata(idev->dev, idev);
661 660  
662 661 ret = uio_dev_add_attributes(idev);
663 662 if (ret)