[RFC/PATCH 4/4] usb: core: add two usb get status helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that we have more than one USB Status Type, we can provide helpers
to the users so that we reduce the amount of arguments that need to be
passed. This will also reduce the amount of mistakes when using this
API.

Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx>
---
 drivers/staging/wlan-ng/hfa384x_usb.c |  8 ++++----
 drivers/usb/core/driver.c             |  5 ++---
 drivers/usb/core/hub.c                | 16 +++++++---------
 drivers/usb/core/message.c            | 15 +++++++++++++++
 include/linux/usb.h                   |  3 +++
 5 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
index 18f825705646..c7cdb88152e4 100644
--- a/drivers/staging/wlan-ng/hfa384x_usb.c
+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
@@ -2459,8 +2459,8 @@ int hfa384x_drvr_start(struct hfa384x *hw)
 	 * badly if a clear_halt is called when the endpoint is already
 	 * ok
 	 */
-	result = usb_get_status(hw->usb, USB_RECIP_ENDPOINT, USB_STATUS_TYPE_STANDARD,
-				hw->endp_in, &status);
+	result = usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in,
+		&status);
 	if (result < 0) {
 		netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
 		goto done;
@@ -2468,8 +2468,8 @@ int hfa384x_drvr_start(struct hfa384x *hw)
 	if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
 		netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
 
-	result = usb_get_status(hw->usb, USB_RECIP_ENDPOINT, USB_STATUS_TYPE_STANDARD,
-				hw->endp_out, &status);
+	result = usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out,
+		&status);
 	if (result < 0) {
 		netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
 		goto done;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 5b4f74febdf3..e1b9f6c9a62f 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1340,9 +1340,8 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
 			int err;
 			u16 devstat;
 
-			err = usb_get_status(udev, USB_RECIP_DEVICE,
-					     USB_STATUS_TYPE_STANDARD, 0,
-					     &devstat);
+			err = usb_get_std_status(udev, USB_RECIP_DEVICE,
+					     0, &devstat);
 			if (err) {
 				dev_err(&udev->dev,
 					"Failed to suspend device, error %d\n",
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c49a8524c6b9..341fa80b8a10 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1482,8 +1482,7 @@ static int hub_configure(struct usb_hub *hub,
 	/* power budgeting mostly matters with bus-powered hubs,
 	 * and battery-powered root hubs (may provide just 8 mA).
 	 */
-	ret = usb_get_status(hdev, USB_RECIP_DEVICE, USB_STATUS_TYPE_STANDARD,
-			     0, &hubstatus);
+	ret = usb_get_std_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);
 	if (ret) {
 		message = "can't get hub status";
 		goto fail;
@@ -3280,8 +3279,8 @@ static int finish_port_resume(struct usb_device *udev)
 	 */
 	if (status == 0) {
 		devstatus = 0;
-		status = usb_get_status(udev, USB_RECIP_DEVICE,
-				USB_STATUS_TYPE_STANDARD, 0, &devstatus);
+		status = usb_get_std_status(udev, USB_RECIP_DEVICE,
+				0, &devstatus);
 
 		/* If a normal resume failed, try doing a reset-resume */
 		if (status && !udev->reset_resume && udev->persist_enabled) {
@@ -3305,9 +3304,8 @@ static int finish_port_resume(struct usb_device *udev)
 			if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
 				status = usb_disable_remote_wakeup(udev);
 		} else {
-			status = usb_get_status(udev, USB_RECIP_INTERFACE,
-					USB_STATUS_TYPE_STANDARD, 0,
-					&devstatus);
+			status = usb_get_std_status(udev, USB_RECIP_INTERFACE,
+					0, &devstatus);
 			if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP
 					| USB_INTRF_STAT_FUNC_RW))
 				status = usb_disable_remote_wakeup(udev);
@@ -4856,8 +4854,8 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 				&& udev->bus_mA <= unit_load) {
 			u16	devstat;
 
-			status = usb_get_status(udev, USB_RECIP_DEVICE,
-					USB_STATUS_TYPE_STANDARD, 0, &devstat);
+			status = usb_get_std_status(udev, USB_RECIP_DEVICE,
+					0, &devstat);
 			if (status) {
 				dev_dbg(&udev->dev, "get status %d ?\n", status);
 				goto loop_disable;
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 0a9d0fd51388..e4dc4a306745 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -993,6 +993,21 @@ int usb_get_status(struct usb_device *dev, int recip, int type, int target,
 }
 EXPORT_SYMBOL_GPL(usb_get_status);
 
+int usb_get_std_status(struct usb_device *dev, int recip, int target,
+	void *data)
+{
+	return usb_get_status(dev, recip, USB_STATUS_TYPE_STANDARD, target,
+		data);
+}
+EXPORT_SYMBOL_GPL(usb_get_std_status);
+
+int usb_get_ptm_status(struct usb_device *dev, int type, void *data)
+{
+	return usb_get_status(dev, USB_RECIP_DEVICE, USB_STATUS_TYPE_PTM, 0,
+		data);
+}
+EXPORT_SYMBOL_GPL(usb_get_ptm_status);
+
 /**
  * usb_clear_halt - tells device to clear endpoint halt/stall condition
  * @dev: device whose endpoint is halted
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 3e1b5d0dba66..82ebf7002ac0 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1767,6 +1767,9 @@ extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
 	unsigned char descindex, void *buf, int size);
 extern int usb_get_status(struct usb_device *dev,
 	int recip, int type, int target, void *data);
+extern int usb_get_std_status(struct usb_device *dev, int recip, int target,
+	void *data);
+extern int usb_get_ptm_status(struct usb_device *dev, int type, void *data);
 extern int usb_string(struct usb_device *dev, int index,
 	char *buf, size_t size);
 
-- 
2.14.2.642.g20fed7cad4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux