* [PATCH] mci: dove: fix dereference of nullable pointer
@ 2019-11-20 7:38 Ahmad Fatoum
2019-11-25 7:59 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2019-11-20 7:38 UTC (permalink / raw)
To: barebox
data->{blocks, blocksize, flags} are all used outside of the if clause
checking whether data is not NULL.
Fix this to avoid dereferencing null pointers.
Fixes: bdcf89d274 ("mci: add Marvell Dove SDHCI driver")
Cc: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
drivers/mci/dove-sdhci.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/mci/dove-sdhci.c b/drivers/mci/dove-sdhci.c
index e71a27ce4f33..bccda5399491 100644
--- a/drivers/mci/dove-sdhci.c
+++ b/drivers/mci/dove-sdhci.c
@@ -116,7 +116,7 @@ static int dove_sdhci_mci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
u32 command, xfer;
u64 start;
int ret;
- unsigned int num_bytes = data->blocks * data->blocksize;
+ unsigned int num_bytes = 0;
struct dove_sdhci *host = priv_from_mci_host(mci);
sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, ~0);
@@ -140,6 +140,7 @@ static int dove_sdhci_mci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
/* setup transfer data */
if (data) {
+ num_bytes = data->blocks * data->blocksize;
if (data->flags & MMC_DATA_READ)
sdhci_write32(&host->sdhci, SDHCI_DMA_ADDRESS, (u32)data->dest);
else
@@ -178,14 +179,14 @@ static int dove_sdhci_mci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
sdhci_read_response(&host->sdhci, cmd);
- if (data->flags & MMC_DATA_WRITE)
- dma_sync_single_for_cpu((unsigned long)data->src,
- num_bytes, DMA_TO_DEVICE);
- else
- dma_sync_single_for_cpu((unsigned long)data->dest,
+ if (data) {
+ if (data->flags & MMC_DATA_WRITE)
+ dma_sync_single_for_cpu((unsigned long)data->src,
+ num_bytes, DMA_TO_DEVICE);
+ else
+ dma_sync_single_for_cpu((unsigned long)data->dest,
num_bytes, DMA_FROM_DEVICE);
- if (data) {
ret = dove_sdhci_wait_for_done(host, SDHCI_INT_XFER_COMPLETE);
if (ret) {
dev_err(host->mci.hw_dev, "error while transfering data for command %d\n",
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mci: dove: fix dereference of nullable pointer
2019-11-20 7:38 [PATCH] mci: dove: fix dereference of nullable pointer Ahmad Fatoum
@ 2019-11-25 7:59 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-11-25 7:59 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Nov 20, 2019 at 08:38:16AM +0100, Ahmad Fatoum wrote:
> data->{blocks, blocksize, flags} are all used outside of the if clause
> checking whether data is not NULL.
> Fix this to avoid dereferencing null pointers.
>
> Fixes: bdcf89d274 ("mci: add Marvell Dove SDHCI driver")
> Cc: Michael Grzeschik <m.grzeschik@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
> drivers/mci/dove-sdhci.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-25 7:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 7:38 [PATCH] mci: dove: fix dereference of nullable pointer Ahmad Fatoum
2019-11-25 7:59 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox