Skip to contentSkip to conversation

mmc: tegra: handle error returned from bounce_buffer_start

PATCH New Michael Scott 1 participant 1 message Oct 21, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: tegra: handle error returned from bounce_buffer_start

Function bounce_buffer_start can return ENOMEM when memalign fails, but the error code is never checked.

One such failure happens when state->len_aligned is larger than the remaining free memory (set via CONFIG_SYS_MALLOC_LEN). This leaves state->bounce_buffer as a NULL. If unchecked, the tegra_mmc driver writes the entire block as a 0xFF and will continue on its way.

Let's handle this error by printing that it happened, and then return it up the chain.

This bug was discoverd during fastboot flashing of sparse images. A pointer is moved through buffered data and often needs to be DMA aligned prior to MMC write. These blocks are are often more than 4mb which is the default Tegra setting for CONFIG_SYS_MALLOC_LEN.

Cc Tom Warren <[email protected]>
Cc Stephen Warren <[email protected]>
---
 drivers/mmc/tegra_mmc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/tegra_mmc.c +7 -1
index ca9c4aa..5ecc2c9 100644
@@ -332,7 +332,13 @@ static int tegra_mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		}
 		len = data->blocks * data->blocksize;
 
-		bounce_buffer_start(&bbstate, buf, len, bbflags);
+		ret = bounce_buffer_start(&bbstate, buf, len, bbflags);
+		if (ret) {
+			printf("%s: bounce_buffer_start failed with error %d "
+				"(buf = %p, len = %u, flags = %u)\n",
+				__func__, ret, buf, len, bbflags);
+			return ret;
+		}
 	}
 
 	ret = mmc_send_cmd_bounced(mmc, cmd, data, &bbstate);
Signature · 1 line
1.9.1