USB: usbsevseg: convert to use dev_groups
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 6 Aug 2019 14:45:01 +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.

Link: https://lore.kernel.org/r/20190806144502.17792-12-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/usbsevseg.c

index 1923d5b..551074f 100644 (file)
@@ -316,7 +316,7 @@ MYDEV_ATTR_SIMPLE_UNSIGNED(powered, update_display_powered);
 MYDEV_ATTR_SIMPLE_UNSIGNED(mode_msb, update_display_mode);
 MYDEV_ATTR_SIMPLE_UNSIGNED(mode_lsb, update_display_mode);
 
-static struct attribute *dev_attrs[] = {
+static struct attribute *sevseg_attrs[] = {
        &dev_attr_powered.attr,
        &dev_attr_text.attr,
        &dev_attr_textmode.attr,
@@ -325,10 +325,7 @@ static struct attribute *dev_attrs[] = {
        &dev_attr_mode_lsb.attr,
        NULL
 };
-
-static const struct attribute_group dev_attr_grp = {
-       .attrs = dev_attrs,
-};
+ATTRIBUTE_GROUPS(sevseg);
 
 static int sevseg_probe(struct usb_interface *interface,
        const struct usb_device_id *id)
@@ -354,17 +351,9 @@ static int sevseg_probe(struct usb_interface *interface,
        mydev->mode_msb = 0x06; /* 6 characters */
        mydev->mode_lsb = 0x3f; /* scanmode for 6 chars */
 
-       rc = sysfs_create_group(&interface->dev.kobj, &dev_attr_grp);
-       if (rc)
-               goto error;
-
        dev_info(&interface->dev, "USB 7 Segment device now attached\n");
        return 0;
 
-error:
-       usb_set_intfdata(interface, NULL);
-       usb_put_dev(mydev->udev);
-       kfree(mydev);
 error_mem:
        return rc;
 }
@@ -374,7 +363,6 @@ static void sevseg_disconnect(struct usb_interface *interface)
        struct usb_sevsegdev *mydev;
 
        mydev = usb_get_intfdata(interface);
-       sysfs_remove_group(&interface->dev.kobj, &dev_attr_grp);
        usb_set_intfdata(interface, NULL);
        usb_put_dev(mydev->udev);
        kfree(mydev);
@@ -423,6 +411,7 @@ static struct usb_driver sevseg_driver = {
        .resume =       sevseg_resume,
        .reset_resume = sevseg_reset_resume,
        .id_table =     id_table,
+       .dev_groups =   sevseg_groups,
        .supports_autosuspend = 1,
 };