Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce26bd23 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

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: default avatarFelipe Balbi <balbi@ti.com>
Acked-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarGreg 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(-)
parent 154547c4
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -1497,8 +1497,7 @@ void composite_disconnect(struct usb_gadget *gadget)


/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/


static ssize_t composite_show_suspended(struct device *dev,
static ssize_t suspended_show(struct device *dev, struct device_attribute *attr,
					struct device_attribute *attr,
			      char *buf)
			      char *buf)
{
{
	struct usb_gadget *gadget = dev_to_usb_gadget(dev);
	struct usb_gadget *gadget = dev_to_usb_gadget(dev);
@@ -1506,8 +1505,7 @@ static ssize_t composite_show_suspended(struct device *dev,


	return sprintf(buf, "%d\n", cdev->suspended);
	return sprintf(buf, "%d\n", cdev->suspended);
}
}

static DEVICE_ATTR_RO(suspended);
static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);


static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver)
static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver)
{
{
+4 −4
Original line number Original line Diff line number Diff line
@@ -868,7 +868,7 @@ static const struct usb_gadget_ops dummy_ops = {
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/


/* "function" sysfs attribute */
/* "function" sysfs attribute */
static ssize_t show_function(struct device *dev, struct device_attribute *attr,
static ssize_t function_show(struct device *dev, struct device_attribute *attr,
		char *buf)
		char *buf)
{
{
	struct dummy	*dum = gadget_dev_to_dummy(dev);
	struct dummy	*dum = gadget_dev_to_dummy(dev);
@@ -877,7 +877,7 @@ static ssize_t show_function(struct device *dev, struct device_attribute *attr,
		return 0;
		return 0;
	return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function);
	return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function);
}
}
static DEVICE_ATTR(function, S_IRUGO, show_function, NULL);
static DEVICE_ATTR_RO(function);


/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/


@@ -2290,7 +2290,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
		urb->actual_length, urb->transfer_buffer_length);
		urb->actual_length, urb->transfer_buffer_length);
}
}


static ssize_t show_urbs(struct device *dev, struct device_attribute *attr,
static ssize_t urbs_show(struct device *dev, struct device_attribute *attr,
		char *buf)
		char *buf)
{
{
	struct usb_hcd		*hcd = dev_get_drvdata(dev);
	struct usb_hcd		*hcd = dev_get_drvdata(dev);
@@ -2311,7 +2311,7 @@ static ssize_t show_urbs(struct device *dev, struct device_attribute *attr,


	return size;
	return size;
}
}
static DEVICE_ATTR(urbs, S_IRUGO, show_urbs, NULL);
static DEVICE_ATTR_RO(urbs);


static int dummy_start_ss(struct dummy_hcd *dum_hcd)
static int dummy_start_ss(struct dummy_hcd *dum_hcd)
{
{
+6 −8
Original line number Original line Diff line number Diff line
@@ -2578,14 +2578,12 @@ static int fsg_main_thread(void *common_)


/*************************** DEVICE ATTRIBUTES ***************************/
/*************************** DEVICE ATTRIBUTES ***************************/


static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
static DEVICE_ATTR_RW(ro);
static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
static DEVICE_ATTR_RW(nofua);
static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
static DEVICE_ATTR_RW(file);


static struct device_attribute dev_attr_ro_cdrom =
static struct device_attribute dev_attr_ro_cdrom = __ATTR_RO(ro);
	__ATTR(ro, 0444, fsg_show_ro, NULL);
static struct device_attribute dev_attr_file_nonremovable = __ATTR_RO(file);
static struct device_attribute dev_attr_file_nonremovable =
	__ATTR(file, 0444, fsg_show_file, NULL);




/****************************** FSG COMMON ******************************/
/****************************** FSG COMMON ******************************/
+2 −2
Original line number Original line Diff line number Diff line
@@ -1184,7 +1184,7 @@ static const struct usb_gadget_ops net2272_ops = {
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/


static ssize_t
static ssize_t
net2272_show_registers(struct device *_dev, struct device_attribute *attr, char *buf)
registers_show(struct device *_dev, struct device_attribute *attr, char *buf)
{
{
	struct net2272 *dev;
	struct net2272 *dev;
	char *next;
	char *next;
@@ -1308,7 +1308,7 @@ net2272_show_registers(struct device *_dev, struct device_attribute *attr, char


	return PAGE_SIZE - size;
	return PAGE_SIZE - size;
}
}
static DEVICE_ATTR(registers, S_IRUGO, net2272_show_registers, NULL);
static DEVICE_ATTR_RO(registers);


/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/


+9 −9
Original line number Original line Diff line number Diff line
@@ -1424,8 +1424,8 @@ static const struct usb_gadget_ops net2280_ops = {
 */
 */


/* "function" sysfs attribute */
/* "function" sysfs attribute */
static ssize_t
static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
show_function (struct device *_dev, struct device_attribute *attr, char *buf)
			     char *buf)
{
{
	struct net2280	*dev = dev_get_drvdata (_dev);
	struct net2280	*dev = dev_get_drvdata (_dev);


@@ -1435,9 +1435,9 @@ show_function (struct device *_dev, struct device_attribute *attr, char *buf)
		return 0;
		return 0;
	return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
	return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
}
}
static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
static DEVICE_ATTR_RO(function);


static ssize_t net2280_show_registers(struct device *_dev,
static ssize_t registers_show(struct device *_dev,
			      struct device_attribute *attr, char *buf)
			      struct device_attribute *attr, char *buf)
{
{
	struct net2280		*dev;
	struct net2280		*dev;
@@ -1590,10 +1590,10 @@ static ssize_t net2280_show_registers(struct device *_dev,


	return PAGE_SIZE - size;
	return PAGE_SIZE - size;
}
}
static DEVICE_ATTR(registers, S_IRUGO, net2280_show_registers, NULL);
static DEVICE_ATTR_RO(registers);


static ssize_t
static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
show_queues (struct device *_dev, struct device_attribute *attr, char *buf)
			   char *buf)
{
{
	struct net2280		*dev;
	struct net2280		*dev;
	char			*next;
	char			*next;
@@ -1690,7 +1690,7 @@ done:
	spin_unlock_irqrestore (&dev->lock, flags);
	spin_unlock_irqrestore (&dev->lock, flags);
	return PAGE_SIZE - size;
	return PAGE_SIZE - size;
}
}
static DEVICE_ATTR (queues, S_IRUGO, show_queues, NULL);
static DEVICE_ATTR_RO(queues);




#else
#else
Loading