Re: [PATCH v3 1/2] usb: serial: Add MaxLinear/Exar USB to Serial driver

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

 



On Fri, May 01, 2020 at 12:19:23AM +0530, mani@xxxxxxxxxx wrote:
> +static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg,
> +		      u8 val)
> +{
> +	struct usb_serial *serial = port->serial;
> +	int ret = -EINVAL;
> +
> +	/* XR21V141X uses custom command for writing UART registers */
> +	ret = usb_control_msg(serial->dev,
> +			      usb_sndctrlpipe(serial->dev, 0),
> +			      XR_SET_XR21V141X,
> +			      USB_DIR_OUT | USB_TYPE_VENDOR, val,
> +			      reg | (block << 8), NULL, 0,
> +			      USB_CTRL_SET_TIMEOUT);
> +
> +	if (ret < 0)
> +		dev_err(&port->dev, "Failed to set reg 0x%x status: %d\n",
> +			reg, ret);
> +
> +	return ret;
> +}

So if this call is successful, it would return the number of bytes
written in the control message.  Which is 0.  But that's kind of a hack,
right?  Why not just return 0 to make it more obvious and easier to
read, instead of returning 'ret' and making the reader have to realize
that you only are writing 0 bytes?

> +
> +static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg,
> +		      u8 *val)
> +{
> +	struct usb_serial *serial = port->serial;
> +	void *dmabuf;

char *dmabuf; ?

> +	int ret = -EINVAL;
> +
> +	dmabuf = kmalloc(1, GFP_KERNEL);
> +	if (!dmabuf)
> +		return -ENOMEM;
> +
> +	/* XR21V141X uses custom command for reading UART registers */
> +	ret = usb_control_msg(serial->dev,
> +			      usb_rcvctrlpipe(serial->dev, 0),
> +			      XR_GET_XR21V141X,
> +			      USB_DIR_IN | USB_TYPE_VENDOR, 0,
> +			      reg | (block << 8), dmabuf, 1,
> +			      USB_CTRL_SET_TIMEOUT);
> +
> +	if (ret == 1) {
> +		memcpy(val, dmabuf, 1);

*val = *dmabuf; ?

> +		ret = 0;
> +	} else {
> +		dev_err(&port->dev, "Failed to get reg 0x%x status: %d\n",
> +			reg, ret);
> +		if (ret >= 0)
> +			ret = -EIO;
> +	}
> +
> +	kfree(dmabuf);
> +
> +	return ret;
> +}

Anyway, other than these minor things, this looks good to me:

Reviewed-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>



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

  Powered by Linux