USB: usbip: convert to use dev_groups
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 6 Aug 2019 14:45:02 +0000 (16:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Aug 2019 05:55:45 +0000 (07:55 +0200)
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: Valentina Manea <valentina.manea.m@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Link: https://lore.kernel.org/r/20190806144502.17792-13-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/usbip/stub_dev.c

index 7931e6c..2305d42 100644 (file)
@@ -106,38 +106,13 @@ err:
 }
 static DEVICE_ATTR_WO(usbip_sockfd);
 
-static int stub_add_files(struct device *dev)
-{
-       int err = 0;
-
-       err = device_create_file(dev, &dev_attr_usbip_status);
-       if (err)
-               goto err_status;
-
-       err = device_create_file(dev, &dev_attr_usbip_sockfd);
-       if (err)
-               goto err_sockfd;
-
-       err = device_create_file(dev, &dev_attr_usbip_debug);
-       if (err)
-               goto err_debug;
-
-       return 0;
-
-err_debug:
-       device_remove_file(dev, &dev_attr_usbip_sockfd);
-err_sockfd:
-       device_remove_file(dev, &dev_attr_usbip_status);
-err_status:
-       return err;
-}
-
-static void stub_remove_files(struct device *dev)
-{
-       device_remove_file(dev, &dev_attr_usbip_status);
-       device_remove_file(dev, &dev_attr_usbip_sockfd);
-       device_remove_file(dev, &dev_attr_usbip_debug);
-}
+static struct attribute *usbip_attrs[] = {
+       &dev_attr_usbip_status.attr,
+       &dev_attr_usbip_sockfd.attr,
+       &dev_attr_usbip_debug.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(usbip);
 
 static void stub_shutdown_connection(struct usbip_device *ud)
 {
@@ -379,17 +354,8 @@ static int stub_probe(struct usb_device *udev)
                goto err_port;
        }
 
-       rc = stub_add_files(&udev->dev);
-       if (rc) {
-               dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid);
-               goto err_files;
-       }
-
        return 0;
 
-err_files:
-       usb_hub_release_port(udev->parent, udev->portnum,
-                            (struct usb_dev_state *) udev);
 err_port:
        dev_set_drvdata(&udev->dev, NULL);
        usb_put_dev(udev);
@@ -457,7 +423,6 @@ static void stub_disconnect(struct usb_device *udev)
        /*
         * NOTE: rx/tx threads are invoked for each usb_device.
         */
-       stub_remove_files(&udev->dev);
 
        /* release port */
        rc = usb_hub_release_port(udev->parent, udev->portnum,
@@ -526,4 +491,5 @@ struct usb_device_driver stub_driver = {
        .resume         = stub_resume,
 #endif
        .supports_autosuspend   =       0,
+       .dev_groups     = usbip_groups,
 };