Commit d03f254f authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 598d0361
...@@ -32,31 +32,31 @@ struct ep_attribute { ...@@ -32,31 +32,31 @@ struct ep_attribute {
container_of(_attr, struct ep_attribute, attr) container_of(_attr, struct ep_attribute, attr)
#define usb_ep_attr(field, format_string) \ #define usb_ep_attr(field, format_string) \
static ssize_t show_ep_##field(struct device *dev, \ static ssize_t field##_show(struct device *dev, \
struct device_attribute *attr, \ struct device_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
struct ep_device *ep = to_ep_device(dev); \ struct ep_device *ep = to_ep_device(dev); \
return sprintf(buf, format_string, ep->desc->field); \ return sprintf(buf, format_string, ep->desc->field); \
} \ } \
static DEVICE_ATTR(field, S_IRUGO, show_ep_##field, NULL); static DEVICE_ATTR_RO(field)
usb_ep_attr(bLength, "%02x\n") usb_ep_attr(bLength, "%02x\n");
usb_ep_attr(bEndpointAddress, "%02x\n") usb_ep_attr(bEndpointAddress, "%02x\n");
usb_ep_attr(bmAttributes, "%02x\n") usb_ep_attr(bmAttributes, "%02x\n");
usb_ep_attr(bInterval, "%02x\n") usb_ep_attr(bInterval, "%02x\n");
static ssize_t show_ep_wMaxPacketSize(struct device *dev, static ssize_t wMaxPacketSize_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ep_device *ep = to_ep_device(dev); struct ep_device *ep = to_ep_device(dev);
return sprintf(buf, "%04x\n", return sprintf(buf, "%04x\n",
usb_endpoint_maxp(ep->desc) & 0x07ff); usb_endpoint_maxp(ep->desc) & 0x07ff);
} }
static DEVICE_ATTR(wMaxPacketSize, S_IRUGO, show_ep_wMaxPacketSize, NULL); static DEVICE_ATTR_RO(wMaxPacketSize);
static ssize_t show_ep_type(struct device *dev, struct device_attribute *attr, static ssize_t type_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct ep_device *ep = to_ep_device(dev); struct ep_device *ep = to_ep_device(dev);
char *type = "unknown"; char *type = "unknown";
...@@ -77,10 +77,10 @@ static ssize_t show_ep_type(struct device *dev, struct device_attribute *attr, ...@@ -77,10 +77,10 @@ static ssize_t show_ep_type(struct device *dev, struct device_attribute *attr,
} }
return sprintf(buf, "%s\n", type); return sprintf(buf, "%s\n", type);
} }
static DEVICE_ATTR(type, S_IRUGO, show_ep_type, NULL); static DEVICE_ATTR_RO(type);
static ssize_t show_ep_interval(struct device *dev, static ssize_t interval_show(struct device *dev, struct device_attribute *attr,
struct device_attribute *attr, char *buf) char *buf)
{ {
struct ep_device *ep = to_ep_device(dev); struct ep_device *ep = to_ep_device(dev);
char unit; char unit;
...@@ -123,10 +123,10 @@ static ssize_t show_ep_interval(struct device *dev, ...@@ -123,10 +123,10 @@ static ssize_t show_ep_interval(struct device *dev,
return sprintf(buf, "%d%cs\n", interval, unit); return sprintf(buf, "%d%cs\n", interval, unit);
} }
static DEVICE_ATTR(interval, S_IRUGO, show_ep_interval, NULL); static DEVICE_ATTR_RO(interval);
static ssize_t show_ep_direction(struct device *dev, static ssize_t direction_show(struct device *dev, struct device_attribute *attr,
struct device_attribute *attr, char *buf) char *buf)
{ {
struct ep_device *ep = to_ep_device(dev); struct ep_device *ep = to_ep_device(dev);
char *direction; char *direction;
...@@ -139,7 +139,7 @@ static ssize_t show_ep_direction(struct device *dev, ...@@ -139,7 +139,7 @@ static ssize_t show_ep_direction(struct device *dev,
direction = "out"; direction = "out";
return sprintf(buf, "%s\n", direction); return sprintf(buf, "%s\n", direction);
} }
static DEVICE_ATTR(direction, S_IRUGO, show_ep_direction, NULL); static DEVICE_ATTR_RO(direction);
static struct attribute *ep_dev_attrs[] = { static struct attribute *ep_dev_attrs[] = {
&dev_attr_bLength.attr, &dev_attr_bLength.attr,
......
...@@ -849,9 +849,8 @@ static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) ...@@ -849,9 +849,8 @@ static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
/* /*
* Show & store the current value of authorized_default * Show & store the current value of authorized_default
*/ */
static ssize_t usb_host_authorized_default_show(struct device *dev, static ssize_t authorized_default_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct usb_device *rh_usb_dev = to_usb_device(dev); struct usb_device *rh_usb_dev = to_usb_device(dev);
struct usb_bus *usb_bus = rh_usb_dev->bus; struct usb_bus *usb_bus = rh_usb_dev->bus;
...@@ -863,9 +862,9 @@ static ssize_t usb_host_authorized_default_show(struct device *dev, ...@@ -863,9 +862,9 @@ static ssize_t usb_host_authorized_default_show(struct device *dev,
return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default); return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default);
} }
static ssize_t usb_host_authorized_default_store(struct device *dev, static ssize_t authorized_default_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t size) const char *buf, size_t size)
{ {
ssize_t result; ssize_t result;
unsigned val; unsigned val;
...@@ -885,11 +884,7 @@ static ssize_t usb_host_authorized_default_store(struct device *dev, ...@@ -885,11 +884,7 @@ static ssize_t usb_host_authorized_default_store(struct device *dev,
result = -EINVAL; result = -EINVAL;
return result; return result;
} }
static DEVICE_ATTR_RW(authorized_default);
static DEVICE_ATTR(authorized_default, 0644,
usb_host_authorized_default_show,
usb_host_authorized_default_store);
/* Group all the USB bus attributes */ /* Group all the USB bus attributes */
static struct attribute *usb_bus_attrs[] = { static struct attribute *usb_bus_attrs[] = {
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
static const struct attribute_group *port_dev_group[]; static const struct attribute_group *port_dev_group[];
static ssize_t show_port_connect_type(struct device *dev, static ssize_t connect_type_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct usb_port *port_dev = to_usb_port(dev); struct usb_port *port_dev = to_usb_port(dev);
char *result; char *result;
...@@ -46,8 +46,7 @@ static ssize_t show_port_connect_type(struct device *dev, ...@@ -46,8 +46,7 @@ static ssize_t show_port_connect_type(struct device *dev,
return sprintf(buf, "%s\n", result); return sprintf(buf, "%s\n", result);
} }
static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type, static DEVICE_ATTR_RO(connect_type);
NULL);
static struct attribute *port_dev_attrs[] = { static struct attribute *port_dev_attrs[] = {
&dev_attr_connect_type.attr, &dev_attr_connect_type.attr,
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment