Replace fsl_lpspi->chipselect by controller->cs_gpios. Clean up the code. Signed-off-by: Clark Wang <xiaoning.wang@xxxxxxx> Acked-by: Fugang Duan <fugang.duan@xxxxxxx> --- drivers/spi/spi-fsl-lpspi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index a8e83cb96f61..aa6218cbc9e8 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -124,8 +124,6 @@ struct fsl_lpspi_data { bool usedma; struct completion dma_rx_completion; struct completion dma_tx_completion; - - int chipselect[0]; }; static const struct of_device_id fsl_lpspi_dt_ids[] = { @@ -230,10 +228,8 @@ static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller) static int fsl_lpspi_prepare_message(struct spi_controller *controller, struct spi_message *msg) { - struct fsl_lpspi_data *fsl_lpspi = - spi_controller_get_devdata(controller); struct spi_device *spi = msg->spi; - int gpio = fsl_lpspi->chipselect[spi->chip_select]; + int gpio = controller->cs_gpios[spi->chip_select]; if (gpio_is_valid(gpio)) gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); @@ -877,6 +873,9 @@ static int fsl_lpspi_probe(struct platform_device *pdev) fsl_lpspi->dev = &pdev->dev; fsl_lpspi->is_slave = is_slave; + controller->cs_gpios = devm_kzalloc(&controller->dev, + sizeof(int) * controller->num_chipselect, GFP_KERNEL); + if (!fsl_lpspi->is_slave) { for (i = 0; i < controller->num_chipselect; i++) { int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); @@ -884,19 +883,18 @@ static int fsl_lpspi_probe(struct platform_device *pdev) if (!gpio_is_valid(cs_gpio) && lpspi_platform_info) cs_gpio = lpspi_platform_info->chipselect[i]; - fsl_lpspi->chipselect[i] = cs_gpio; + controller->cs_gpios[i] = cs_gpio; if (!gpio_is_valid(cs_gpio)) continue; ret = devm_gpio_request(&pdev->dev, - fsl_lpspi->chipselect[i], + controller->cs_gpios[i], DRIVER_NAME); if (ret) { dev_err(&pdev->dev, "can't get cs gpios\n"); goto out_controller_put; } } - controller->cs_gpios = fsl_lpspi->chipselect; controller->prepare_message = fsl_lpspi_prepare_message; } -- 2.17.1