X-Git-Url: http://git.rot13.org/?p=bcm963xx.git;a=blobdiff_plain;f=bcmdrivers%2Fopensource%2Fchar%2Fboard%2Fbcm963xx%2Fimpl1%2Fbcm63xx_flash.c;h=5b90057aff36a7c886b3d276b03e9d0091ec30c8;hp=0c7fb9fd32fbef3bfbab10b794f7a5d1626bebb4;hb=6adeba4d92a546ebbadde2562283ee6b984b22c1;hpb=57a096f051259ceaefd5977f30d269884e1dd248 diff --git a/bcmdrivers/opensource/char/board/bcm963xx/impl1/bcm63xx_flash.c b/bcmdrivers/opensource/char/board/bcm963xx/impl1/bcm63xx_flash.c index 0c7fb9fd..5b90057a 100755 --- a/bcmdrivers/opensource/char/board/bcm963xx/impl1/bcm63xx_flash.c +++ b/bcmdrivers/opensource/char/board/bcm963xx/impl1/bcm63xx_flash.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -53,9 +54,16 @@ void *retriedKmalloc(size_t size) { void *pBuf; int tryCount = 0; + int allocType = GFP_KERNEL; + + if( in_interrupt() ) + { + allocType = GFP_ATOMIC; + tryCount = 999; + } // try 1000 times before quit - while (((pBuf = kmalloc(size, GFP_KERNEL)) == NULL) && (tryCount++ < 1000)) + while (((pBuf = kmalloc(size, allocType)) == NULL) && (++tryCount < 1000)) { current->state = TASK_INTERRUPTIBLE; schedule_timeout(HZ/10); @@ -606,6 +614,7 @@ int kerSysScratchPadGet(char *tokenId, char *tokBuf, int bufLen) if(memcmp(((PSP_HEADER)pBuf)->SPMagicNum, MAGIC_NUMBER, MAGIC_NUM_LEN) != 0) { printk("Scratch pad is not initialized.\n"); + retriedKfree(pShareBuf); return sts; } @@ -620,7 +629,12 @@ int kerSysScratchPadGet(char *tokenId, char *tokBuf, int bufLen) if (strncmp(pToken->tokenName, tokenId, TOKEN_NAME_LEN) == 0) { - sts = pToken->tokenLen; + if ( pToken->tokenLen > bufLen ) + { + printk("The length %d of token %s is greater than buffer len %d.\n", pToken->tokenLen, pToken->tokenName, bufLen); + break; + } else + sts = pToken->tokenLen; memcpy(tokBuf, startPtr + sizeof(SP_TOKEN), sts); break; } @@ -785,6 +799,32 @@ int kerSysScratchPadSet(char *tokenId, char *tokBuf, int bufLen) } +// wipe out the scratchPad +// return: +// 0 - ok +// -1 - fail +int kerSysScratchPadClearAll(void) +{ + int sts = -1; + char *pShareBuf = NULL; + char *pBuf = NULL; + + + if (fInfo.flash_scratch_pad_length == 0) + return sts; + if( (pShareBuf = getSharedBlks( fInfo.flash_scratch_pad_start_blk, + (fInfo.flash_scratch_pad_start_blk + fInfo.flash_scratch_pad_number_blk) )) == NULL ) + return sts; + pBuf = pShareBuf + fInfo.flash_scratch_pad_blk_offset; + memset(pBuf, 0x00, fInfo.flash_scratch_pad_length); + sts = setSharedBlks(fInfo.flash_scratch_pad_start_blk, + (fInfo.flash_scratch_pad_number_blk + fInfo.flash_scratch_pad_start_blk), pShareBuf); + + retriedKfree(pShareBuf); + + return sts; +} + int kerSysFlashSizeGet(void) { return flash_get_total_size();