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

USB: cypress_cy7c63: 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.

Link: https://lore.kernel.org/r/20190806144502.17792-8-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+8 -21
+8 -21
drivers/usb/misc/cypress_cy7c63.c
··· 183 183 { 184 184 return read_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0); 185 185 } 186 + static DEVICE_ATTR_RW(port0); 186 187 187 188 /* attribute callback handler (read) */ 188 189 static ssize_t port1_show(struct device *dev, ··· 191 190 { 192 191 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1); 193 192 } 194 - 195 - static DEVICE_ATTR_RW(port0); 196 - 197 193 static DEVICE_ATTR_RW(port1); 198 194 195 + static struct attribute *cypress_attrs[] = { 196 + &dev_attr_port0.attr, 197 + &dev_attr_port1.attr, 198 + NULL, 199 + }; 200 + ATTRIBUTE_GROUPS(cypress); 199 201 200 202 static int cypress_probe(struct usb_interface *interface, 201 203 const struct usb_device_id *id) ··· 216 212 /* save our data pointer in this interface device */ 217 213 usb_set_intfdata(interface, dev); 218 214 219 - /* create device attribute files */ 220 - retval = device_create_file(&interface->dev, &dev_attr_port0); 221 - if (retval) 222 - goto error; 223 - retval = device_create_file(&interface->dev, &dev_attr_port1); 224 - if (retval) 225 - goto error; 226 - 227 215 /* let the user know that the device is now attached */ 228 216 dev_info(&interface->dev, 229 217 "Cypress CY7C63xxx device now attached\n"); 230 218 return 0; 231 - 232 - error: 233 - device_remove_file(&interface->dev, &dev_attr_port0); 234 - device_remove_file(&interface->dev, &dev_attr_port1); 235 - usb_set_intfdata(interface, NULL); 236 - usb_put_dev(dev->udev); 237 - kfree(dev); 238 219 239 220 error_mem: 240 221 return retval; ··· 231 242 232 243 dev = usb_get_intfdata(interface); 233 244 234 - /* remove device attribute files */ 235 - device_remove_file(&interface->dev, &dev_attr_port0); 236 - device_remove_file(&interface->dev, &dev_attr_port1); 237 245 /* the intfdata can be set to NULL only after the 238 246 * device files have been removed */ 239 247 usb_set_intfdata(interface, NULL); ··· 248 262 .probe = cypress_probe, 249 263 .disconnect = cypress_disconnect, 250 264 .id_table = cypress_table, 265 + .dev_groups = cypress_groups, 251 266 }; 252 267 253 268 module_usb_driver(cypress_driver);