linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mfd: rtsx_usb: avoid setting ucr->current_sg.status
@ 2016-08-11  2:39 Lu Baolu
  2016-08-30 14:39 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Lu Baolu @ 2016-08-11  2:39 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-usb, linux-kernel, Lu Baolu, stable, Alan Stern, Roger Tseng

Member "status" of struct usb_sg_request is managed by usb core. A
spin lock is used to serialize the change of it. The driver could
check the value of req->status, but should avoid changing it without
the hold of the spinlock. Otherwise, it could cause race or error
in usb core.

This patch could be backported to stable kernels with version later
than v3.14.

Cc: stable@vger.kernel.org # 3.14+
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Roger Tseng <rogerable@realtek.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/mfd/rtsx_usb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
index dbd907d..691dab7 100644
--- a/drivers/mfd/rtsx_usb.c
+++ b/drivers/mfd/rtsx_usb.c
@@ -46,9 +46,6 @@ static void rtsx_usb_sg_timed_out(unsigned long data)
 
 	dev_dbg(&ucr->pusb_intf->dev, "%s: sg transfer timed out", __func__);
 	usb_sg_cancel(&ucr->current_sg);
-
-	/* we know the cancellation is caused by time-out */
-	ucr->current_sg.status = -ETIMEDOUT;
 }
 
 static int rtsx_usb_bulk_transfer_sglist(struct rtsx_ucr *ucr,
@@ -67,12 +64,15 @@ static int rtsx_usb_bulk_transfer_sglist(struct rtsx_ucr *ucr,
 	ucr->sg_timer.expires = jiffies + msecs_to_jiffies(timeout);
 	add_timer(&ucr->sg_timer);
 	usb_sg_wait(&ucr->current_sg);
-	del_timer_sync(&ucr->sg_timer);
+	if (!del_timer_sync(&ucr->sg_timer))
+		ret = -ETIMEDOUT;
+	else
+		ret = ucr->current_sg.status;
 
 	if (act_len)
 		*act_len = ucr->current_sg.bytes;
 
-	return ucr->current_sg.status;
+	return ret;
 }
 
 int rtsx_usb_transfer_data(struct rtsx_ucr *ucr, unsigned int pipe,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] mfd: rtsx_usb: avoid setting ucr->current_sg.status
  2016-08-11  2:39 [PATCH 1/1] mfd: rtsx_usb: avoid setting ucr->current_sg.status Lu Baolu
@ 2016-08-30 14:39 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2016-08-30 14:39 UTC (permalink / raw)
  To: Lu Baolu; +Cc: linux-usb, linux-kernel, stable, Alan Stern, Roger Tseng

On Thu, 11 Aug 2016, Lu Baolu wrote:

> Member "status" of struct usb_sg_request is managed by usb core. A
> spin lock is used to serialize the change of it. The driver could
> check the value of req->status, but should avoid changing it without
> the hold of the spinlock. Otherwise, it could cause race or error
> in usb core.
> 
> This patch could be backported to stable kernels with version later
> than v3.14.
> 
> Cc: stable@vger.kernel.org # 3.14+
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: Roger Tseng <rogerable@realtek.com>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
>  drivers/mfd/rtsx_usb.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Applied, thanks.

> diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
> index dbd907d..691dab7 100644
> --- a/drivers/mfd/rtsx_usb.c
> +++ b/drivers/mfd/rtsx_usb.c
> @@ -46,9 +46,6 @@ static void rtsx_usb_sg_timed_out(unsigned long data)
>  
>  	dev_dbg(&ucr->pusb_intf->dev, "%s: sg transfer timed out", __func__);
>  	usb_sg_cancel(&ucr->current_sg);
> -
> -	/* we know the cancellation is caused by time-out */
> -	ucr->current_sg.status = -ETIMEDOUT;
>  }
>  
>  static int rtsx_usb_bulk_transfer_sglist(struct rtsx_ucr *ucr,
> @@ -67,12 +64,15 @@ static int rtsx_usb_bulk_transfer_sglist(struct rtsx_ucr *ucr,
>  	ucr->sg_timer.expires = jiffies + msecs_to_jiffies(timeout);
>  	add_timer(&ucr->sg_timer);
>  	usb_sg_wait(&ucr->current_sg);
> -	del_timer_sync(&ucr->sg_timer);
> +	if (!del_timer_sync(&ucr->sg_timer))
> +		ret = -ETIMEDOUT;
> +	else
> +		ret = ucr->current_sg.status;
>  
>  	if (act_len)
>  		*act_len = ucr->current_sg.bytes;
>  
> -	return ucr->current_sg.status;
> +	return ret;
>  }
>  
>  int rtsx_usb_transfer_data(struct rtsx_ucr *ucr, unsigned int pipe,

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-30 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11  2:39 [PATCH 1/1] mfd: rtsx_usb: avoid setting ucr->current_sg.status Lu Baolu
2016-08-30 14:39 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).