lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VcG9MtL8ozGbuNHtMfYrww7jAu6-VCW4sH5iFcp60PAVA@mail.gmail.com>
Date:	Sun, 15 Nov 2015 22:10:35 +0200
From:	Andy Shevchenko <andy.shevchenko@...il.com>
To:	Dave Penkler <dpenkler@...il.com>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	peter.chen@...escale.com, teuniz@...il.com,
	USB <linux-usb@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 5/5] Add ioctls to enable and disable local controls on
 an instrument

On Sun, Nov 15, 2015 at 8:40 PM, Dave Penkler <dpenkler@...il.com> wrote:
> These ioctls provide support for the USBTMC-USB488 control requests
> for REN_CONTROL, GO_TO_LOCAL and LOCAL_LOCKOUT
>

Nitpicks below.

> Signed-off-by: Dave Penkler <dpenkler@...il.com>
> ---
>  drivers/usb/class/usbtmc.c   | 76 ++++++++++++++++++++++++++++++++++++++++++++
>  include/uapi/linux/usb/tmc.h |  6 ++++
>  2 files changed, 82 insertions(+)
>
> diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
> index add0ce2..79caa78 100644
> --- a/drivers/usb/class/usbtmc.c
> +++ b/drivers/usb/class/usbtmc.c
> @@ -478,6 +478,68 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data,
>         return rv;
>  }
>
> +static int usbtmc488_ioctl_simple(struct usbtmc_device_data *data,
> +                               unsigned long arg,
> +                               unsigned int cmd)
> +{
> +       u8 *buffer;
> +       struct device *dev;
> +       int rv;
> +       unsigned int val;
> +       u16 wValue;
> +
> +       dev = &data->intf->dev;

Could be assigned above.

> +
> +       if (!(data->usb488_caps & USBTMC488_CAPABILITY_SIMPLE))
> +               return -EINVAL;
> +
> +       buffer = kmalloc(8, GFP_KERNEL);
> +       if (!buffer)
> +               return -ENOMEM;
> +
> +       if (cmd == USBTMC488_REQUEST_REN_CONTROL) {
> +               rv = copy_from_user(&val, (void __user *)arg, sizeof(val));
> +               if (rv) {
> +                       rv = -EFAULT;
> +                       goto exit;
> +               }
> +               wValue = (val) ? 1 : 0;

Redundant parens.

> +       } else {
> +               wValue = 0;
> +       }
> +
> +       dev_warn(dev, "wValue is %d\n", wValue);
> +
> +       rv = usb_control_msg(data->usb_dev,
> +                       usb_rcvctrlpipe(data->usb_dev, 0),
> +                       cmd,
> +                       USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
> +                       wValue,
> +                       data->ifnum,
> +                       buffer, 0x01, USBTMC_TIMEOUT);
> +
> +       if (rv < 0) {
> +               dev_err(dev, "simple usb_control_msg failed %d\n", rv);
> +               goto exit;
> +       } else if (rv != 1) {
> +               dev_warn(dev, "simple usb_control_msg returned %d\n", rv);
> +               rv = -EIO;

Hmm… Does usb_control_msg() return a proper error code? If it does,
perhaps better to propagate it.

> +               goto exit;
> +       }
> +
> +       if (buffer[0] != USBTMC_STATUS_SUCCESS) {
> +               dev_err(dev, "simple control status returned %x\n", buffer[0]);
> +               rv = -EIO;
> +               goto exit;

> +       } else {

Redundant else.

> +               rv = 0;
> +       }


> +
> + exit:
> +       kfree(buffer);
> +       return rv;
> +}
> +
>  /*
>   * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
>   * @transfer_size: number of bytes to request from the device.
> @@ -1188,6 +1250,20 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>                 retval = usbtmc488_ioctl_read_stb(data, arg);
>                 break;
>
> +       case USBTMC488_IOCTL_REN_CONTROL:
> +               retval = usbtmc488_ioctl_simple(data, arg,
> +                                               USBTMC488_REQUEST_REN_CONTROL);
> +               break;
> +
> +       case USBTMC488_IOCTL_GOTO_LOCAL:
> +               retval = usbtmc488_ioctl_simple(data, arg,
> +                                               USBTMC488_REQUEST_GOTO_LOCAL);
> +               break;
> +
> +       case USBTMC488_IOCTL_LOCAL_LOCKOUT:
> +               retval = usbtmc488_ioctl_simple(data, arg,
> +                                               USBTMC488_REQUEST_LOCAL_LOCKOUT);
> +               break;
>         }
>
>  skip_io_on_zombie:
> diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
> index 1dc3af1..0d852c9 100644
> --- a/include/uapi/linux/usb/tmc.h
> +++ b/include/uapi/linux/usb/tmc.h
> @@ -33,6 +33,9 @@
>  #define USBTMC_REQUEST_GET_CAPABILITIES                        7
>  #define USBTMC_REQUEST_INDICATOR_PULSE                 64
>  #define USBTMC488_REQUEST_READ_STATUS_BYTE             128
> +#define USBTMC488_REQUEST_REN_CONTROL                  160
> +#define USBTMC488_REQUEST_GOTO_LOCAL                   161
> +#define USBTMC488_REQUEST_LOCAL_LOCKOUT                        162
>
>  /* Request values for USBTMC driver's ioctl entry point */
>  #define USBTMC_IOC_NR                  91
> @@ -44,6 +47,9 @@
>  #define USBTMC_IOCTL_CLEAR_IN_HALT     _IO(USBTMC_IOC_NR, 7)
>  #define USBTMC488_IOCTL_GET_CAPS       _IO(USBTMC_IOC_NR, 17)
>  #define USBTMC488_IOCTL_READ_STB       _IOR(USBTMC_IOC_NR, 18, unsigned char)
> +#define USBTMC488_IOCTL_REN_CONTROL    _IOW(USBTMC_IOC_NR, 19, unsigned char)
> +#define USBTMC488_IOCTL_GOTO_LOCAL     _IO(USBTMC_IOC_NR, 20)
> +#define USBTMC488_IOCTL_LOCAL_LOCKOUT  _IO(USBTMC_IOC_NR, 21)
>
>  /* Driver encoded usb488 capabilities */
>  #define USBTMC488_CAPABILITY_TRIGGER         1
> --
> 2.5.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