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

HID: gt683r: move mode attribute to led-class devices

Move led_mode attribute from HID device to led-class devices and
rename it mode. This will also fix race condition by using
attribute-groups.

(cooloney@gmai.com: fix a typo in commit message)

Signed-off-by: Janne Kanniainen <janne.kanniainen@gmail.com>
Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

authored by

Janne Kanniainen and committed by
Bryan Wu
6522fe1c c3883ae9

+28 -14
+4 -2
Documentation/ABI/testing/sysfs-class-hid-driver-gt683r Documentation/ABI/testing/sysfs-class-leds-gt683r
··· 1 - What: /sys/class/hidraw/<hidraw>/device/leds_mode 1 + What: /sys/class/leds/<led>/gt683r/mode 2 2 Date: Jun 2014 3 3 KernelVersion: 3.17 4 4 Contact: Janne Kanniainen <janne.kanniainen@gmail.com> 5 5 Description: 6 - Set the mode of LEDs 6 + Set the mode of LEDs. You should notice that changing the mode 7 + of one LED will update the mode of its two sibling devices as 8 + well. 7 9 8 10 0 - normal 9 11 1 - audio
+24 -12
drivers/hid/hid-gt683r.c
··· 84 84 } 85 85 } 86 86 87 - static ssize_t leds_mode_show(struct device *dev, 87 + static ssize_t mode_show(struct device *dev, 88 88 struct device_attribute *attr, 89 89 char *buf) 90 90 { 91 91 u8 sysfs_mode; 92 - struct hid_device *hdev = container_of(dev, struct hid_device, dev); 92 + struct hid_device *hdev = container_of(dev->parent, 93 + struct hid_device, dev); 93 94 struct gt683r_led *led = hid_get_drvdata(hdev); 94 95 95 96 if (led->mode == GT683R_LED_NORMAL) ··· 103 102 return scnprintf(buf, PAGE_SIZE, "%u\n", sysfs_mode); 104 103 } 105 104 106 - static ssize_t leds_mode_store(struct device *dev, 105 + static ssize_t mode_store(struct device *dev, 107 106 struct device_attribute *attr, 108 107 const char *buf, size_t count) 109 108 { 110 109 u8 sysfs_mode; 111 - struct hid_device *hdev = container_of(dev, struct hid_device, dev); 110 + struct hid_device *hdev = container_of(dev->parent, 111 + struct hid_device, dev); 112 112 struct gt683r_led *led = hid_get_drvdata(hdev); 113 113 114 114 ··· 214 212 mutex_unlock(&led->lock); 215 213 } 216 214 217 - static DEVICE_ATTR_RW(leds_mode); 215 + static DEVICE_ATTR_RW(mode); 216 + 217 + static struct attribute *gt683r_led_attrs[] = { 218 + &dev_attr_mode.attr, 219 + NULL 220 + }; 221 + 222 + static const struct attribute_group gt683r_led_group = { 223 + .name = "gt683r", 224 + .attrs = gt683r_led_attrs, 225 + }; 226 + 227 + static const struct attribute_group *gt683r_led_groups[] = { 228 + &gt683r_led_group, 229 + NULL 230 + }; 218 231 219 232 static int gt683r_led_probe(struct hid_device *hdev, 220 233 const struct hid_device_id *id) ··· 278 261 led->led_devs[i].name = name; 279 262 led->led_devs[i].max_brightness = 1; 280 263 led->led_devs[i].brightness_set = gt683r_brightness_set; 264 + led->led_devs[i].groups = gt683r_led_groups; 265 + 281 266 ret = led_classdev_register(&hdev->dev, &led->led_devs[i]); 282 267 if (ret) { 283 268 hid_err(hdev, "could not register led device\n"); 284 269 goto fail; 285 270 } 286 - } 287 - 288 - ret = device_create_file(&led->hdev->dev, &dev_attr_leds_mode); 289 - if (ret) { 290 - hid_err(hdev, "could not make mode attribute file\n"); 291 - goto fail; 292 271 } 293 272 294 273 return 0; ··· 301 288 int i; 302 289 struct gt683r_led *led = hid_get_drvdata(hdev); 303 290 304 - device_remove_file(&hdev->dev, &dev_attr_leds_mode); 305 291 for (i = 0; i < GT683R_LED_COUNT; i++) 306 292 led_classdev_unregister(&led->led_devs[i]); 307 293 flush_work(&led->work);