Re: [PATCH] USB: serial: cp210x: Workaround for cp2108 failure due to GET_LINE_CTL bug

From: BjÃrn Mork
Date: Thu Oct 08 2015 - 03:32:04 EST


Konstantin Shkolnyy <konstantin.shkolnyy@xxxxxxxxx> writes:

> @@ -343,6 +344,28 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
> return result;
> }
>
> + /* Workaround for swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */
> + if (spriv->swap_get_line_ctl && request == CP210X_GET_LINE_CTL && size == 2) {
> + union {
> + struct {
> + u8 byte0;
> + u8 byte1;
> + u8 byte2;
> + u8 byte3;
> + };
> + u32 as_u32;
> + } tmp_data;
> + u8 old_byte0;
> + u8 old_byte1;
> +
> + tmp_data.as_u32 = data[0]; /* from caller's buffer */
> + old_byte0 = tmp_data.byte0;
> + old_byte1 = tmp_data.byte1;
> + tmp_data.byte0 = old_byte1;
> + tmp_data.byte1 = old_byte0;
> + data[0] = tmp_data.as_u32; /* to caller's buffer */
> + }

That looks unnecessarily complicated... How about:

if (spriv->swap_get_line_ctl && request == CP210X_GET_LINE_CTL && size == 2)
swab16s((u16 *)data);


Completely untested...



BjÃrn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/