diff mbox

[12/12] usb: usbtmc: Add ioctl to return API version of usbtmc driver

Message ID 20180517170336.8426-13-guido@kiener-muenchen.de (mailing list archive)
State New, archived
Headers show

Commit Message

Guido Kiener May 17, 2018, 5:03 p.m. UTC
- add ioctl USBTMC_IOCTL_API_VERSION to get current API version
- add info message to show API version
- replace USBTMC_TIMEOUT macros with common used USB_CTRL_GET_TIMEOUT
  or USB_CTRL_SET_TIMEOUT macros.
- delete some superfluous code lines.
- update ioctl-number.txt

Signed-off-by: Guido Kiener <guido.kiener@rohde-schwarz.com>
Reviewed-by: Steve Bayless <steve_bayless@keysight.com>
---
 Documentation/ioctl/ioctl-number.txt |  2 +-
 drivers/usb/class/usbtmc.c           | 38 +++++++++++++++-------------
 include/uapi/linux/usb/tmc.h         |  1 +
 3 files changed, 23 insertions(+), 18 deletions(-)

Comments

Greg KH May 18, 2018, 1:44 p.m. UTC | #1
On Thu, May 17, 2018 at 07:03:36PM +0200, Guido Kiener wrote:
> - add ioctl USBTMC_IOCTL_API_VERSION to get current API version
> - add info message to show API version
> - replace USBTMC_TIMEOUT macros with common used USB_CTRL_GET_TIMEOUT
>   or USB_CTRL_SET_TIMEOUT macros.
> - delete some superfluous code lines.
> - update ioctl-number.txt

All should be individual patches.

> @@ -2478,6 +2479,9 @@ static int usbtmc_probe(struct usb_interface *intf,
>  
>  	dev_dbg(&intf->dev, "%s called\n", __func__);
>  
> +	pr_info("USBTMC driver with API version %d loaded\n",
> +		USBTMC_API_VERSION);

No, please do not be noisy.  Working drivers should not send any data to
the kernel log.

thanks,

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

Patch

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 7f7413e597f3..9112df246a77 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -200,7 +200,7 @@  Code  Seq#(hex)	Include File		Comments
 'X'	01	linux/pktcdvd.h		conflict!
 'Y'	all	linux/cyclades.h
 'Z'	14-15	drivers/message/fusion/mptctl.h
-'['	00-07	linux/usb/tmc.h		USB Test and Measurement Devices
+'['	00-3F	linux/usb/tmc.h		USB Test and Measurement Devices
 					<mailto:gregkh@linuxfoundation.org>
 'a'	all	linux/atm*.h, linux/sonet.h	ATM on linux
 					<http://lrcwww.epfl.ch/>
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index c24efe513556..25c5418556ef 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -21,16 +21,14 @@ 
 #include <linux/usb.h>
 #include <linux/usb/tmc.h>
 
+/* Increment API VERSION when changing tmc.h with new flags or ioctls
+ * or when changing a significant behavior of the driver.
+ */
+#define USBTMC_API_VERSION (2)
 
 #define USBTMC_HEADER_SIZE	12
 #define USBTMC_MINOR_BASE	176
 
-/*
- * Size of driver internal IO buffer. Must be multiple of 4 and at least as
- * large as wMaxPacketSize (which is usually 512 bytes).
- */
-#define USBTMC_SIZE_IOBUFFER	2048
-
 /* Minimum USB timeout (in milliseconds) */
 #define USBTMC_MIN_TIMEOUT	100
 /* Default USB timeout (in milliseconds) */
@@ -512,8 +510,6 @@  static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data,
 		rv = put_user(stb, (__u8 __user *)arg);
 		dev_dbg(dev, "stb:0x%02x with srq received %d\n",
 			(unsigned int)stb, rv);
-		if (rv)
-			return -EFAULT;
 		return rv;
 	}
 	spin_unlock_irq(&data->dev_lock);
@@ -530,7 +526,7 @@  static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data,
 			USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
 			data->iin_bTag,
 			data->ifnum,
-			buffer, 0x03, USBTMC_TIMEOUT);
+			buffer, 0x03, USB_CTRL_GET_TIMEOUT);
 	if (rv < 0) {
 		dev_err(dev, "stb usb_control_msg returned %d\n", rv);
 		goto exit;
@@ -569,10 +565,7 @@  static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data,
 		stb = buffer[2];
 	}
 
