mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 06:32:08 +00:00
usb: renesas_usbhs: gadget: Fix usb_ep_set_{halt,wedge}() behavior
According to usb_ep_set_halt()'s description,
__usbhsg_ep_set_halt_wedge() should return -EAGAIN if the IN endpoint
has any queue or data. Otherwise, this driver is possible to cause
just STALL without sending a short packet data on g_mass_storage driver,
and then a few resetting a device happens on a host side during
a usb enumaration.
Fixes: 2f98382dcd
("usb: renesas_usbhs: Add Renesas USBHS Gadget")
Cc: <stable@vger.kernel.org> # v3.0+
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/1569924633-322-3-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1aae139429
commit
4d599cd3a0
6 changed files with 34 additions and 2 deletions
|
@ -211,6 +211,7 @@ struct usbhs_priv;
|
||||||
/* DCPCTR */
|
/* DCPCTR */
|
||||||
#define BSTS (1 << 15) /* Buffer Status */
|
#define BSTS (1 << 15) /* Buffer Status */
|
||||||
#define SUREQ (1 << 14) /* Sending SETUP Token */
|
#define SUREQ (1 << 14) /* Sending SETUP Token */
|
||||||
|
#define INBUFM (1 << 14) /* (PIPEnCTR) Transfer Buffer Monitor */
|
||||||
#define CSSTS (1 << 12) /* CSSTS Status */
|
#define CSSTS (1 << 12) /* CSSTS Status */
|
||||||
#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
|
#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
|
||||||
#define SQCLR (1 << 8) /* Toggle Bit Clear */
|
#define SQCLR (1 << 8) /* Toggle Bit Clear */
|
||||||
|
|
|
@ -89,7 +89,7 @@ static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
|
||||||
list_del_init(&pkt->node);
|
list_del_init(&pkt->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
|
struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
|
||||||
{
|
{
|
||||||
return list_first_entry_or_null(&pipe->list, struct usbhs_pkt, node);
|
return list_first_entry_or_null(&pipe->list, struct usbhs_pkt, node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,5 +97,6 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
|
||||||
void *buf, int len, int zero, int sequence);
|
void *buf, int len, int zero, int sequence);
|
||||||
struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
|
struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
|
||||||
void usbhs_pkt_start(struct usbhs_pipe *pipe);
|
void usbhs_pkt_start(struct usbhs_pipe *pipe);
|
||||||
|
struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
|
||||||
|
|
||||||
#endif /* RENESAS_USB_FIFO_H */
|
#endif /* RENESAS_USB_FIFO_H */
|
||||||
|
|
|
@ -722,6 +722,7 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
|
||||||
struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
|
struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
|
||||||
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
|
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
dev_dbg(dev, "set halt %d (pipe %d)\n",
|
dev_dbg(dev, "set halt %d (pipe %d)\n",
|
||||||
halt, usbhs_pipe_number(pipe));
|
halt, usbhs_pipe_number(pipe));
|
||||||
|
@ -729,6 +730,18 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
|
||||||
/******************** spin lock ********************/
|
/******************** spin lock ********************/
|
||||||
usbhs_lock(priv, flags);
|
usbhs_lock(priv, flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* According to usb_ep_set_halt()'s description, this function should
|
||||||
|
* return -EAGAIN if the IN endpoint has any queue or data. Note
|
||||||
|
* that the usbhs_pipe_is_dir_in() returns false if the pipe is an
|
||||||
|
* IN endpoint in the gadget mode.
|
||||||
|
*/
|
||||||
|
if (!usbhs_pipe_is_dir_in(pipe) && (__usbhsf_pkt_get(pipe) ||
|
||||||
|
usbhs_pipe_contains_transmittable_data(pipe))) {
|
||||||
|
ret = -EAGAIN;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (halt)
|
if (halt)
|
||||||
usbhs_pipe_stall(pipe);
|
usbhs_pipe_stall(pipe);
|
||||||
else
|
else
|
||||||
|
@ -739,10 +752,11 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
|
||||||
else
|
else
|
||||||
usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
|
usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
|
||||||
|
|
||||||
|
out:
|
||||||
usbhs_unlock(priv, flags);
|
usbhs_unlock(priv, flags);
|
||||||
/******************** spin unlock ******************/
|
/******************** spin unlock ******************/
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
|
static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
|
||||||
|
|
|
@ -277,6 +277,21 @@ int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
|
||||||
|
{
|
||||||
|
u16 val;
|
||||||
|
|
||||||
|
/* Do not support for DCP pipe */
|
||||||
|
if (usbhs_pipe_is_dcp(pipe))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
val = usbhsp_pipectrl_get(pipe);
|
||||||
|
if (val & INBUFM)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PID ctrl
|
* PID ctrl
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -83,6 +83,7 @@ void usbhs_pipe_clear(struct usbhs_pipe *pipe);
|
||||||
void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
|
void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
|
||||||
int needs_bfre, int bfre_enable);
|
int needs_bfre, int bfre_enable);
|
||||||
int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
|
int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
|
||||||
|
bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
|
||||||
void usbhs_pipe_enable(struct usbhs_pipe *pipe);
|
void usbhs_pipe_enable(struct usbhs_pipe *pipe);
|
||||||
void usbhs_pipe_disable(struct usbhs_pipe *pipe);
|
void usbhs_pipe_disable(struct usbhs_pipe *pipe);
|
||||||
void usbhs_pipe_stall(struct usbhs_pipe *pipe);
|
void usbhs_pipe_stall(struct usbhs_pipe *pipe);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue