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

USB: cytherm: 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-9-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+19 -45
+19 -45
drivers/usb/misc/cytherm.c
··· 36 36 }; 37 37 38 38 39 - /* local function prototypes */ 40 - static int cytherm_probe(struct usb_interface *interface, 41 - const struct usb_device_id *id); 42 - static void cytherm_disconnect(struct usb_interface *interface); 43 - 44 - 45 - /* usb specific object needed to register this driver with the usb subsystem */ 46 - static struct usb_driver cytherm_driver = { 47 - .name = "cytherm", 48 - .probe = cytherm_probe, 49 - .disconnect = cytherm_disconnect, 50 - .id_table = id_table, 51 - }; 52 - 53 39 /* Vendor requests */ 54 40 /* They all operate on one byte at a time */ 55 41 #define PING 0x00 ··· 290 304 } 291 305 static DEVICE_ATTR_RW(port1); 292 306 307 + static struct attribute *cytherm_attrs[] = { 308 + &dev_attr_brightness.attr, 309 + &dev_attr_temp.attr, 310 + &dev_attr_button.attr, 311 + &dev_attr_port0.attr, 312 + &dev_attr_port1.attr, 313 + NULL, 314 + }; 315 + ATTRIBUTE_GROUPS(cytherm); 293 316 294 317 static int cytherm_probe(struct usb_interface *interface, 295 318 const struct usb_device_id *id) ··· 317 322 318 323 dev->brightness = 0xFF; 319 324 320 - retval = device_create_file(&interface->dev, &dev_attr_brightness); 321 - if (retval) 322 - goto error; 323 - retval = device_create_file(&interface->dev, &dev_attr_temp); 324 - if (retval) 325 - goto error; 326 - retval = device_create_file(&interface->dev, &dev_attr_button); 327 - if (retval) 328 - goto error; 329 - retval = device_create_file(&interface->dev, &dev_attr_port0); 330 - if (retval) 331 - goto error; 332 - retval = device_create_file(&interface->dev, &dev_attr_port1); 333 - if (retval) 334 - goto error; 335 - 336 325 dev_info (&interface->dev, 337 326 "Cypress thermometer device now attached\n"); 338 327 return 0; 339 - error: 340 - device_remove_file(&interface->dev, &dev_attr_brightness); 341 - device_remove_file(&interface->dev, &dev_attr_temp); 342 - device_remove_file(&interface->dev, &dev_attr_button); 343 - device_remove_file(&interface->dev, &dev_attr_port0); 344 - device_remove_file(&interface->dev, &dev_attr_port1); 345 - usb_set_intfdata (interface, NULL); 346 - usb_put_dev(dev->udev); 347 - kfree(dev); 328 + 348 329 error_mem: 349 330 return retval; 350 331 } ··· 331 360 332 361 dev = usb_get_intfdata (interface); 333 362 334 - device_remove_file(&interface->dev, &dev_attr_brightness); 335 - device_remove_file(&interface->dev, &dev_attr_temp); 336 - device_remove_file(&interface->dev, &dev_attr_button); 337 - device_remove_file(&interface->dev, &dev_attr_port0); 338 - device_remove_file(&interface->dev, &dev_attr_port1); 339 - 340 363 /* first remove the files, then NULL the pointer */ 341 364 usb_set_intfdata (interface, NULL); 342 365 ··· 340 375 341 376 dev_info(&interface->dev, "Cypress thermometer now disconnected\n"); 342 377 } 378 + 379 + /* usb specific object needed to register this driver with the usb subsystem */ 380 + static struct usb_driver cytherm_driver = { 381 + .name = "cytherm", 382 + .probe = cytherm_probe, 383 + .disconnect = cytherm_disconnect, 384 + .id_table = id_table, 385 + .dev_groups = cytherm_groups, 386 + }; 343 387 344 388 module_usb_driver(cytherm_driver); 345 389