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

USB: core: be specific about attribute permissions

Instead of having to audit all sysfs attributes, to ensure we get them
right, use the default macros the driver core provides us (read-only,
read-write) to make the code simpler, and to prevent any mistakes from
ever happening.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+166 -197
+18 -18
drivers/usb/core/endpoint.c
··· 32 32 container_of(_attr, struct ep_attribute, attr) 33 33 34 34 #define usb_ep_attr(field, format_string) \ 35 - static ssize_t show_ep_##field(struct device *dev, \ 35 + static ssize_t field##_show(struct device *dev, \ 36 36 struct device_attribute *attr, \ 37 37 char *buf) \ 38 38 { \ 39 39 struct ep_device *ep = to_ep_device(dev); \ 40 40 return sprintf(buf, format_string, ep->desc->field); \ 41 41 } \ 42 - static DEVICE_ATTR(field, S_IRUGO, show_ep_##field, NULL); 42 + static DEVICE_ATTR_RO(field) 43 43 44 - usb_ep_attr(bLength, "%02x\n") 45 - usb_ep_attr(bEndpointAddress, "%02x\n") 46 - usb_ep_attr(bmAttributes, "%02x\n") 47 - usb_ep_attr(bInterval, "%02x\n") 44 + usb_ep_attr(bLength, "%02x\n"); 45 + usb_ep_attr(bEndpointAddress, "%02x\n"); 46 + usb_ep_attr(bmAttributes, "%02x\n"); 47 + usb_ep_attr(bInterval, "%02x\n"); 48 48 49 - static ssize_t show_ep_wMaxPacketSize(struct device *dev, 50 - struct device_attribute *attr, char *buf) 49 + static ssize_t wMaxPacketSize_show(struct device *dev, 50 + struct device_attribute *attr, char *buf) 51 51 { 52 52 struct ep_device *ep = to_ep_device(dev); 53 53 return sprintf(buf, "%04x\n", 54 54 usb_endpoint_maxp(ep->desc) & 0x07ff); 55 55 } 56 - static DEVICE_ATTR(wMaxPacketSize, S_IRUGO, show_ep_wMaxPacketSize, NULL); 56 + static DEVICE_ATTR_RO(wMaxPacketSize); 57 57 58 - static ssize_t show_ep_type(struct device *dev, struct device_attribute *attr, 59 - char *buf) 58 + static ssize_t type_show(struct device *dev, struct device_attribute *attr, 59 + char *buf) 60 60 { 61 61 struct ep_device *ep = to_ep_device(dev); 62 62 char *type = "unknown"; ··· 77 77 } 78 78 return sprintf(buf, "%s\n", type); 79 79 } 80 - static DEVICE_ATTR(type, S_IRUGO, show_ep_type, NULL); 80 + static DEVICE_ATTR_RO(type); 81 81 82 - static ssize_t show_ep_interval(struct device *dev, 83 - struct device_attribute *attr, char *buf) 82 + static ssize_t interval_show(struct device *dev, struct device_attribute *attr, 83 + char *buf) 84 84 { 85 85 struct ep_device *ep = to_ep_device(dev); 86 86 char unit; ··· 123 123 124 124 return sprintf(buf, "%d%cs\n", interval, unit); 125 125 } 126 - static DEVICE_ATTR(interval, S_IRUGO, show_ep_interval, NULL); 126 + static DEVICE_ATTR_RO(interval); 127 127 128 - static ssize_t show_ep_direction(struct device *dev, 129 - struct device_attribute *attr, char *buf) 128 + static ssize_t direction_show(struct device *dev, struct device_attribute *attr, 129 + char *buf) 130 130 { 131 131 struct ep_device *ep = to_ep_device(dev); 132 132 char *direction; ··· 139 139 direction = "out"; 140 140 return sprintf(buf, "%s\n", direction); 141 141 } 142 - static DEVICE_ATTR(direction, S_IRUGO, show_ep_direction, NULL); 142 + static DEVICE_ATTR_RO(direction); 143 143 144 144 static struct attribute *ep_dev_attrs[] = { 145 145 &dev_attr_bLength.attr,
+6 -11
drivers/usb/core/hcd.c
··· 849 849 /* 850 850 * Show & store the current value of authorized_default 851 851 */ 852 - static ssize_t usb_host_authorized_default_show(struct device *dev, 853 - struct device_attribute *attr, 854 - char *buf) 852 + static ssize_t authorized_default_show(struct device *dev, 853 + struct device_attribute *attr, char *buf) 855 854 { 856 855 struct usb_device *rh_usb_dev = to_usb_device(dev); 857 856 struct usb_bus *usb_bus = rh_usb_dev->bus; ··· 862 863 return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); 863 864 } 864 865 865 - static ssize_t usb_host_authorized_default_store(struct device *dev, 866 - struct device_attribute *attr, 867 - const char *buf, size_t size) 866 + static ssize_t authorized_default_store(struct device *dev, 867 + struct device_attribute *attr, 868 + const char *buf, size_t size) 868 869 { 869 870 ssize_t result; 870 871 unsigned val; ··· 884 885 result = -EINVAL; 885 886 return result; 886 887 } 887 - 888 - static DEVICE_ATTR(authorized_default, 0644, 889 - usb_host_authorized_default_show, 890 - usb_host_authorized_default_store); 891 - 888 + static DEVICE_ATTR_RW(authorized_default); 892 889 893 890 /* Group all the USB bus attributes */ 894 891 static struct attribute *usb_bus_attrs[] = {
+3 -4
drivers/usb/core/port.c
··· 23 23 24 24 static const struct attribute_group *port_dev_group[]; 25 25 26 - static ssize_t show_port_connect_type(struct device *dev, 27 - struct device_attribute *attr, char *buf) 26 + static ssize_t connect_type_show(struct device *dev, 27 + struct device_attribute *attr, char *buf) 28 28 { 29 29 struct usb_port *port_dev = to_usb_port(dev); 30 30 char *result; ··· 46 46 47 47 return sprintf(buf, "%s\n", result); 48 48 } 49 - static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type, 50 - NULL); 49 + static DEVICE_ATTR_RO(connect_type); 51 50 52 51 static struct attribute *port_dev_attrs[] = { 53 52 &dev_attr_connect_type.attr,
+139 -164
drivers/usb/core/sysfs.c
··· 18 18 19 19 /* Active configuration fields */ 20 20 #define usb_actconfig_show(field, format_string) \ 21 - static ssize_t show_##field(struct device *dev, \ 22 - struct device_attribute *attr, char *buf) \ 21 + static ssize_t field##_show(struct device *dev, \ 22 + struct device_attribute *attr, char *buf) \ 23 23 { \ 24 24 struct usb_device *udev; \ 25 25 struct usb_host_config *actconfig; \ ··· 35 35 36 36 #define usb_actconfig_attr(field, format_string) \ 37 37 usb_actconfig_show(field, format_string) \ 38 - static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 38 + static DEVICE_ATTR_RO(field) 39 39 40 - usb_actconfig_attr(bNumInterfaces, "%2d\n") 41 - usb_actconfig_attr(bmAttributes, "%2x\n") 40 + usb_actconfig_attr(bNumInterfaces, "%2d\n"); 41 + usb_actconfig_attr(bmAttributes, "%2x\n"); 42 42 43 - static ssize_t show_bMaxPower(struct device *dev, 43 + static ssize_t bMaxPower_show(struct device *dev, 44 44 struct device_attribute *attr, char *buf) 45 45 { 46 46 struct usb_device *udev; ··· 52 52 return 0; 53 53 return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 54 54 } 55 - static DEVICE_ATTR(bMaxPower, S_IRUGO, show_bMaxPower, NULL); 55 + static DEVICE_ATTR_RO(bMaxPower); 56 56 57 - static ssize_t show_configuration_string(struct device *dev, 57 + static ssize_t configuration_show(struct device *dev, 58 58 struct device_attribute *attr, char *buf) 59 59 { 60 60 struct usb_device *udev; ··· 66 66 return 0; 67 67 return sprintf(buf, "%s\n", actconfig->string); 68 68 } 69 - static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL); 69 + static DEVICE_ATTR_RO(configuration); 70 70 71 71 /* configuration value is always present, and r/w */ 72 72 usb_actconfig_show(bConfigurationValue, "%u\n"); 73 73 74 - static ssize_t 75 - set_bConfigurationValue(struct device *dev, struct device_attribute *attr, 76 - const char *buf, size_t count) 74 + static ssize_t bConfigurationValue_store(struct device *dev, 75 + struct device_attribute *attr, 76 + const char *buf, size_t count) 77 77 { 78 78 struct usb_device *udev = to_usb_device(dev); 79 79 int config, value; ··· 85 85 usb_unlock_device(udev); 86 86 return (value < 0) ? value : count; 87 87 } 88 - 89 88 static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue, S_IRUGO | S_IWUSR, 90 - show_bConfigurationValue, set_bConfigurationValue); 89 + bConfigurationValue_show, bConfigurationValue_store); 91 90 92 91 /* String fields */ 93 92 #define usb_string_attr(name) \ 94 - static ssize_t show_##name(struct device *dev, \ 93 + static ssize_t name##_show(struct device *dev, \ 95 94 struct device_attribute *attr, char *buf) \ 96 95 { \ 97 96 struct usb_device *udev; \ ··· 102 103 usb_unlock_device(udev); \ 103 104 return retval; \ 104 105 } \ 105 - static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 106 + static DEVICE_ATTR_RO(name) 106 107 107 108 usb_string_attr(product); 108 109 usb_string_attr(manufacturer); 109 110 usb_string_attr(serial); 110 111 111 - static ssize_t 112 - show_speed(struct device *dev, struct device_attribute *attr, char *buf) 112 + static ssize_t speed_show(struct device *dev, struct device_attribute *attr, 113 + char *buf) 113 114 { 114 115 struct usb_device *udev; 115 116 char *speed; ··· 138 139 } 139 140 return sprintf(buf, "%s\n", speed); 140 141 } 141 - static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL); 142 + static DEVICE_ATTR_RO(speed); 142 143 143 - static ssize_t 144 - show_busnum(struct device *dev, struct device_attribute *attr, char *buf) 144 + static ssize_t busnum_show(struct device *dev, struct device_attribute *attr, 145 + char *buf) 145 146 { 146 147 struct usb_device *udev; 147 148 148 149 udev = to_usb_device(dev); 149 150 return sprintf(buf, "%d\n", udev->bus->busnum); 150 151 } 151 - static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL); 152 + static DEVICE_ATTR_RO(busnum); 152 153 153 - static ssize_t 154 - show_devnum(struct device *dev, struct device_attribute *attr, char *buf) 154 + static ssize_t devnum_show(struct device *dev, struct device_attribute *attr, 155 + char *buf) 155 156 { 156 157 struct usb_device *udev; 157 158 158 159 udev = to_usb_device(dev); 159 160 return sprintf(buf, "%d\n", udev->devnum); 160 161 } 161 - static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL); 162 + static DEVICE_ATTR_RO(devnum); 162 163 163 - static ssize_t 164 - show_devpath(struct device *dev, struct device_attribute *attr, char *buf) 164 + static ssize_t devpath_show(struct device *dev, struct device_attribute *attr, 165 + char *buf) 165 166 { 166 167 struct usb_device *udev; 167 168 168 169 udev = to_usb_device(dev); 169 170 return sprintf(buf, "%s\n", udev->devpath); 170 171 } 171 - static DEVICE_ATTR(devpath, S_IRUGO, show_devpath, NULL); 172 + static DEVICE_ATTR_RO(devpath); 172 173 173 - static ssize_t 174 - show_version(struct device *dev, struct device_attribute *attr, char *buf) 174 + static ssize_t version_show(struct device *dev, struct device_attribute *attr, 175 + char *buf) 175 176 { 176 177 struct usb_device *udev; 177 178 u16 bcdUSB; ··· 180 181 bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB); 181 182 return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff); 182 183 } 183 - static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); 184 + static DEVICE_ATTR_RO(version); 184 185 185 - static ssize_t 186 - show_maxchild(struct device *dev, struct device_attribute *attr, char *buf) 186 + static ssize_t maxchild_show(struct device *dev, struct device_attribute *attr, 187 + char *buf) 187 188 { 188 189 struct usb_device *udev; 189 190 190 191 udev = to_usb_device(dev); 191 192 return sprintf(buf, "%d\n", udev->maxchild); 192 193 } 193 - static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL); 194 + static DEVICE_ATTR_RO(maxchild); 194 195 195 - static ssize_t 196 - show_quirks(struct device *dev, struct device_attribute *attr, char *buf) 196 + static ssize_t quirks_show(struct device *dev, struct device_attribute *attr, 197 + char *buf) 197 198 { 198 199 struct usb_device *udev; 199 200 200 201 udev = to_usb_device(dev); 201 202 return sprintf(buf, "0x%x\n", udev->quirks); 202 203 } 203 - static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); 204 + static DEVICE_ATTR_RO(quirks); 204 205 205 - static ssize_t 206 - show_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, char *buf) 206 + static ssize_t avoid_reset_quirk_show(struct device *dev, 207 + struct device_attribute *attr, char *buf) 207 208 { 208 209 struct usb_device *udev; 209 210 ··· 211 212 return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET)); 212 213 } 213 214 214 - static ssize_t 215 - set_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, 216 - const char *buf, size_t count) 215 + static ssize_t avoid_reset_quirk_store(struct device *dev, 216 + struct device_attribute *attr, 217 + const char *buf, size_t count) 217 218 { 218 219 struct usb_device *udev = to_usb_device(dev); 219 220 int val; ··· 228 229 usb_unlock_device(udev); 229 230 return count; 230 231 } 232 + static DEVICE_ATTR_RW(avoid_reset_quirk); 231 233 232 - static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR, 233 - show_avoid_reset_quirk, set_avoid_reset_quirk); 234 - 235 - static ssize_t 236 - show_urbnum(struct device *dev, struct device_attribute *attr, char *buf) 234 + static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr, 235 + char *buf) 237 236 { 238 237 struct usb_device *udev; 239 238 240 239 udev = to_usb_device(dev); 241 240 return sprintf(buf, "%d\n", atomic_read(&udev->urbnum)); 242 241 } 243 - static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); 242 + static DEVICE_ATTR_RO(urbnum); 244 243 245 - static ssize_t 246 - show_removable(struct device *dev, struct device_attribute *attr, char *buf) 244 + static ssize_t removable_show(struct device *dev, struct device_attribute *attr, 245 + char *buf) 247 246 { 248 247 struct usb_device *udev; 249 248 char *state; ··· 261 264 262 265 return sprintf(buf, "%s\n", state); 263 266 } 264 - static DEVICE_ATTR(removable, S_IRUGO, show_removable, NULL); 267 + static DEVICE_ATTR_RO(removable); 265 268 266 - static ssize_t 267 - show_ltm_capable(struct device *dev, struct device_attribute *attr, char *buf) 269 + static ssize_t ltm_capable_show(struct device *dev, 270 + struct device_attribute *attr, char *buf) 268 271 { 269 272 if (usb_device_supports_ltm(to_usb_device(dev))) 270 273 return sprintf(buf, "%s\n", "yes"); 271 274 return sprintf(buf, "%s\n", "no"); 272 275 } 273 - static DEVICE_ATTR(ltm_capable, S_IRUGO, show_ltm_capable, NULL); 276 + static DEVICE_ATTR_RO(ltm_capable); 274 277 275 278 #ifdef CONFIG_PM 276 279 277 - static ssize_t 278 - show_persist(struct device *dev, struct device_attribute *attr, char *buf) 280 + static ssize_t persist_show(struct device *dev, struct device_attribute *attr, 281 + char *buf) 279 282 { 280 283 struct usb_device *udev = to_usb_device(dev); 281 284 282 285 return sprintf(buf, "%d\n", udev->persist_enabled); 283 286 } 284 287 285 - static ssize_t 286 - set_persist(struct device *dev, struct device_attribute *attr, 287 - const char *buf, size_t count) 288 + static ssize_t persist_store(struct device *dev, struct device_attribute *attr, 289 + const char *buf, size_t count) 288 290 { 289 291 struct usb_device *udev = to_usb_device(dev); 290 292 int value; ··· 300 304 usb_unlock_device(udev); 301 305 return count; 302 306 } 303 - 304 - static DEVICE_ATTR(persist, S_IRUGO | S_IWUSR, show_persist, set_persist); 307 + static DEVICE_ATTR_RW(persist); 305 308 306 309 static int add_persist_attributes(struct device *dev) 307 310 { ··· 335 340 336 341 #ifdef CONFIG_PM_RUNTIME 337 342 338 - static ssize_t 339 - show_connected_duration(struct device *dev, struct device_attribute *attr, 340 - char *buf) 343 + static ssize_t connected_duration_show(struct device *dev, 344 + struct device_attribute *attr, char *buf) 341 345 { 342 346 struct usb_device *udev = to_usb_device(dev); 343 347 344 348 return sprintf(buf, "%u\n", 345 349 jiffies_to_msecs(jiffies - udev->connect_time)); 346 350 } 347 - 348 - static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL); 351 + static DEVICE_ATTR_RO(connected_duration); 349 352 350 353 /* 351 354 * If the device is resumed, the last time the device was suspended has ··· 352 359 * 353 360 * If the device is suspended, the active_duration is up-to-date. 354 361 */ 355 - static ssize_t 356 - show_active_duration(struct device *dev, struct device_attribute *attr, 357 - char *buf) 362 + static ssize_t active_duration_show(struct device *dev, 363 + struct device_attribute *attr, char *buf) 358 364 { 359 365 struct usb_device *udev = to_usb_device(dev); 360 366 int duration; ··· 364 372 duration = jiffies_to_msecs(udev->active_duration); 365 373 return sprintf(buf, "%u\n", duration); 366 374 } 375 + static DEVICE_ATTR_RO(active_duration); 367 376 368 - static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL); 369 - 370 - static ssize_t 371 - show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) 377 + static ssize_t autosuspend_show(struct device *dev, 378 + struct device_attribute *attr, char *buf) 372 379 { 373 380 return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000); 374 381 } 375 382 376 - static ssize_t 377 - set_autosuspend(struct device *dev, struct device_attribute *attr, 378 - const char *buf, size_t count) 383 + static ssize_t autosuspend_store(struct device *dev, 384 + struct device_attribute *attr, const char *buf, 385 + size_t count) 379 386 { 380 387 int value; 381 388 ··· 385 394 pm_runtime_set_autosuspend_delay(dev, value * 1000); 386 395 return count; 387 396 } 388 - 389 - static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR, 390 - show_autosuspend, set_autosuspend); 397 + static DEVICE_ATTR_RW(autosuspend); 391 398 392 399 static const char on_string[] = "on"; 393 400 static const char auto_string[] = "auto"; ··· 400 411 } 401 412 } 402 413 403 - static ssize_t 404 - show_level(struct device *dev, struct device_attribute *attr, char *buf) 414 + static ssize_t level_show(struct device *dev, struct device_attribute *attr, 415 + char *buf) 405 416 { 406 417 struct usb_device *udev = to_usb_device(dev); 407 418 const char *p = auto_string; ··· 412 423 return sprintf(buf, "%s\n", p); 413 424 } 414 425 415 - static ssize_t 416 - set_level(struct device *dev, struct device_attribute *attr, 417 - const char *buf, size_t count) 426 + static ssize_t level_store(struct device *dev, struct device_attribute *attr, 427 + const char *buf, size_t count) 418 428 { 419 429 struct usb_device *udev = to_usb_device(dev); 420 430 int len = count; ··· 441 453 usb_unlock_device(udev); 442 454 return rc; 443 455 } 456 + static DEVICE_ATTR_RW(level); 444 457 445 - static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); 446 - 447 - static ssize_t 448 - show_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr, 449 - char *buf) 458 + static ssize_t usb2_hardware_lpm_show(struct device *dev, 459 + struct device_attribute *attr, char *buf) 450 460 { 451 461 struct usb_device *udev = to_usb_device(dev); 452 462 const char *p; ··· 457 471 return sprintf(buf, "%s\n", p); 458 472 } 459 473 460 - static ssize_t 461 - set_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr, 462 - const char *buf, size_t count) 474 + static ssize_t usb2_hardware_lpm_store(struct device *dev, 475 + struct device_attribute *attr, 476 + const char *buf, size_t count) 463 477 { 464 478 struct usb_device *udev = to_usb_device(dev); 465 479 bool value; ··· 479 493 480 494 return ret; 481 495 } 496 + static DEVICE_ATTR_RW(usb2_hardware_lpm); 482 497 483 - static DEVICE_ATTR(usb2_hardware_lpm, S_IRUGO | S_IWUSR, show_usb2_hardware_lpm, 484 - set_usb2_hardware_lpm); 485 - 486 - static ssize_t 487 - show_usb2_lpm_l1_timeout(struct device *dev, struct device_attribute *attr, 488 - char *buf) 498 + static ssize_t usb2_lpm_l1_timeout_show(struct device *dev, 499 + struct device_attribute *attr, 500 + char *buf) 489 501 { 490 502 struct usb_device *udev = to_usb_device(dev); 491 503 return sprintf(buf, "%d\n", udev->l1_params.timeout); 492 504 } 493 505 494 - static ssize_t 495 - set_usb2_lpm_l1_timeout(struct device *dev, struct device_attribute *attr, 496 - const char *buf, size_t count) 506 + static ssize_t usb2_lpm_l1_timeout_store(struct device *dev, 507 + struct device_attribute *attr, 508 + const char *buf, size_t count) 497 509 { 498 510 struct usb_device *udev = to_usb_device(dev); 499 511 u16 timeout; ··· 503 519 504 520 return count; 505 521 } 522 + static DEVICE_ATTR_RW(usb2_lpm_l1_timeout); 506 523 507 - static DEVICE_ATTR(usb2_lpm_l1_timeout, S_IRUGO | S_IWUSR, 508 - show_usb2_lpm_l1_timeout, set_usb2_lpm_l1_timeout); 509 - 510 - static ssize_t 511 - show_usb2_lpm_besl(struct device *dev, struct device_attribute *attr, 512 - char *buf) 524 + static ssize_t usb2_lpm_besl_show(struct device *dev, 525 + struct device_attribute *attr, char *buf) 513 526 { 514 527 struct usb_device *udev = to_usb_device(dev); 515 528 return sprintf(buf, "%d\n", udev->l1_params.besl); 516 529 } 517 530 518 - static ssize_t 519 - set_usb2_lpm_besl(struct device *dev, struct device_attribute *attr, 520 - const char *buf, size_t count) 531 + static ssize_t usb2_lpm_besl_store(struct device *dev, 532 + struct device_attribute *attr, 533 + const char *buf, size_t count) 521 534 { 522 535 struct usb_device *udev = to_usb_device(dev); 523 536 u8 besl; ··· 526 545 527 546 return count; 528 547 } 529 - 530 - static DEVICE_ATTR(usb2_lpm_besl, S_IRUGO | S_IWUSR, 531 - show_usb2_lpm_besl, set_usb2_lpm_besl); 548 + static DEVICE_ATTR_RW(usb2_lpm_besl); 532 549 533 550 static struct attribute *usb2_hardware_lpm_attr[] = { 534 551 &dev_attr_usb2_hardware_lpm.attr, ··· 583 604 /* Descriptor fields */ 584 605 #define usb_descriptor_attr_le16(field, format_string) \ 585 606 static ssize_t \ 586 - show_##field(struct device *dev, struct device_attribute *attr, \ 607 + field##_show(struct device *dev, struct device_attribute *attr, \ 587 608 char *buf) \ 588 609 { \ 589 610 struct usb_device *udev; \ ··· 592 613 return sprintf(buf, format_string, \ 593 614 le16_to_cpu(udev->descriptor.field)); \ 594 615 } \ 595 - static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 616 + static DEVICE_ATTR_RO(field) 596 617 597 - usb_descriptor_attr_le16(idVendor, "%04x\n") 598 - usb_descriptor_attr_le16(idProduct, "%04x\n") 599 - usb_descriptor_attr_le16(bcdDevice, "%04x\n") 618 + usb_descriptor_attr_le16(idVendor, "%04x\n"); 619 + usb_descriptor_attr_le16(idProduct, "%04x\n"); 620 + usb_descriptor_attr_le16(bcdDevice, "%04x\n"); 600 621 601 622 #define usb_descriptor_attr(field, format_string) \ 602 623 static ssize_t \ 603 - show_##field(struct device *dev, struct device_attribute *attr, \ 624 + field##_show(struct device *dev, struct device_attribute *attr, \ 604 625 char *buf) \ 605 626 { \ 606 627 struct usb_device *udev; \ ··· 608 629 udev = to_usb_device(dev); \ 609 630 return sprintf(buf, format_string, udev->descriptor.field); \ 610 631 } \ 611 - static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 632 + static DEVICE_ATTR_RO(field) 612 633 613 - usb_descriptor_attr(bDeviceClass, "%02x\n") 614 - usb_descriptor_attr(bDeviceSubClass, "%02x\n") 615 - usb_descriptor_attr(bDeviceProtocol, "%02x\n") 616 - usb_descriptor_attr(bNumConfigurations, "%d\n") 617 - usb_descriptor_attr(bMaxPacketSize0, "%d\n") 618 - 634 + usb_descriptor_attr(bDeviceClass, "%02x\n"); 635 + usb_descriptor_attr(bDeviceSubClass, "%02x\n"); 636 + usb_descriptor_attr(bDeviceProtocol, "%02x\n"); 637 + usb_descriptor_attr(bNumConfigurations, "%d\n"); 638 + usb_descriptor_attr(bMaxPacketSize0, "%d\n"); 619 639 620 640 621 641 /* show if the device is authorized (1) or not (0) */ 622 - static ssize_t usb_dev_authorized_show(struct device *dev, 623 - struct device_attribute *attr, 624 - char *buf) 642 + static ssize_t authorized_show(struct device *dev, 643 + struct device_attribute *attr, char *buf) 625 644 { 626 645 struct usb_device *usb_dev = to_usb_device(dev); 627 646 return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized); 628 647 } 629 - 630 648 631 649 /* 632 650 * Authorize a device to be used in the system 633 651 * 634 652 * Writing a 0 deauthorizes the device, writing a 1 authorizes it. 635 653 */ 636 - static ssize_t usb_dev_authorized_store(struct device *dev, 637 - struct device_attribute *attr, 638 - const char *buf, size_t size) 654 + static ssize_t authorized_store(struct device *dev, 655 + struct device_attribute *attr, const char *buf, 656 + size_t size) 639 657 { 640 658 ssize_t result; 641 659 struct usb_device *usb_dev = to_usb_device(dev); ··· 646 670 result = usb_authorize_device(usb_dev); 647 671 return result < 0? result : size; 648 672 } 649 - 650 - static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, 0644, 651 - usb_dev_authorized_show, usb_dev_authorized_store); 673 + static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, 674 + authorized_show, authorized_store); 652 675 653 676 /* "Safely remove a device" */ 654 - static ssize_t usb_remove_store(struct device *dev, 655 - struct device_attribute *attr, 656 - const char *buf, size_t count) 677 + static ssize_t remove_store(struct device *dev, struct device_attribute *attr, 678 + const char *buf, size_t count) 657 679 { 658 680 struct usb_device *udev = to_usb_device(dev); 659 681 int rc = 0; ··· 668 694 usb_unlock_device(udev); 669 695 return rc; 670 696 } 671 - static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, usb_remove_store); 697 + static DEVICE_ATTR_IGNORE_LOCKDEP(remove, S_IWUSR, NULL, remove_store); 672 698 673 699 674 700 static struct attribute *dev_attrs[] = { ··· 827 853 /* Interface Accociation Descriptor fields */ 828 854 #define usb_intf_assoc_attr(field, format_string) \ 829 855 static ssize_t \ 830 - show_iad_##field(struct device *dev, struct device_attribute *attr, \ 856 + iad_##field##_show(struct device *dev, struct device_attribute *attr, \ 831 857 char *buf) \ 832 858 { \ 833 859 struct usb_interface *intf = to_usb_interface(dev); \ ··· 835 861 return sprintf(buf, format_string, \ 836 862 intf->intf_assoc->field); \ 837 863 } \ 838 - static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL); 864 + static DEVICE_ATTR_RO(iad_##field) 839 865 840 - usb_intf_assoc_attr(bFirstInterface, "%02x\n") 841 - usb_intf_assoc_attr(bInterfaceCount, "%02d\n") 842 - usb_intf_assoc_attr(bFunctionClass, "%02x\n") 843 - usb_intf_assoc_attr(bFunctionSubClass, "%02x\n") 844 - usb_intf_assoc_attr(bFunctionProtocol, "%02x\n") 866 + usb_intf_assoc_attr(bFirstInterface, "%02x\n"); 867 + usb_intf_assoc_attr(bInterfaceCount, "%02d\n"); 868 + usb_intf_assoc_attr(bFunctionClass, "%02x\n"); 869 + usb_intf_assoc_attr(bFunctionSubClass, "%02x\n"); 870 + usb_intf_assoc_attr(bFunctionProtocol, "%02x\n"); 845 871 846 872 /* Interface fields */ 847 873 #define usb_intf_attr(field, format_string) \ 848 874 static ssize_t \ 849 - show_##field(struct device *dev, struct device_attribute *attr, \ 875 + field##_show(struct device *dev, struct device_attribute *attr, \ 850 876 char *buf) \ 851 877 { \ 852 878 struct usb_interface *intf = to_usb_interface(dev); \ ··· 854 880 return sprintf(buf, format_string, \ 855 881 intf->cur_altsetting->desc.field); \ 856 882 } \ 857 - static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 883 + static DEVICE_ATTR_RO(field) 858 884 859 - usb_intf_attr(bInterfaceNumber, "%02x\n") 860 - usb_intf_attr(bAlternateSetting, "%2d\n") 861 - usb_intf_attr(bNumEndpoints, "%02x\n") 862 - usb_intf_attr(bInterfaceClass, "%02x\n") 863 - usb_intf_attr(bInterfaceSubClass, "%02x\n") 864 - usb_intf_attr(bInterfaceProtocol, "%02x\n") 885 + usb_intf_attr(bInterfaceNumber, "%02x\n"); 886 + usb_intf_attr(bAlternateSetting, "%2d\n"); 887 + usb_intf_attr(bNumEndpoints, "%02x\n"); 888 + usb_intf_attr(bInterfaceClass, "%02x\n"); 889 + usb_intf_attr(bInterfaceSubClass, "%02x\n"); 890 + usb_intf_attr(bInterfaceProtocol, "%02x\n"); 865 891 866 - static ssize_t show_interface_string(struct device *dev, 867 - struct device_attribute *attr, char *buf) 892 + static ssize_t interface_show(struct device *dev, struct device_attribute *attr, 893 + char *buf) 868 894 { 869 895 struct usb_interface *intf; 870 896 char *string; ··· 877 903 return 0; 878 904 return sprintf(buf, "%s\n", string); 879 905 } 880 - static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL); 906 + static DEVICE_ATTR_RO(interface); 881 907 882 - static ssize_t show_modalias(struct device *dev, 883 - struct device_attribute *attr, char *buf) 908 + static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 909 + char *buf) 884 910 { 885 911 struct usb_interface *intf; 886 912 struct usb_device *udev; ··· 903 929 alt->desc.bInterfaceProtocol, 904 930 alt->desc.bInterfaceNumber); 905 931 } 906 - static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 932 + static DEVICE_ATTR_RO(modalias); 907 933 908 - static ssize_t show_supports_autosuspend(struct device *dev, 909 - struct device_attribute *attr, char *buf) 934 + static ssize_t supports_autosuspend_show(struct device *dev, 935 + struct device_attribute *attr, 936 + char *buf) 910 937 { 911 938 struct usb_interface *intf; 912 939 struct usb_device *udev; ··· 927 952 928 953 return ret; 929 954 } 930 - static DEVICE_ATTR(supports_autosuspend, S_IRUGO, show_supports_autosuspend, NULL); 955 + static DEVICE_ATTR_RO(supports_autosuspend); 931 956 932 957 static struct attribute *intf_attrs[] = { 933 958 &dev_attr_bInterfaceNumber.attr,