aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-23 19:34:43 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-27 15:50:53 -0400
commitce26bd23d4ad180883f53709f9a2220dc771c030 (patch)
tree3402bdee198548f7ef41cc48ffc31c9e017323fa /drivers/usb
parent154547c4fe0fbe92185e69a6cdc2b0502b361995 (diff)
USB: gadget: audit sysfs attribute permissions
Convert all USB gadget sysfs attributes to use the _RO or _RW variants, to make them easier to audit and ensure that the permissions are correct. Note, two are left using the DEVICE_ATTR() macro, as there is no DEVICE_ATTR_WO() in Linus's tree, that will happen after 3.12-rc1 is out, a follow-on patch will be sent then. Reviewed-by: Felipe Balbi <balbi@ti.com> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -- drivers/usb/gadget/composite.c | 8 +++----- drivers/usb/gadget/dummy_hcd.c | 8 ++++---- drivers/usb/gadget/f_mass_storage.c | 14 ++++++-------- drivers/usb/gadget/net2272.c | 4 ++-- drivers/usb/gadget/net2280.c | 18 +++++++++--------- drivers/usb/gadget/storage_common.c | 25 ++++++++++++------------- drivers/usb/gadget/udc-core.c | 14 +++++++------- 7 files changed, 43 insertions(+), 48 deletions(-)
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/composite.c8
-rw-r--r--drivers/usb/gadget/dummy_hcd.c8
-rw-r--r--drivers/usb/gadget/f_mass_storage.c14
-rw-r--r--drivers/usb/gadget/net2272.c4
-rw-r--r--drivers/usb/gadget/net2280.c18
-rw-r--r--drivers/usb/gadget/storage_common.c25
-rw-r--r--drivers/usb/gadget/udc-core.c14
7 files changed, 43 insertions, 48 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 55f4df60f327..d4f0f3305759 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1497,17 +1497,15 @@ void composite_disconnect(struct usb_gadget *gadget)
1497 1497
1498/*-------------------------------------------------------------------------*/ 1498/*-------------------------------------------------------------------------*/
1499 1499
1500static ssize_t composite_show_suspended(struct device *dev, 1500static ssize_t suspended_show(struct device *dev, struct device_attribute *attr,
1501 struct device_attribute *attr, 1501 char *buf)
1502 char *buf)
1503{ 1502{
1504 struct usb_gadget *gadget = dev_to_usb_gadget(dev); 1503 struct usb_gadget *gadget = dev_to_usb_gadget(dev);
1505 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1504 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1506 1505
1507 return sprintf(buf, "%d\n", cdev->suspended); 1506 return sprintf(buf, "%d\n", cdev->suspended);
1508} 1507}
1509 1508static DEVICE_ATTR_RO(suspended);
1510static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
1511 1509
1512static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver) 1510static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver)
1513{ 1511{
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index c588e8e486e5..06ecd08fd57a 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -868,7 +868,7 @@ static const struct usb_gadget_ops dummy_ops = {
868/*-------------------------------------------------------------------------*/ 868/*-------------------------------------------------------------------------*/
869 869
870/* "function" sysfs attribute */ 870/* "function" sysfs attribute */
871static ssize_t show_function(struct device *dev, struct device_attribute *attr, 871static ssize_t function_show(struct device *dev, struct device_attribute *attr,
872 char *buf) 872 char *buf)
873{ 873{
874 struct dummy *dum = gadget_dev_to_dummy(dev); 874 struct dummy *dum = gadget_dev_to_dummy(dev);
@@ -877,7 +877,7 @@ static ssize_t show_function(struct device *dev, struct device_attribute *attr,
877 return 0; 877 return 0;
878 return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function); 878 return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function);
879} 879}
880static DEVICE_ATTR(function, S_IRUGO, show_function, NULL); 880static DEVICE_ATTR_RO(function);
881 881
882/*-------------------------------------------------------------------------*/ 882/*-------------------------------------------------------------------------*/
883 883
@@ -2290,7 +2290,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2290 urb->actual_length, urb->transfer_buffer_length); 2290 urb->actual_length, urb->transfer_buffer_length);
2291} 2291}
2292 2292
2293static ssize_t show_urbs(struct device *dev, struct device_attribute *attr, 2293static ssize_t urbs_show(struct device *dev, struct device_attribute *attr,
2294 char *buf) 2294 char *buf)
2295{ 2295{
2296 struct usb_hcd *hcd = dev_get_drvdata(dev); 2296 struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -2311,7 +2311,7 @@ static ssize_t show_urbs(struct device *dev, struct device_attribute *attr,
2311 2311
2312 return size; 2312 return size;
2313} 2313}
2314static DEVICE_ATTR(urbs, S_IRUGO, show_urbs, NULL); 2314static DEVICE_ATTR_RO(urbs);
2315 2315
2316static int dummy_start_ss(struct dummy_hcd *dum_hcd) 2316static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2317{ 2317{
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 4d4e96a5d2e9..313b835eedfd 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2578,14 +2578,12 @@ static int fsg_main_thread(void *common_)
2578 2578
2579/*************************** DEVICE ATTRIBUTES ***************************/ 2579/*************************** DEVICE ATTRIBUTES ***************************/
2580 2580
2581static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro); 2581static DEVICE_ATTR_RW(ro);
2582static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua); 2582static DEVICE_ATTR_RW(nofua);
2583static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file); 2583static DEVICE_ATTR_RW(file);
2584 2584
2585static struct device_attribute dev_attr_ro_cdrom = 2585static struct device_attribute dev_attr_ro_cdrom = __ATTR_RO(ro);
2586 __ATTR(ro, 0444, fsg_show_ro, NULL); 2586static struct device_attribute dev_attr_file_nonremovable = __ATTR_RO(file);
2587static struct device_attribute dev_attr_file_nonremovable =
2588 __ATTR(file, 0444, fsg_show_file, NULL);
2589 2587
2590 2588
2591/****************************** FSG COMMON ******************************/ 2589/****************************** FSG COMMON ******************************/
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index f1e50a3e322d..bf2bb39f35a2 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -1184,7 +1184,7 @@ static const struct usb_gadget_ops net2272_ops = {
1184/*---------------------------------------------------------------------------*/ 1184/*---------------------------------------------------------------------------*/
1185 1185
1186static ssize_t 1186static ssize_t
1187net2272_show_registers(struct device *_dev, struct device_attribute *attr, char *buf) 1187registers_show(struct device *_dev, struct device_attribute *attr, char *buf)
1188{ 1188{
1189 struct net2272 *dev; 1189 struct net2272 *dev;
1190 char *next; 1190 char *next;
@@ -1308,7 +1308,7 @@ net2272_show_registers(struct device *_dev, struct device_attribute *attr, char
1308 1308
1309 return PAGE_SIZE - size; 1309 return PAGE_SIZE - size;
1310} 1310}
1311static DEVICE_ATTR(registers, S_IRUGO, net2272_show_registers, NULL); 1311static DEVICE_ATTR_RO(registers);
1312 1312
1313/*---------------------------------------------------------------------------*/ 1313/*---------------------------------------------------------------------------*/
1314 1314
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index fbd006ab31d3..0781bff70015 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1424,8 +1424,8 @@ static const struct usb_gadget_ops net2280_ops = {
1424 */ 1424 */
1425 1425
1426/* "function" sysfs attribute */ 1426/* "function" sysfs attribute */
1427static ssize_t 1427static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
1428show_function (struct device *_dev, struct device_attribute *attr, char *buf) 1428 char *buf)
1429{ 1429{
1430 struct net2280 *dev = dev_get_drvdata (_dev); 1430 struct net2280 *dev = dev_get_drvdata (_dev);
1431 1431
@@ -1435,10 +1435,10 @@ show_function (struct device *_dev, struct device_attribute *attr, char *buf)
1435 return 0; 1435 return 0;
1436 return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function); 1436 return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
1437} 1437}
1438static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 1438static DEVICE_ATTR_RO(function);
1439 1439
1440static ssize_t net2280_show_registers(struct device *_dev, 1440static ssize_t registers_show(struct device *_dev,
1441 struct device_attribute *attr, char *buf) 1441 struct device_attribute *attr, char *buf)
1442{ 1442{
1443 struct net2280 *dev; 1443 struct net2280 *dev;
1444 char *next; 1444 char *next;
@@ -1590,10 +1590,10 @@ static ssize_t net2280_show_registers(struct device *_dev,
1590 1590
1591 return PAGE_SIZE - size; 1591 return PAGE_SIZE - size;
1592} 1592}
1593static DEVICE_ATTR(registers, S_IRUGO, net2280_show_registers, NULL); 1593static DEVICE_ATTR_RO(registers);
1594 1594
1595static ssize_t 1595static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1596show_queues (struct device *_dev, struct device_attribute *attr, char *buf) 1596 char *buf)
1597{ 1597{
1598 struct net2280 *dev; 1598 struct net2280 *dev;
1599 char *next; 1599 char *next;
@@ -1690,7 +1690,7 @@ done:
1690 spin_unlock_irqrestore (&dev->lock, flags); 1690 spin_unlock_irqrestore (&dev->lock, flags);
1691 return PAGE_SIZE - size; 1691 return PAGE_SIZE - size;
1692} 1692}
1693static DEVICE_ATTR (queues, S_IRUGO, show_queues, NULL); 1693static DEVICE_ATTR_RO(queues);
1694 1694
1695 1695
1696#else 1696#else
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 8c71212a8c52..08a1a3210a21 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -547,8 +547,8 @@ static void store_cdrom_address(u8 *dest, int msf, u32 addr)
547/*-------------------------------------------------------------------------*/ 547/*-------------------------------------------------------------------------*/
548 548
549 549
550static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr, 550static ssize_t ro_show(struct device *dev, struct device_attribute *attr,
551 char *buf) 551 char *buf)
552{ 552{
553 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 553 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
554 554
@@ -557,16 +557,16 @@ static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
557 : curlun->initially_ro); 557 : curlun->initially_ro);
558} 558}
559 559
560static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr, 560static ssize_t nofua_show(struct device *dev, struct device_attribute *attr,
561 char *buf) 561 char *buf)
562{ 562{
563 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 563 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
564 564
565 return sprintf(buf, "%u\n", curlun->nofua); 565 return sprintf(buf, "%u\n", curlun->nofua);
566} 566}
567 567
568static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr, 568static ssize_t file_show(struct device *dev, struct device_attribute *attr,
569 char *buf) 569 char *buf)
570{ 570{
571 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 571 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
572 struct rw_semaphore *filesem = dev_get_drvdata(dev); 572 struct rw_semaphore *filesem = dev_get_drvdata(dev);
@@ -593,8 +593,8 @@ static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
593} 593}
594 594
595 595
596static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr, 596static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
597 const char *buf, size_t count) 597 const char *buf, size_t count)
598{ 598{
599 ssize_t rc; 599 ssize_t rc;
600 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 600 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
@@ -623,9 +623,8 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
623 return rc; 623 return rc;
624} 624}
625 625
626static ssize_t fsg_store_nofua(struct device *dev, 626static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
627 struct device_attribute *attr, 627 const char *buf, size_t count)
628 const char *buf, size_t count)
629{ 628{
630 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 629 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
631 unsigned nofua; 630 unsigned nofua;
@@ -644,8 +643,8 @@ static ssize_t fsg_store_nofua(struct device *dev,
644 return count; 643 return count;
645} 644}
646 645
647static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr, 646static ssize_t file_store(struct device *dev, struct device_attribute *attr,
648 const char *buf, size_t count) 647 const char *buf, size_t count)
649{ 648{
650 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 649 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
651 struct rw_semaphore *filesem = dev_get_drvdata(dev); 650 struct rw_semaphore *filesem = dev_get_drvdata(dev);
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 546bfda3059a..59891b1c48fc 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -470,31 +470,31 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
470} 470}
471static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); 471static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
472 472
473static ssize_t usb_gadget_state_show(struct device *dev, 473static ssize_t state_show(struct device *dev, struct device_attribute *attr,
474 struct device_attribute *attr, char *buf) 474 char *buf)
475{ 475{
476 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 476 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
477 struct usb_gadget *gadget = udc->gadget; 477 struct usb_gadget *gadget = udc->gadget;
478 478
479 return sprintf(buf, "%s\n", usb_state_string(gadget->state)); 479 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
480} 480}
481static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL); 481static DEVICE_ATTR_RO(state);
482 482
483#define USB_UDC_SPEED_ATTR(name, param) \ 483#define USB_UDC_SPEED_ATTR(name, param) \
484ssize_t usb_udc_##param##_show(struct device *dev, \ 484ssize_t name##_show(struct device *dev, \
485 struct device_attribute *attr, char *buf) \ 485 struct device_attribute *attr, char *buf) \
486{ \ 486{ \
487 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 487 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
488 return snprintf(buf, PAGE_SIZE, "%s\n", \ 488 return snprintf(buf, PAGE_SIZE, "%s\n", \
489 usb_speed_string(udc->gadget->param)); \ 489 usb_speed_string(udc->gadget->param)); \
490} \ 490} \
491static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL) 491static DEVICE_ATTR_RO(name)
492 492
493static USB_UDC_SPEED_ATTR(current_speed, speed); 493static USB_UDC_SPEED_ATTR(current_speed, speed);
494static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); 494static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
495 495
496#define USB_UDC_ATTR(name) \ 496#define USB_UDC_ATTR(name) \
497ssize_t usb_udc_##name##_show(struct device *dev, \ 497ssize_t name##_show(struct device *dev, \
498 struct device_attribute *attr, char *buf) \ 498 struct device_attribute *attr, char *buf) \
499{ \ 499{ \
500 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 500 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
@@ -502,7 +502,7 @@ ssize_t usb_udc_##name##_show(struct device *dev, \
502 \ 502 \
503 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ 503 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
504} \ 504} \
505static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL) 505static DEVICE_ATTR_RO(name)
506 506
507static USB_UDC_ATTR(is_otg); 507static USB_UDC_ATTR(is_otg);
508static USB_UDC_ATTR(is_a_peripheral); 508static USB_UDC_ATTR(is_a_peripheral);