Re: [PATCH] usb: misc: cypress_cy7c63: check control transfer status
From: Greg KH
Date: Wed Jul 08 2026 - 11:46:17 EST
On Fri, Jun 19, 2026 at 02:00:53AM +0530, Keshav Verma wrote:
> read_port() currently ignores errors from vendor_command() and always
> returns the cached port value. This can report stale data when the USB
> control transfer fails or returns a short response.
>
> Return the underlying error for failed transfers and report -EIO if the
> device returns fewer bytes than required.
>
> Fixes: 9189bfc2df0f ("[PATCH] USB: rename Cypress CY7C63xxx driver to proper name and fix up some tiny things")
> Signed-off-by: Keshav Verma <iganschel@xxxxxxxxx>
> ---
> drivers/usb/misc/cypress_cy7c63.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
> index 4a7f955ba85b..8601ee0a1ea3 100644
> --- a/drivers/usb/misc/cypress_cy7c63.c
> +++ b/drivers/usb/misc/cypress_cy7c63.c
> @@ -177,6 +177,10 @@ static ssize_t read_port(struct device *dev, struct device_attribute *attr,
> result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0);
>
> dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);
> + if (result < 0)
> + return result;
> + if (result < 2)
> + return -EIO;
>
> return sprintf(buf, "%d", cyp->port[port_num]);
> }
You only changed one call to vendor_command() here, why? Why not fix
this all up by changing vendor_command() to use a better function that
will give you a sane error value, and then check that?
Start with this patch:
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index d26f460ecdbc..86c4678e23b3 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -51,12 +51,10 @@ static int vendor_command(struct usb_device *dev, unsigned char request,
unsigned char value, unsigned char index,
void *buf, int size)
{
- return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
- request,
- USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
- value,
- index, buf, size,
- USB_CTRL_GET_TIMEOUT);
+ return usb_control_msg_recv(dev, 0, request,
+ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+ value, index, buf, size,
+ USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
}
And go from there!
thanks,
greg k-h