Skip to content

Commit 9a8fc29

Browse files
andy-shevbroonie
authored andcommitted
spi: pxa2xx: Do not override dev->platform_data on probe
The platform_data field may be supplied by legacy board code. In other cases we override it, and module remove and probe cycle will crash the kernel since it will carry a stale pointer. Fix this by supplying a third argument to the pxa2xx_spi_probe() and avoid overriding dev->platform_data. Reported-by: Hao Ma <[email protected]> Fixes: cc16069 ("spi: pxa2xx: Convert PCI driver to use spi-pxa2xx code directly") Fixes: 3d8f037 ("spi: pxa2xx: Move platform driver to a separate file") Fixes: 20ade9b ("spi: pxa2xx: Extract pxa2xx_spi_platform_*() callbacks") Signed-off-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 783bf5d commit 9a8fc29

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

drivers/spi/spi-pxa2xx-pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
297297
return ret;
298298
ssp->irq = pci_irq_vector(dev, 0);
299299

300-
return pxa2xx_spi_probe(&dev->dev, ssp);
300+
return pxa2xx_spi_probe(&dev->dev, ssp, pdata);
301301
}
302302

303303
static void pxa2xx_spi_pci_remove(struct pci_dev *dev)

drivers/spi/spi-pxa2xx-platform.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static struct ssp_device *pxa2xx_spi_ssp_request(struct platform_device *pdev)
6363

6464
ssp = pxa_ssp_request(pdev->id, pdev->name);
6565
if (!ssp)
66-
return ssp;
66+
return NULL;
6767

6868
status = devm_add_action_or_reset(&pdev->dev, pxa2xx_spi_ssp_release, ssp);
6969
if (status)
@@ -148,8 +148,6 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
148148
platform_info = pxa2xx_spi_init_pdata(pdev);
149149
if (IS_ERR(platform_info))
150150
return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n");
151-
152-
dev->platform_data = platform_info;
153151
}
154152

155153
ssp = pxa2xx_spi_ssp_request(pdev);
@@ -158,7 +156,7 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
158156
if (!ssp)
159157
ssp = &platform_info->ssp;
160158

161-
return pxa2xx_spi_probe(dev, ssp);
159+
return pxa2xx_spi_probe(dev, ssp, platform_info);
162160
}
163161

164162
static void pxa2xx_spi_platform_remove(struct platform_device *pdev)

drivers/spi/spi-pxa2xx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,16 +1277,15 @@ static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi)
12771277
return MAX_DMA_LEN;
12781278
}
12791279

1280-
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp)
1280+
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
1281+
struct pxa2xx_spi_controller *platform_info)
12811282
{
1282-
struct pxa2xx_spi_controller *platform_info;
12831283
struct spi_controller *controller;
12841284
struct driver_data *drv_data;
12851285
const struct lpss_config *config;
12861286
int status;
12871287
u32 tmp;
12881288

1289-
platform_info = dev_get_platdata(dev);
12901289
if (platform_info->is_target)
12911290
controller = devm_spi_alloc_target(dev, sizeof(*drv_data));
12921291
else

drivers/spi/spi-pxa2xx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
132132
extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
133133
extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
134134

135-
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp);
135+
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
136+
struct pxa2xx_spi_controller *platform_info);
136137
void pxa2xx_spi_remove(struct device *dev);
137138

138139
extern const struct dev_pm_ops pxa2xx_spi_pm_ops;

0 commit comments

Comments
 (0)