diff mbox

[U-Boot,1/2] dfu: mmc: check if mmc device exists in mmc_block_op()

Message ID 1418295780-27611-1-git-send-email-p.marczak@samsung.com
State Changes Requested
Delegated to: Łukasz Majewski
Headers show

Commit Message

Przemyslaw Marczak Dec. 11, 2014, 11:02 a.m. UTC
The function mmc_block_op() is the last function before
the physicall data write, but the mmc device pointer is not
checked. If mmc device not exists, then data abort will occur.
To avoid this, first the mmc device pointer is checked.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
---
 drivers/dfu/dfu_mmc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Łukasz Majewski Dec. 12, 2014, 8:38 a.m. UTC | #1
Hi Przemyslaw,

> The function mmc_block_op() is the last function before
> the physicall data write, but the mmc device pointer is not
> checked. If mmc device not exists, then data abort will occur.
> To avoid this, first the mmc device pointer is checked.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> ---
>  drivers/dfu/dfu_mmc.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
> index 72fa03e..41ac188 100644
> --- a/drivers/dfu/dfu_mmc.c
> +++ b/drivers/dfu/dfu_mmc.c
> @@ -40,10 +40,16 @@ static int mmc_access_part(struct dfu_entity
> *dfu, struct mmc *mmc, int part) static int mmc_block_op(enum dfu_op
> op, struct dfu_entity *dfu, u64 offset, void *buf, long *len)
>  {
> -	struct mmc *mmc = find_mmc_device(dfu->data.mmc.dev_num);
> +	struct mmc *mmc;
>  	u32 blk_start, blk_count, n = 0;
>  	int ret, part_num_bkp = 0;
>  
> +	mmc = find_mmc_device(dfu->data.mmc.dev_num);
> +	if (!mmc) {
> +		printf("Device MMC %d - not found!",
> dfu->data.mmc.dev_num);

Please change printf() -> error();

> +		return -ENODEV;
> +	}
> +
>  	/*
>  	 * We must ensure that we work in lba_blk_size chunks, so
> ALIGN
>  	 * this value.
diff mbox

Patch

diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 72fa03e..41ac188 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -40,10 +40,16 @@  static int mmc_access_part(struct dfu_entity *dfu, struct mmc *mmc, int part)
 static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
 			u64 offset, void *buf, long *len)
 {
-	struct mmc *mmc = find_mmc_device(dfu->data.mmc.dev_num);
+	struct mmc *mmc;
 	u32 blk_start, blk_count, n = 0;
 	int ret, part_num_bkp = 0;
 
+	mmc = find_mmc_device(dfu->data.mmc.dev_num);
+	if (!mmc) {
+		printf("Device MMC %d - not found!", dfu->data.mmc.dev_num);
+		return -ENODEV;
+	}
+
 	/*
 	 * We must ensure that we work in lba_blk_size chunks, so ALIGN
 	 * this value.