diff mbox

mmc: android-goldfish: fix potential panic due to null pointer

Message ID 1471750476-335-1-git-send-email-shawn.lin@rock-chips.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shawn Lin Aug. 21, 2016, 3:34 a.m. UTC
We should never compare virt_base with zero to indicate whether
we get the right buffer or not from dma_alloc_coherent. It's quite
architecture related. If failing to get the address from CMA or swoitlb
cases, the sub architecture code should decide the return value for it.
So we should never presume that zero always means the failure.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/android-goldfish.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Korsgaard Aug. 22, 2016, 12:33 p.m. UTC | #1
>>>>> "Shawn" == Shawn Lin <shawn.lin@rock-chips.com> writes:

 > We should never compare virt_base with zero to indicate whether
 > we get the right buffer or not from dma_alloc_coherent. It's quite
 > architecture related. If failing to get the address from CMA or swoitlb
 > cases, the sub architecture code should decide the return value for it.
 > So we should never presume that zero always means the failure.

 > Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
 > ---

 >  drivers/mmc/host/android-goldfish.c | 2 +-
 >  1 file changed, 1 insertion(+), 1 deletion(-)

 > diff --git a/drivers/mmc/host/android-goldfish.c b/drivers/mmc/host/android-goldfish.c
 > index dca5518..6d8bd03 100644
 > --- a/drivers/mmc/host/android-goldfish.c
 > +++ b/drivers/mmc/host/android-goldfish.c
 > @@ -484,7 +484,7 @@ static int goldfish_mmc_probe(struct platform_device *pdev)
 host-> virt_base = dma_alloc_coherent(&pdev->dev, BUFFER_SIZE,
 >  					     &buf_addr, GFP_KERNEL);
 
 > -	if (host->virt_base == 0) {
 > +	if (!host->virt_base) {

Huh, these are equivalent?
diff mbox

Patch

diff --git a/drivers/mmc/host/android-goldfish.c b/drivers/mmc/host/android-goldfish.c
index dca5518..6d8bd03 100644
--- a/drivers/mmc/host/android-goldfish.c
+++ b/drivers/mmc/host/android-goldfish.c
@@ -484,7 +484,7 @@  static int goldfish_mmc_probe(struct platform_device *pdev)
 	host->virt_base = dma_alloc_coherent(&pdev->dev, BUFFER_SIZE,
 					     &buf_addr, GFP_KERNEL);
 
-	if (host->virt_base == 0) {
+	if (!host->virt_base) {
 		ret = -ENOMEM;
 		goto dma_alloc_failed;
 	}