Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: trancevibrator: convert to use dev_groups

USB drivers now support the ability for the driver core to handle the
creation and removal of device-specific sysfs files in a race-free
manner. Take advantage of that by converting the driver to use this by
moving the sysfs attributes into a group and assigning the dev_groups
pointer to it.

Cc: Ding Xiang <dingxiang@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20190806144502.17792-11-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+7 -8
+7 -8
drivers/usb/misc/trancevibrator.c
··· 71 71 } 72 72 return count; 73 73 } 74 - 75 74 static DEVICE_ATTR_RW(speed); 75 + 76 + static struct attribute *tv_attrs[] = { 77 + &dev_attr_speed.attr, 78 + NULL, 79 + }; 80 + ATTRIBUTE_GROUPS(tv); 76 81 77 82 static int tv_probe(struct usb_interface *interface, 78 83 const struct usb_device_id *id) ··· 94 89 95 90 dev->udev = usb_get_dev(udev); 96 91 usb_set_intfdata(interface, dev); 97 - retval = device_create_file(&interface->dev, &dev_attr_speed); 98 - if (retval) 99 - goto error_create_file; 100 92 101 93 return 0; 102 94 103 - error_create_file: 104 - usb_put_dev(udev); 105 - usb_set_intfdata(interface, NULL); 106 95 error: 107 96 kfree(dev); 108 97 return retval; ··· 107 108 struct trancevibrator *dev; 108 109 109 110 dev = usb_get_intfdata (interface); 110 - device_remove_file(&interface->dev, &dev_attr_speed); 111 111 usb_set_intfdata(interface, NULL); 112 112 usb_put_dev(dev->udev); 113 113 kfree(dev); ··· 118 120 .probe = tv_probe, 119 121 .disconnect = tv_disconnect, 120 122 .id_table = id_table, 123 + .dev_groups = tv_groups, 121 124 }; 122 125 123 126 module_usb_driver(tv_driver);