Skip to content

Commit 3b9561e

Browse files
Stephen Warrengregkh
authored andcommitted
USB: set device dma_mask without reference to global data
Many USB host drivers contain code such as: if (!pdev->dev.dma_mask) pdev->dev.dma_mask = &tegra_ehci_dma_mask; ... where tegra_ehci_dma_mask is a global. I suspect this code originated in commit 4a53f4e "USB: ehci-tegra: add probing through device tree" and was simply copied everywhere else. This works fine when the code is built-in, but can cause a crash when the code is in a module. The first module load sets up the dma_mask pointer, but if the module is removed and re-inserted, the value is now non-NULL, and hence is not updated to point at the new location, and hence points at a stale location within the previous module load address, which in turn causes a crash if the pointer is de-referenced. The simplest way of solving this seems to be to copy the code from ehci-platform.c, which uses the coherent_dma_mask as the target for the dma_mask pointer. Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Tony Prisk <linux@prisktech.co.nz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8ff10bd commit 3b9561e

14 files changed

Lines changed: 41 additions & 52 deletions

‎drivers/usb/chipidea/ci13xxx_imx.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,10 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
173173

174174
ci13xxx_imx_platdata.phy = data->phy;
175175

176-
if (!pdev->dev.dma_mask) {
177-
pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
178-
sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
179-
if (!pdev->dev.dma_mask) {
180-
ret = -ENOMEM;
181-
dev_err(&pdev->dev, "Failed to alloc dma_mask!\n");
182-
goto err;
183-
}
184-
*pdev->dev.dma_mask = DMA_BIT_MASK(32);
185-
dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
186-
}
176+
if (!pdev->dev.dma_mask)
177+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
178+
if (!pdev->dev.coherent_dma_mask)
179+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
187180

188181
if (usbmisc_ops && usbmisc_ops->init) {
189182
ret = usbmisc_ops->init(&pdev->dev);

‎drivers/usb/dwc3/dwc3-exynos.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ static int dwc3_exynos_remove_child(struct device *dev, void *unused)
9595
return 0;
9696
}
9797

98-
static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
99-
10098
static int dwc3_exynos_probe(struct platform_device *pdev)
10199
{
102100
struct dwc3_exynos *exynos;
@@ -118,7 +116,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
118116
* Once we move to full device tree support this will vanish off.
119117
*/
120118
if (!dev->dma_mask)
121-
dev->dma_mask = &dwc3_exynos_dma_mask;
119+
dev->dma_mask = &dev->coherent_dma_mask;
120+
if (!dev->coherent_dma_mask)
121+
dev->coherent_dma_mask = DMA_BIT_MASK(32);
122122

123123
platform_set_drvdata(pdev, exynos);
124124

‎drivers/usb/host/ehci-atmel.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ static void atmel_stop_ehci(struct platform_device *pdev)
6363

6464
/*-------------------------------------------------------------------------*/
6565

66-
static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32);
67-
6866
static int ehci_atmel_drv_probe(struct platform_device *pdev)
6967
{
7068
struct usb_hcd *hcd;
@@ -93,7 +91,9 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
9391
* Once we have dma capability bindings this can go away.
9492
*/
9593
if (!pdev->dev.dma_mask)
96-
pdev->dev.dma_mask = &at91_ehci_dma_mask;
94+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
95+
if (!pdev->dev.coherent_dma_mask)
96+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
9797

9898
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
9999
if (!hcd) {

‎drivers/usb/host/ehci-omap.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ static const struct ehci_driver_overrides ehci_omap_overrides __initdata = {
9090
.extra_priv_size = sizeof(struct omap_hcd),
9191
};
9292

93-
static u64 omap_ehci_dma_mask = DMA_BIT_MASK(32);
94-
9593
/**
9694
* ehci_hcd_omap_probe - initialize TI-based HCDs
9795
*
@@ -146,8 +144,10 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
146144
* Since shared usb code relies on it, set it here for now.
147145
* Once we have dma capability bindings this can go away.
148146
*/
149-
if (!pdev->dev.dma_mask)
150-
pdev->dev.dma_mask = &omap_ehci_dma_mask;
147+
if (!dev->dma_mask)
148+
dev->dma_mask = &dev->coherent_dma_mask;
149+
if (!dev->coherent_dma_mask)
150+
dev->coherent_dma_mask = DMA_BIT_MASK(32);
151151

152152
hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
153153
dev_name(dev));

‎drivers/usb/host/ehci-orion.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
137137
}
138138
}
139139