-	if (put_user(stb, (__u8 __user *)arg))
-		rv = -EFAULT;
-	else
-		rv = 0;
+	rv = put_user(stb, (__u8 __user *)arg);
 	dev_dbg(dev, "stb:0x%02x received %d\n", (unsigned int)stb, rv);
 
  exit:
@@ -667,7 +660,7 @@  static int usbtmc488_ioctl_simple(struct usbtmc_device_data *data,
 			USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
 			wValue,
 			data->ifnum,
-			buffer, 0x01, USBTMC_TIMEOUT);
+			buffer, 0x01, USB_CTRL_GET_TIMEOUT);
 	if (rv < 0) {
 		dev_err(dev, "simple usb_control_msg failed %d\n", rv);
 		goto exit;
@@ -1861,7 +1854,7 @@  static int get_capabilities(struct usbtmc_device_data *data)
 	rv = usb_control_msg(data->usb_dev, usb_rcvctrlpipe(data->usb_dev, 0),
 			     USBTMC_REQUEST_GET_CAPABILITIES,
 			     USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-			     0, 0, buffer, 0x18, USBTMC_TIMEOUT);
+			     0, 0, buffer, 0x18, USB_CTRL_GET_TIMEOUT);
 	if (rv < 0) {
 		dev_err(dev, "usb_control_msg returned %d\n", rv);
 		goto err_out;
@@ -1984,6 +1977,9 @@  static const struct attribute_group data_attr_grp = {
 	.attrs = data_attrs,
 };
 
+/*
+ * Flash activity indicator on device
+ */
 static int usbtmc_ioctl_indicator_pulse(struct usbtmc_device_data *data)
 {
 	struct device *dev;
@@ -2000,7 +1996,7 @@  static int usbtmc_ioctl_indicator_pulse(struct usbtmc_device_data *data)
 			     usb_rcvctrlpipe(data->usb_dev, 0),
 			     USBTMC_REQUEST_INDICATOR_PULSE,
 			     USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-			     0, 0, buffer, 0x01, USBTMC_TIMEOUT);
+			     0, 0, buffer, 0x01, USB_CTRL_GET_TIMEOUT);
 
 	if (rv < 0) {
 		dev_err(dev, "usb_control_msg returned %d\n", rv);
@@ -2249,6 +2245,11 @@  static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 						   (void __user *)arg);
 		break;
 
+	case USBTMC_IOCTL_API_VERSION:
+		retval = put_user(USBTMC_API_VERSION,
+				  (unsigned int __user *)arg);
+		break;
+
 	case USBTMC488_IOCTL_GET_CAPS:
 		retval = put_user(data->usb488_caps,
 				  (unsigned char __user *)arg);
@@ -2271,7 +2272,7 @@  static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 	case USBTMC488_IOCTL_LOCAL_LOCKOUT:
 		retval = usbtmc488_ioctl_simple(data, (void __user *)arg,
-						USBTMC488_REQUEST_LOCAL_LOCKOUT);
+					     USBTMC488_REQUEST_LOCAL_LOCKOUT);
 		break;
 
 	case USBTMC488_IOCTL_TRIGGER:
@@ -2478,6 +2479,9 @@  static int usbtmc_probe(struct usb_interface *intf,
 
 	dev_dbg(&intf->dev, "%s called\n", __func__);
 
+	pr_info("USBTMC driver with API version %d loaded\n",
+		USBTMC_API_VERSION);
+
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
index 98d756489302..db15ad5c83af 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -89,6 +89,7 @@  struct usbtmc_message {
 #define USBTMC_IOCTL_WRITE		_IOWR(USBTMC_IOC_NR, 13, struct usbtmc_message)
 #define USBTMC_IOCTL_READ		_IOWR(USBTMC_IOC_NR, 14, struct usbtmc_message)
 #define USBTMC_IOCTL_WRITE_RESULT	_IOWR(USBTMC_IOC_NR, 15, __u64)
+#define USBTMC_IOCTL_API_VERSION	_IOR(USBTMC_IOC_NR, 16, unsigned int)
 
 #define USBTMC488_IOCTL_GET_CAPS	_IOR(USBTMC_IOC_NR, 17, unsigned char)
 #define USBTMC488_IOCTL_READ_STB	_IOR(USBTMC_IOC_NR, 18, unsigned char)