[U-Boot] [PATCH 2/3] mmc: add boundary check for mmc operation

Wolfgang Denk wd at denx.de
Tue Sep 7 15:49:31 CEST 2010


Dear Lei Wen,

In message <1283862729-17045-2-git-send-email-leiwen at marvell.com> you wrote:
> Signed-off-by: Lei Wen <leiwen at marvell.com>
> ---
>  drivers/mmc/mmc.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 5cc1904..9a50b2f 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -134,6 +134,10 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
>  	if (!mmc)
>  		return -1;
>  
> +	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
> +		printf("\noperation excceed mmc boudary..\n");

No initial newline, please.

Please fix typos: exceed, boundary.

Use puts() instead of printf() for messages that do not need
formatting.

Hm... Maybe you could change the message so it is more informatiove,
i. e. tell the user which boundary was exceeded, and what caused this
condition - is this a user error or a problem in the code?

>  	err = mmc_set_blocklen(mmc, mmc->write_bl_len);
>  	if (err) {
>  		printf("set write bl len failed\n\r");

While you are at it: please fix this message, too. Remove the '\r',
and replace the "bl len" with something the user can understand.

> @@ -236,6 +240,10 @@ static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
>  	if (!mmc)
>  		return 0;
>  
> +	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
> +		printf("\noperation excceed mmc boudary..\n");

See above.

Hm... This is repeated code. Factor it out?


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There's an old proverb that says just about whatever you want it to.


More information about the U-Boot mailing list