mmc: fix return value check of mmc_add_host()
cover mmc: fix return value check of mmc_add_host()
mmc_add_host() may return error, but it was ignored in some drivers, if we ignore it, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and calling mmc_free_host() in error path.
Yang Yingliang (9):
mmc: alcor: fix return value check of mmc_add_host()
mmc: moxart: fix return value check of mmc_add_host()
mmc: mxcmmc: fix return value check of mmc_add_host()
mmc: pxamci: fix return value check of mmc_add_host()
mmc: rtsx_pci: fix return value check of mmc_add_host()
mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host()
mmc: toshsd: fix return value check of mmc_add_host()
mmc: vub300: fix return value check of mmc_add_host()
mmc: wmt-sdmmc: fix return value check of mmc_add_host()
drivers/mmc/host/alcor.c | 5 ++++- drivers/mmc/host/moxart-mmc.c | 4 +++- drivers/mmc/host/mxcmmc.c | 4 +++- drivers/mmc/host/pxamci.c | 7 ++++++- drivers/mmc/host/rtsx_pci_sdmmc.c | 9 ++++++++- drivers/mmc/host/rtsx_usb_sdmmc.c | 11 ++++++++++- drivers/mmc/host/toshsd.c | 6 +++++- drivers/mmc/host/vub300.c | 11 ++++++++--- drivers/mmc/host/wmt-sdmmc.c | 6 +++++- 9 files changed, 52 insertions(+), 11 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/9 mmc: alcor: fix return value check of mmc_add_host()
mmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and calling mmc_free_host() in the error path.
--- drivers/mmc/host/alcor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/alcor.c +4 -1
@@ -1114,7 +1114,10 @@ static int alcor_pci_sdmmc_drv_probe(struct platform_device *pdev)alcor_hw_init (host);dev_set_drvdata (&pdev->dev, host); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) + goto free_host; +return 0 ; free_host:
Signature · 1 line
2.25.1
PATCH 2/9 mmc: moxart: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host().
--- drivers/mmc/host/moxart-mmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/host/moxart-mmc.c +3 -1
@@ -665,7 +665,9 @@ static int moxart_probe(struct platform_device *pdev) goto out;dev_set_drvdata (dev, mmc); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) + goto out;dev_dbg (dev,"IRQ=%d, FIFO is %d bytes\n" , irq, host->fifo_width);
Signature · 1 line
2.25.1
PATCH 3/9 mmc: mxcmmc: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host().
--- drivers/mmc/host/mxcmmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/host/mxcmmc.c +3 -1
@@ -1143,7 +1143,9 @@ static int mxcmci_probe(struct platform_device *pdev)timer_setup (&host->watchdog, mxcmci_watchdog,0 ); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) + goto out_free_dma;return 0 ;
Signature · 1 line
2.25.1
PATCH 4/9 mmc: pxamci: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host(), besides, ->exit() need be called to uninit the pdata.
--- drivers/mmc/host/pxamci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mmc/host/pxamci.c +6 -1
@@ -763,7 +763,12 @@ static int pxamci_probe(struct platform_device *pdev)dev_warn (dev,"gpio_ro and get_ro() both defined\n" ); } -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) { +if (host->pdata && host->pdata->exit) + host->pdata->exit (dev, mmc); + goto out; + }return 0 ;
Signature · 1 line
2.25.1
PATCH 5/9 mmc: rtsx_pci: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and calling mmc_free_host() in the error path, beside, runtime PM also needs be disabled.
--- drivers/mmc/host/rtsx_pci_sdmmc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/mmc/host/rtsx_pci_sdmmc.c +8 -1
@@ -1474,6 +1474,7 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)struct realtek_pci_sdmmc *host;struct rtsx_pcr *pcr;struct pcr_handle *handle = pdev->dev.platform_data; +int ret;if (!handle)return -ENXIO ;
@@ -1511,7 +1512,13 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)pm_runtime_mark_last_busy (&pdev->dev);pm_runtime_use_autosuspend (&pdev->dev); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) { +pm_runtime_dont_use_autosuspend (&pdev->dev); +pm_runtime_disable (&pdev->dev); +mmc_free_host (mmc); +return ret; + }return 0 ; }
Signature · 1 line
2.25.1
PATCH 6/9 mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and calling mmc_free_host() in the error path, besides, led_classdev_unregister() and pm_runtime_disable() also need be called.
--- drivers/mmc/host/rtsx_usb_sdmmc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/mmc/host/rtsx_usb_sdmmc.c +10 -1
@@ -1329,6 +1329,7 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)#ifdef RTSX_USB_USE_LEDS_CLASS int err;#endif +int ret; ucr =usb_get_intfdata (to_usb_interface (pdev->dev.parent));if (!ucr)
@@ -1365,7 +1366,15 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)INIT_WORK (&host->led_work, rtsx_usb_update_led);#endif -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) { +#ifdef RTSX_USB_USE_LEDS_CLASS +led_classdev_unregister (&host->led); +#endif +mmc_free_host (mmc); +pm_runtime_disable (&pdev->dev); +return ret; + }return 0 ; }
Signature · 1 line
2.25.1
PATCH 7/9 mmc: toshsd: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host(), besides, free_irq() also needs be called.
--- drivers/mmc/host/toshsd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mmc/host/toshsd.c +5 -1
@@ -651,7 +651,9 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (ret) goto unmap; -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) + goto free_irq; base =pci_resource_start (pdev,0 );dev_dbg (&pdev->dev,"MMIO %pa, IRQ %d\n" , &base, pdev->irq);
@@ -660,6 +662,8 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +free_irq: +free_irq (pdev->irq, host); unmap:pci_iounmap (pdev, host->ioaddr); release:
Signature · 1 line
2.25.1
PATCH 8/9 mmc: vub300: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host(), besides, the timer added before mmc_add_host() needs be del.
And this patch fixes another missing call mmc_free_host() if usb_control_msg() fails.
--- drivers/mmc/host/vub300.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/mmc/host/vub300.c +8 -3
@@ -2299,14 +2299,14 @@ static int vub300_probe(struct usb_interface *interface,0x0000 ,0x0000 , &vub300->system_port_status, sizeof(vub300->system_port_status), 1000);if (retval <0 ) { - goto error4; + goto error5; }else if (sizeof (vub300->system_port_status) == retval) { vub300->card_present = (0x0001 & vub300->system_port_status.port_flags) ?1 :0 ; vub300->read_only = (0x0010 & vub300->system_port_status.port_flags) ?1 :0 ; }else { - goto error4; + goto error5; }usb_set_intfdata (interface, vub300);INIT_DELAYED_WORK (&vub300->pollwork, vub300_pollwork_thread);
@@ -2329,8 +2329,13 @@ static int vub300_probe(struct usb_interface *interface,"USB vub300 remote SDIO host controller[%d]" "connected with no SD/SDIO card inserted\n" , interface_to_InterfaceNumber(interface)); -mmc_add_host (mmc); + retval =mmc_add_host (mmc); +if (retval) + goto error6; +return 0 ; +error6: +del_timer_sync (&vub300->inactivity_timer); error5:mmc_free_host (mmc);/*
Signature · 1 line
2.25.1
PATCH 9/9 mmc: wmt-sdmmc: fix return value check of mmc_add_host()
In reply to Yang Yingliangmmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and goto error path which will call mmc_free_host(), besides, clk_disable_unprepare() also needs be called.
--- drivers/mmc/host/wmt-sdmmc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mmc/host/wmt-sdmmc.c +5 -1
@@ -856,11 +856,15 @@ static int wmt_mci_probe(struct platform_device *pdev)/* configure the controller to a known 'ready' state */ wmt_reset_hardware (mmc); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) + goto fail7;dev_info (&pdev->dev,"WMT SDHC Controller initialized\n" );return 0 ; +fail7: +clk_disable_unprepare (priv->clk_sdmmc); fail6:clk_put (priv->clk_sdmmc); fail5_and_a_half:
Signature · 1 line
2.25.1
Quoted 20 lines · Yang Yingliang
mmc_add_host()may return error, but it was ignored in some drivers, if we ignore it, the memory that allocated inmmc_alloc_host()will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.So fix this by checking the return value and calling
mmc_free_host()in error path.Yang Yingliang (9):
mmc: alcor: fix return value check ofmmc_add_host()
mmc: moxart: fix return value check ofmmc_add_host()
mmc: mxcmmc: fix return value check ofmmc_add_host()
mmc: pxamci: fix return value check ofmmc_add_host()
mmc:rtsx_pci: fix return value check ofmmc_add_host()
mmc:rtsx_usb_sdmmc: fix return value check ofmmc_add_host()
mmc: toshsd: fix return value check ofmmc_add_host()
mmc: vub300: fix return value check ofmmc_add_host()
mmc: wmt-sdmmc: fix return value check ofmmc_add_host()
Quoted 11 lines
drivers/mmc/host/alcor.c | 5 ++++- drivers/mmc/host/moxart-mmc.c | 4 +++- drivers/mmc/host/mxcmmc.c | 4 +++- drivers/mmc/host/pxamci.c | 7 ++++++- drivers/mmc/host/rtsx_pci_sdmmc.c | 9 ++++++++- drivers/mmc/host/rtsx_usb_sdmmc.c | 11 ++++++++++- drivers/mmc/host/toshsd.c | 6 +++++- drivers/mmc/host/vub300.c | 11 ++++++++--- drivers/mmc/host/wmt-sdmmc.c | 6 +++++- 9 files changed, 52 insertions(+), 11 deletions(-)
Applied for next, thanks!
Kind regards
Uffe