Skip to content

Commit

Permalink
UIO: fix race in device_create
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Greg Kroah-Hartman committed May 20, 2008
1 parent 54d29ad commit 43691da
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions drivers/uio/uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,15 +649,14 @@ int __uio_register_device(struct module *owner,
if (ret)
goto err_get_minor;

idev->dev = device_create(uio_class->class, parent,
MKDEV(uio_major, idev->minor),
"uio%d", idev->minor);
idev->dev = device_create_drvdata(uio_class->class, parent,
MKDEV(uio_major, idev->minor), idev,
"uio%d", idev->minor);
if (IS_ERR(idev->dev)) {
printk(KERN_ERR "UIO: device register failed\n");
ret = PTR_ERR(idev->dev);
goto err_device_create;
}
dev_set_drvdata(idev->dev, idev);

ret = uio_dev_add_attributes(idev);
if (ret)
Expand Down

0 comments on commit 43691da

Please sign in to comment.