public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Patrick Delaunay <patrick.delaunay73@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] usb: gadget: dfu: correct size for USB_REQ_DFU_GETSTATE result
Date: Fri, 16 Dec 2016 18:41:31 +0100	[thread overview]
Message-ID: <1481910092-13844-2-git-send-email-patrick.delaunay73@gmail.com> (raw)
In-Reply-To: <1481910092-13844-1-git-send-email-patrick.delaunay73@gmail.com>

From: Patrick Delaunay <patrick.delaunay@st.com>

return the correct size for DFU_GETSTATE result (1 byte in DFU 1.1 spec)
to avoid issue in USB protocol and the variable "value" is propagated
to req->lenght as all the in the other request with answer
- DFU_GETSTATUS
- DFU_DNLOAD
- DFU_UPLOAD
Then the buffer is correctly treated in USB driver

NB: it was the only request witch directly change "req->actual"

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
---

 drivers/usb/gadget/f_dfu.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
index 8e7c981..2790ddb 100644
--- a/drivers/usb/gadget/f_dfu.c
+++ b/drivers/usb/gadget/f_dfu.c
@@ -212,12 +212,12 @@ static void handle_getstatus(struct usb_request *req)
 	dstat->iString = 0;
 }
 
-static void handle_getstate(struct usb_request *req)
+static int handle_getstate(struct usb_request *req)
 {
 	struct f_dfu *f_dfu = req->context;
 
 	((u8 *)req->buf)[0] = f_dfu->dfu_state;
-	req->actual = sizeof(u8);
+	return sizeof(u8);
 }
 
 static inline void to_dfu_mode(struct f_dfu *f_dfu)
@@ -272,7 +272,7 @@ static int state_app_idle(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	case USB_REQ_DFU_DETACH:
 		f_dfu->dfu_state = DFU_STATE_appDETACH;
@@ -300,7 +300,7 @@ static int state_app_detach(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_appIDLE;
@@ -345,7 +345,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	case USB_REQ_DFU_DETACH:
 		/*
@@ -385,7 +385,7 @@ static int state_dfu_dnload_sync(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -441,7 +441,7 @@ static int state_dfu_dnload_idle(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -469,7 +469,7 @@ static int state_dfu_manifest_sync(struct f_dfu *f_dfu,
 		req->complete = dnload_request_flush;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -497,7 +497,7 @@ static int state_dfu_manifest(struct f_dfu *f_dfu,
 		puts("DOWNLOAD ... OK\nCtrl+C to exit ...\n");
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -534,7 +534,7 @@ static int state_dfu_upload_idle(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -558,7 +558,7 @@ static int state_dfu_error(struct f_dfu *f_dfu,
 		value = RET_STAT_LEN;
 		break;
 	case USB_REQ_DFU_GETSTATE:
-		handle_getstate(req);
+		value = handle_getstate(req);
 		break;
 	case USB_REQ_DFU_CLRSTATUS:
 		f_dfu->dfu_state = DFU_STATE_dfuIDLE;
-- 
1.9.1

  reply	other threads:[~2016-12-16 17:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-16 17:41 [U-Boot] [PATCH 0/2] Series to clean handle_XXX() in f_dfu.c Patrick Delaunay
2016-12-16 17:41 ` Patrick Delaunay [this message]
2016-12-16 17:41 ` [U-Boot] [PATCH 2/2] usb: gadget: dfu: add result for handle_getstatus() Patrick Delaunay
2017-02-21 22:36 ` [U-Boot] [PATCH 0/2] Series to clean handle_XXX() in f_dfu.c Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481910092-13844-2-git-send-email-patrick.delaunay73@gmail.com \
    --to=patrick.delaunay73@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox