From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Schocher Date: Thu, 13 Mar 2014 06:31:03 +0100 Subject: [U-Boot] [PATCH 1/3] usb, dfu: extract flush code into seperate function In-Reply-To: <201403121243.35158.marex@denx.de> References: <1394618481-9572-1-git-send-email-hs@denx.de> <1394618481-9572-2-git-send-email-hs@denx.de> <201403121243.35158.marex@denx.de> Message-ID: <53214297.2060605@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Marek, Am 12.03.2014 12:43, schrieb Marek Vasut: > On Wednesday, March 12, 2014 at 11:01:19 AM, Heiko Schocher wrote: >> move the flushing code into an extra function dfu_flush(), >> so it can be used from other code. >> >> Signed-off-by: Heiko Schocher >> Cc: Lukasz Majewski >> Cc: Kyungmin Park >> Cc: Marek Vasut >> --- >> drivers/dfu/dfu.c | 46 ++++++++++++++++++++++++++-------------------- >> include/dfu.h | 1 + >> 2 files changed, 27 insertions(+), 20 deletions(-) >> >> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c >> index 56e69fd..193e047 100644 >> --- a/drivers/dfu/dfu.c >> +++ b/drivers/dfu/dfu.c >> @@ -127,6 +127,31 @@ static int dfu_write_buffer_drain(struct dfu_entity >> *dfu) return ret; >> } >> >> +int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int >> blk_seq_num) +{ >> + int ret = 0; >> + >> + /* end? */ > > What does this comment mean ? I don't understand it ... Comes from original code... Thinking about it, it seems better to let this comment and the below "if" in the dfu_write function... >> + if (size == 0) { > > You can check this like so: > > if (size) > return; ... as when moving this "if" back to dfu_write(), this "if" kindly disappears in the patch 2/3 of this series, as calling dfu_flush() is only in the new dfuMANIFEST state necessary, which is called at the end of the dfu transfer, so no need for checking, if end of size is reached! > > code > code > code > > This would cut down the indent, no ? Yes. Did the above change and this "if" is no longer necessary ;-) I will wait for comments from Lukasz before posting v2. > Please let's fix this when this popped up, either in separate patch or wrap it > into this one. > >> + /* Now try and flush to the medium if needed. */ >> + if (dfu->flush_medium) >> + ret = dfu->flush_medium(dfu); >> + printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc); >> + >> + /* clear everything */ >> + dfu_free_buf(); >> + dfu->crc = 0; >> + dfu->offset = 0; >> + dfu->i_blk_seq_num = 0; >> + dfu->i_buf_start = dfu_buf; >> + dfu->i_buf_end = dfu_buf; >> + dfu->i_buf = dfu->i_buf_start; >> + >> + dfu->inited = 0; >> + } >> + return ret; >> +} > [...] Thanks! bye, Heiko -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany