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 <hao.ma@intel.com>
Fixes: cc160697a5 ("spi: pxa2xx: Convert PCI driver to use spi-pxa2xx code directly")
Fixes: 3d8f037fbc ("spi: pxa2xx: Move platform driver to a separate file")
Fixes: 20ade9b977 ("spi: pxa2xx: Extract pxa2xx_spi_platform_*() callbacks")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20240822113408.750831-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Andy Shevchenko 2024-08-22 14:30:53 +03:00 committed by Mark Brown
parent 783bf5d09f
commit 9a8fc292dd
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
4 changed files with 7 additions and 9 deletions

View File

@ -297,7 +297,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
return ret; return ret;
ssp->irq = pci_irq_vector(dev, 0); ssp->irq = pci_irq_vector(dev, 0);
return pxa2xx_spi_probe(&dev->dev, ssp); return pxa2xx_spi_probe(&dev->dev, ssp, pdata);
} }
static void pxa2xx_spi_pci_remove(struct pci_dev *dev) static void pxa2xx_spi_pci_remove(struct pci_dev *dev)

View File

@ -63,7 +63,7 @@ static struct ssp_device *pxa2xx_spi_ssp_request(struct platform_device *pdev)
ssp = pxa_ssp_request(pdev->id, pdev->name); ssp = pxa_ssp_request(pdev->id, pdev->name);
if (!ssp) if (!ssp)
return ssp; return NULL;
status = devm_add_action_or_reset(&pdev->dev, pxa2xx_spi_ssp_release, ssp); status = devm_add_action_or_reset(&pdev->dev, pxa2xx_spi_ssp_release, ssp);
if (status) if (status)
@ -148,8 +148,6 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
platform_info = pxa2xx_spi_init_pdata(pdev); platform_info = pxa2xx_spi_init_pdata(pdev);
if (IS_ERR(platform_info)) if (IS_ERR(platform_info))
return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n"); return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n");
dev->platform_data = platform_info;
} }
ssp = pxa2xx_spi_ssp_request(pdev); ssp = pxa2xx_spi_ssp_request(pdev);
@ -158,7 +156,7 @@ static int pxa2xx_spi_platform_probe(struct platform_device *pdev)
if (!ssp) if (!ssp)
ssp = &platform_info->ssp; ssp = &platform_info->ssp;
return pxa2xx_spi_probe(dev, ssp); return pxa2xx_spi_probe(dev, ssp, platform_info);
} }
static void pxa2xx_spi_platform_remove(struct platform_device *pdev) static void pxa2xx_spi_platform_remove(struct platform_device *pdev)

View File

@ -1277,16 +1277,15 @@ static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi)
return MAX_DMA_LEN; return MAX_DMA_LEN;
} }
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp) int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
struct pxa2xx_spi_controller *platform_info)
{ {
struct pxa2xx_spi_controller *platform_info;
struct spi_controller *controller; struct spi_controller *controller;
struct driver_data *drv_data; struct driver_data *drv_data;
const struct lpss_config *config; const struct lpss_config *config;
int status; int status;
u32 tmp; u32 tmp;
platform_info = dev_get_platdata(dev);
if (platform_info->is_target) if (platform_info->is_target)
controller = devm_spi_alloc_target(dev, sizeof(*drv_data)); controller = devm_spi_alloc_target(dev, sizeof(*drv_data));
else else

View File

@ -132,7 +132,8 @@ extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data); extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
extern void pxa2xx_spi_dma_release(struct driver_data *drv_data); extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp); int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp,
struct pxa2xx_spi_controller *platform_info);
void pxa2xx_spi_remove(struct device *dev); void pxa2xx_spi_remove(struct device *dev);
extern const struct dev_pm_ops pxa2xx_spi_pm_ops; extern const struct dev_pm_ops pxa2xx_spi_pm_ops;