diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-08-06 10:44:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-08-09 01:55:44 -0400 |
commit | c847a36521b08dbdaa4a23cb0795c0ee01241f8f (patch) | |
tree | 00a4329083a982e6d2a32353b0c7ab37bf4eec71 | |
parent | 761ef1e4bc20e7b47e17be3022a2eae87de30560 (diff) |
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>
-rw-r--r-- | drivers/usb/misc/cytherm.c | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c index 8b15ab5e1450..3e3802aaefa3 100644 --- a/drivers/usb/misc/cytherm.c +++ b/drivers/usb/misc/cytherm.c | |||
@@ -36,20 +36,6 @@ struct usb_cytherm { | |||
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 | /* Vendor requests */ | 39 | /* Vendor requests */ |
54 | /* They all operate on one byte at a time */ | 40 | /* They all operate on one byte at a time */ |
55 | #define PING 0x00 | 41 | #define PING 0x00 |
@@ -304,6 +290,15 @@ static ssize_t port1_store(struct device *dev, struct device_attribute *attr, co | |||
304 | } | 290 | } |
305 | static DEVICE_ATTR_RW(port1); | 291 | static DEVICE_ATTR_RW(port1); |
306 | 292 | ||
293 | static struct attribute *cytherm_attrs[] = { | ||
294 | &dev_attr_brightness.attr, | ||
295 | &dev_attr_temp.attr, | ||
296 | &dev_attr_button.attr, | ||
297 | &dev_attr_port0.attr, | ||
298 | &dev_attr_port1.attr, | ||
299 | NULL, | ||
300 | }; | ||
301 | ATTRIBUTE_GROUPS(cytherm); | ||
307 | 302 | ||
308 | static int cytherm_probe(struct usb_interface *interface, | 303 | static int cytherm_probe(struct usb_interface *interface, |
309 | const struct usb_device_id *id) | 304 | const struct usb_device_id *id) |
@@ -322,34 +317,10 @@ static int cytherm_probe(struct usb_interface *interface, | |||
322 | 317 | ||
323 | dev->brightness = 0xFF; | 318 | dev->brightness = 0xFF; |
324 | 319 | ||
325 | retval = device_create_file(&interface->dev, &dev_attr_brightness); | ||
326 | if (retval) | ||
327 | goto error; | ||
328 | retval = device_create_file(&interface->dev, &dev_attr_temp); | ||
329 | if (retval) | ||
330 | goto error; | ||
331 | retval = device_create_file(&interface->dev, &dev_attr_button); | ||
332 | if (retval) | ||
333 | goto error; | ||
334 | retval = device_create_file(&interface->dev, &dev_attr_port0); | ||
335 | if (retval) | ||
336 | goto error; | ||
337 | retval = device_create_file(&interface->dev, &dev_attr_port1); | ||
338 | if (retval) | ||
339 | goto error; | ||
340 | |||
341 | dev_info (&interface->dev, | 320 | dev_info (&interface->dev, |
342 | "Cypress thermometer device now attached\n"); | 321 | "Cypress thermometer device now attached\n"); |
343 | return 0; | 322 | return 0; |
344 | error: | 323 | |
345 | device_remove_file(&interface->dev, &dev_attr_brightness); | ||
346 | device_remove_file(&interface->dev, &dev_attr_temp); | ||
347 | device_remove_file(&interface->dev, &dev_attr_button); | ||
348 | device_remove_file(&interface->dev, &dev_attr_port0); | ||
349 | device_remove_file(&interface->dev, &dev_attr_port1); | ||
350 | usb_set_intfdata (interface, NULL); | ||
351 | usb_put_dev(dev->udev); | ||
352 | kfree(dev); | ||
353 | error_mem: | 324 | error_mem: |
354 | return retval; | 325 | return retval; |
355 | } | 326 | } |
@@ -360,12 +331,6 @@ static void cytherm_disconnect(struct usb_interface *interface) | |||
360 | 331 | ||
361 | dev = usb_get_intfdata (interface); | 332 | dev = usb_get_intfdata (interface); |
362 | 333 | ||
363 | device_remove_file(&interface->dev, &dev_attr_brightness); | ||
364 | device_remove_file(&interface->dev, &dev_attr_temp); | ||
365 | device_remove_file(&interface->dev, &dev_attr_button); | ||
366 | device_remove_file(&interface->dev, &dev_attr_port0); | ||
367 | device_remove_file(&interface->dev, &dev_attr_port1); | ||
368 | |||
369 | /* first remove the files, then NULL the pointer */ | 334 | /* first remove the files, then NULL the pointer */ |
370 | usb_set_intfdata (interface, NULL); | 335 | usb_set_intfdata (interface, NULL); |
371 | 336 | ||
@@ -376,6 +341,15 @@ static void cytherm_disconnect(struct usb_interface *interface) | |||
376 | dev_info(&interface->dev, "Cypress thermometer now disconnected\n"); | 341 | dev_info(&interface->dev, "Cypress thermometer now disconnected\n"); |
377 | } | 342 | } |
378 | 343 | ||
344 | /* usb specific object needed to register this driver with the usb subsystem */ | ||
345 | static struct usb_driver cytherm_driver = { | ||
346 | .name = "cytherm", | ||
347 | .probe = cytherm_probe, | ||
348 | .disconnect = cytherm_disconnect, | ||
349 | .id_table = id_table, | ||
350 | .dev_groups = cytherm_groups, | ||
351 | }; | ||
352 | |||
379 | module_usb_driver(cytherm_driver); | 353 | module_usb_driver(cytherm_driver); |
380 | 354 | ||
381 | MODULE_AUTHOR(DRIVER_AUTHOR); | 355 | MODULE_AUTHOR(DRIVER_AUTHOR); |