Commit bfd3a5a96c1dd432303fdf2283e770419f6aecb3

Authored by Greg Kroah-Hartman
1 parent c5fb920aec

USB: Phidget: 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().  It fixes all 3 phidget drivers, which all have
the same problem.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Sean Young <sean@mess.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 3 changed files with 9 additions and 10 deletions Side-by-side Diff

drivers/usb/misc/phidgetkit.c
... ... @@ -595,14 +595,14 @@
595 595 } while(value);
596 596 kit->dev_no = bit;
597 597  
598   - kit->dev = device_create(phidget_class, &kit->udev->dev, 0,
599   - "interfacekit%d", kit->dev_no);
  598 + kit->dev = device_create_drvdata(phidget_class, &kit->udev->dev,
  599 + MKDEV(0, 0), kit,
  600 + "interfacekit%d", kit->dev_no);
600 601 if (IS_ERR(kit->dev)) {
601 602 rc = PTR_ERR(kit->dev);
602 603 kit->dev = NULL;
603 604 goto out;
604 605 }
605   - dev_set_drvdata(kit->dev, kit);
606 606  
607 607 if (usb_submit_urb(kit->irq, GFP_KERNEL)) {
608 608 rc = -EIO;
drivers/usb/misc/phidgetmotorcontrol.c
... ... @@ -365,15 +365,14 @@
365 365 } while(value);
366 366 mc->dev_no = bit;
367 367  
368   - mc->dev = device_create(phidget_class, &mc->udev->dev, 0,
369   - "motorcontrol%d", mc->dev_no);
  368 + mc->dev = device_create_drvdata(phidget_class, &mc->udev->dev,
  369 + MKDEV(0, 0), mc,
  370 + "motorcontrol%d", mc->dev_no);
370 371 if (IS_ERR(mc->dev)) {
371 372 rc = PTR_ERR(mc->dev);
372 373 mc->dev = NULL;
373 374 goto out;
374 375 }
375   -
376   - dev_set_drvdata(mc->dev, mc);
377 376  
378 377 if (usb_submit_urb(mc->irq, GFP_KERNEL)) {
379 378 rc = -EIO;
drivers/usb/misc/phidgetservo.c
... ... @@ -275,14 +275,14 @@
275 275 } while (value);
276 276 dev->dev_no = bit;
277 277  
278   - dev->dev = device_create(phidget_class, &dev->udev->dev, 0,
279   - "servo%d", dev->dev_no);
  278 + dev->dev = device_create_drvdata(phidget_class, &dev->udev->dev,
  279 + MKDEV(0, 0), dev,
  280 + "servo%d", dev->dev_no);
280 281 if (IS_ERR(dev->dev)) {
281 282 rc = PTR_ERR(dev->dev);
282 283 dev->dev = NULL;
283 284 goto out;
284 285 }
285   - dev_set_drvdata(dev->dev, dev);
286 286  
287 287 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
288 288