140-
static u64 ehci_orion_dma_mask = DMA_BIT_MASK(32);
141-
142140
static int ehci_orion_drv_probe(struct platform_device *pdev)
143141
{
144142
struct orion_ehci_data *pd = pdev->dev.platform_data;
@@ -183,7 +181,9 @@ static int ehci_orion_drv_probe(struct platform_device *pdev)
183181
* now. Once we have dma capability bindings this can go away.
184182
*/
185183
if (!pdev->dev.dma_mask)
186-
pdev->dev.dma_mask = &ehci_orion_dma_mask;
184+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
185+
if (!pdev->dev.coherent_dma_mask)
186+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
187187

188188
if (!request_mem_region(res->start, resource_size(res),
189189
ehci_orion_hc_driver.description)) {

‎drivers/usb/host/ehci-s5p.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static void s5p_setup_vbus_gpio(struct platform_device *pdev)
7171
dev_err(dev, "can't request ehci vbus gpio %d", gpio);
7272
}
7373

74-
static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
75-
7674
static int s5p_ehci_probe(struct platform_device *pdev)
7775
{
7876
struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
@@ -90,7 +88,7 @@ static int s5p_ehci_probe(struct platform_device *pdev)
9088
* Once we move to full device tree support this will vanish off.
9189
*/
9290
if (!pdev->dev.dma_mask)
93-
pdev->dev.dma_mask = &ehci_s5p_dma_mask;
91+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
9492
if (!pdev->dev.coherent_dma_mask)
9593
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
9694

‎drivers/usb/host/ehci-spear.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ static int ehci_spear_drv_resume(struct device *dev)
5858
static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
5959
ehci_spear_drv_resume);
6060

61-
static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
62-
6361
static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
6462
{
6563
struct usb_hcd *hcd ;
@@ -84,7 +82,9 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
8482
* Once we have dma capability bindings this can go away.
8583
*/
8684
if (!pdev->dev.dma_mask)
87-
pdev->dev.dma_mask = &spear_ehci_dma_mask;
85+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
86+
if (!pdev->dev.coherent_dma_mask)
87+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
8888

8989
usbh_clk = devm_clk_get(&pdev->dev, NULL);
9090
if (IS_ERR(usbh_clk)) {

‎drivers/usb/host/ehci-tegra.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,6 @@ static void tegra_ehci_set_phcd(struct usb_phy *x, bool enable)
637637
writel(val, base + TEGRA_USB_PORTSC1);
638638
}
639639

640-
static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32);
641-
642640
static int tegra_ehci_probe(struct platform_device *pdev)
643641
{
644642
struct resource *res;
@@ -661,7 +659,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
661659
* Once we have dma capability bindings this can go away.
662660
*/
663661
if (!pdev->dev.dma_mask)
664-
pdev->dev.dma_mask = &tegra_ehci_dma_mask;
662+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
663+
if (!pdev->dev.coherent_dma_mask)
664+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
665665

666666
setup_vbus_gpio(pdev, pdata);
667667

‎drivers/usb/host/ohci-at91.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ static const struct of_device_id at91_ohci_dt_ids[] = {
504504

505505
MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
506506

507-
static u64 at91_ohci_dma_mask = DMA_BIT_MASK(32);
508-
509507
static int ohci_at91_of_init(struct platform_device *pdev)
510508
{
511509
struct device_node *np = pdev->dev.of_node;
@@ -522,7 +520,9 @@ static int ohci_at91_of_init(struct platform_device *pdev)
522520
* Once we have dma capability bindings this can go away.
523521
*/
524522
if (!pdev->dev.dma_mask)
525-
pdev->dev.dma_mask = &at91_ohci_dma_mask;
523+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
524+
if (!pdev->dev.coherent_dma_mask)
525+
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
526526

527527
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
528528
if (!pdata)

‎drivers/usb/host/ohci-exynos.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static const struct hc_driver exynos_ohci_hc_driver = {
9898
.start_port_reset = ohci_start_port_reset,
9999
};
100100

101-
static u64 ohci_exynos_dma_mask = DMA_BIT_MASK(32);
102-
103101
static int exynos_ohci_probe(struct platform_device *pdev)
104102
{
105103
struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
@@ -117,7 +115,7 @@ static int exynos_ohci_probe(struct platform_device *pdev)
117115
* Once we move to full device tree support this will vanish off.
118116
*/
119117
if (!pdev->dev.dma_mask)
120-
pdev->dev.dma_mask = &ohci_exynos_dma_mask;
118+
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
121119
if (!pdev->dev.coherent_dma_mask)
122120
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
123121

0 commit comments

Comments
 (0)