diff options
author | Marek Belisko <marek.belisko@open-nandra.com> | 2011-02-03 11:07:53 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-04 12:43:43 -0800 |
commit | e7af0786303cfb6c541582839275f1d0addbeb2b (patch) | |
tree | c468ae5266d690fd2775fdf9751123fecc388699 /drivers/staging/ft1000 | |
parent | 672dfeba92bbb1218b5e39f5aff2d1fd2e2268b8 (diff) |
staging: ft1000: Create common function for buffers check.
Same check was done on three places which make code unreadable.
Put repeat routine to separate function.
Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/ft1000')
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_download.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c index b789e7805c42..7c4749ae1ea3 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c @@ -470,6 +470,17 @@ static u16 hdr_checksum(struct pseudo_hdr *pHdr) return chksum; } +static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset) +{ + int i; + + for (i = 0; i < len; i++) { + if (buff_w[i] != buff_r[i + offset]) + return -1; + } + + return 0; +} //--------------------------------------------------------------------------- // Function: write_blk @@ -560,43 +571,31 @@ static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFi Status = ft1000_read_dpram32 (ft1000dev, dpram, (u8 *)&resultbuffer[0], 64); if ( (tempbuffer[31] & 0xfe00) == 0xfe00) { - for (i=0; i<28; i++) - { - if (resultbuffer[i] != tempbuffer[i]) - { - //NdisMSleep (100); - DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n"); - msleep(10); - Status = STATUS_FAILURE; - break; + if (check_buffers(tempbuffer, resultbuffer, 28, 0)) { + DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n"); + msleep(10); + Status = STATUS_FAILURE; + break; } - } Status = ft1000_read_dpram32 (ft1000dev, dpram+12, (u8 *)&resultbuffer[0], 64); - for (i=0; i<16; i++) - { - if (resultbuffer[i] != tempbuffer[i+24]) - { - //NdisMSleep (100); - DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n"); - msleep(10); - Status = STATUS_FAILURE; - break; + + if (check_buffers(tempbuffer, resultbuffer, 16, 24)) { + DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n"); + msleep(10); + Status = STATUS_FAILURE; + break; } - } + } else { - for (i=0; i<32; i++) - { - if (resultbuffer[i] != tempbuffer[i]) - { - //NdisMSleep (100); - DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n"); - msleep(10); - Status = STATUS_FAILURE; - break; + if (check_buffers(tempbuffer, resultbuffer, 32, 0)) { + DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n"); + msleep(10); + Status = STATUS_FAILURE; + break; } - } + } if (Status == STATUS_SUCCESS) |