Make use of local struct device pointer to not dereference the
platform_device pointer everytime.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/dma/imx-sdma.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 422086632d3445b2ce3f2e5df9b2130174a311e8..a85739d279f51fdb517fce90b3dc67673cf2b56c 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -2234,7 +2234,8 @@ static struct dma_chan *sdma_xlate(struct of_phandle_args *dma_spec,
static int sdma_probe(struct platform_device *pdev)
{
- struct device_node *np = pdev->dev.of_node;
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
struct device_node *spba_bus;
const char *fw_name;
int ret;
@@ -2244,18 +2245,18 @@ static int sdma_probe(struct platform_device *pdev)
struct sdma_engine *sdma;
s32 *saddr_arr;
- ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+ ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret)
return ret;
- sdma = devm_kzalloc(&pdev->dev, sizeof(*sdma), GFP_KERNEL);
+ sdma = devm_kzalloc(dev, sizeof(*sdma), GFP_KERNEL);
if (!sdma)
return -ENOMEM;
spin_lock_init(&sdma->channel_0_lock);
- sdma->dev = &pdev->dev;
- sdma->drvdata = of_device_get_match_data(sdma->dev);
+ sdma->dev = dev;
+ sdma->drvdata = of_device_get_match_data(dev);
irq = platform_get_irq(pdev, 0);
if (irq < 0)
@@ -2265,11 +2266,11 @@ static int sdma_probe(struct platform_device *pdev)
if (IS_ERR(sdma->regs))
return PTR_ERR(sdma->regs);
- sdma->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
+ sdma->clk_ipg = devm_clk_get(dev, "ipg");
if (IS_ERR(sdma->clk_ipg))
return PTR_ERR(sdma->clk_ipg);
- sdma->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
+ sdma->clk_ahb = devm_clk_get(dev, "ahb");
if (IS_ERR(sdma->clk_ahb))
return PTR_ERR(sdma->clk_ahb);
@@ -2281,8 +2282,8 @@ static int sdma_probe(struct platform_device *pdev)
if (ret)
goto err_clk;
- ret = devm_request_irq(&pdev->dev, irq, sdma_int_handler, 0,
- dev_name(&pdev->dev), sdma);
+ ret = devm_request_irq(dev, irq, sdma_int_handler, 0,
+ dev_name(dev), sdma);
if (ret)
goto err_irq;
@@ -2327,7 +2328,7 @@ static int sdma_probe(struct platform_device *pdev)
sdma->iram_pool = of_gen_pool_get(np, "iram", 0);
if (sdma->iram_pool)
- dev_info(&pdev->dev, "alloc bd from iram.\n");
+ dev_info(dev, "alloc bd from iram.\n");
ret = sdma_init(sdma);
if (ret)
@@ -2340,7 +2341,7 @@ static int sdma_probe(struct platform_device *pdev)
if (sdma->drvdata->script_addrs)
sdma_add_scripts(sdma, sdma->drvdata->script_addrs);
- sdma->dma_device.dev = &pdev->dev;
+ sdma->dma_device.dev = dev;
sdma->dma_device.device_alloc_chan_resources = sdma_alloc_chan_resources;
sdma->dma_device.device_free_chan_resources = sdma_free_chan_resources;
@@ -2363,13 +2364,13 @@ static int sdma_probe(struct platform_device *pdev)
ret = dma_async_device_register(&sdma->dma_device);
if (ret) {
- dev_err(&pdev->dev, "unable to register\n");
+ dev_err(dev, "unable to register\n");
goto err_init;
}
ret = of_dma_controller_register(np, sdma_xlate, sdma);
if (ret) {
- dev_err(&pdev->dev, "failed to register controller\n");
+ dev_err(dev, "failed to register controller\n");
goto err_register;
}
@@ -2389,11 +2390,11 @@ static int sdma_probe(struct platform_device *pdev)
ret = of_property_read_string(np, "fsl,sdma-ram-script-name",
&fw_name);
if (ret) {
- dev_warn(&pdev->dev, "failed to get firmware name\n");
+ dev_warn(dev, "failed to get firmware name\n");
} else {
ret = sdma_get_firmware(sdma, fw_name);
if (ret)
- dev_warn(&pdev->dev, "failed to get firmware from device tree\n");
+ dev_warn(dev, "failed to get firmware from device tree\n");
}
return 0;
--
2.47.2
On Wed, Sep 03, 2025 at 03:06:11PM +0200, Marco Felsch wrote: > Make use of local struct device pointer to not dereference the > platform_device pointer everytime. > > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> > --- > drivers/dma/imx-sdma.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c > index 422086632d3445b2ce3f2e5df9b2130174a311e8..a85739d279f51fdb517fce90b3dc67673cf2b56c 100644 > --- a/drivers/dma/imx-sdma.c > +++ b/drivers/dma/imx-sdma.c > @@ -2234,7 +2234,8 @@ static struct dma_chan *sdma_xlate(struct of_phandle_args *dma_spec, > > static int sdma_probe(struct platform_device *pdev) > { > - struct device_node *np = pdev->dev.of_node; > + struct device *dev = &pdev->dev; > + struct device_node *np = dev->of_node; > struct device_node *spba_bus; > const char *fw_name; > int ret; > @@ -2244,18 +2245,18 @@ static int sdma_probe(struct platform_device *pdev) > struct sdma_engine *sdma; > s32 *saddr_arr; > > - ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); > + ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); > if (ret) > return ret; Not related this patch, you can remove this check later because dma_coerce_mask_and_coherent() never return failure when >= 32bit. Reviewed-by: Frank Li <Frank.Li@nxp.com> > > - sdma = devm_kzalloc(&pdev->dev, sizeof(*sdma), GFP_KERNEL); > + sdma = devm_kzalloc(dev, sizeof(*sdma), GFP_KERNEL); > if (!sdma) > return -ENOMEM; > > spin_lock_init(&sdma->channel_0_lock); > > - sdma->dev = &pdev->dev; > - sdma->drvdata = of_device_get_match_data(sdma->dev); > + sdma->dev = dev; > + sdma->drvdata = of_device_get_match_data(dev); > > irq = platform_get_irq(pdev, 0); > if (irq < 0) > @@ -2265,11 +2266,11 @@ static int sdma_probe(struct platform_device *pdev) > if (IS_ERR(sdma->regs)) > return PTR_ERR(sdma->regs); > > - sdma->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); > + sdma->clk_ipg = devm_clk_get(dev, "ipg"); > if (IS_ERR(sdma->clk_ipg)) > return PTR_ERR(sdma->clk_ipg); > > - sdma->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); > + sdma->clk_ahb = devm_clk_get(dev, "ahb"); > if (IS_ERR(sdma->clk_ahb)) > return PTR_ERR(sdma->clk_ahb); > > @@ -2281,8 +2282,8 @@ static int sdma_probe(struct platform_device *pdev) > if (ret) > goto err_clk; > > - ret = devm_request_irq(&pdev->dev, irq, sdma_int_handler, 0, > - dev_name(&pdev->dev), sdma); > + ret = devm_request_irq(dev, irq, sdma_int_handler, 0, > + dev_name(dev), sdma); > if (ret) > goto err_irq; > > @@ -2327,7 +2328,7 @@ static int sdma_probe(struct platform_device *pdev) > > sdma->iram_pool = of_gen_pool_get(np, "iram", 0); > if (sdma->iram_pool) > - dev_info(&pdev->dev, "alloc bd from iram.\n"); > + dev_info(dev, "alloc bd from iram.\n"); > > ret = sdma_init(sdma); > if (ret) > @@ -2340,7 +2341,7 @@ static int sdma_probe(struct platform_device *pdev) > if (sdma->drvdata->script_addrs) > sdma_add_scripts(sdma, sdma->drvdata->script_addrs); > > - sdma->dma_device.dev = &pdev->dev; > + sdma->dma_device.dev = dev; > > sdma->dma_device.device_alloc_chan_resources = sdma_alloc_chan_resources; > sdma->dma_device.device_free_chan_resources = sdma_free_chan_resources; > @@ -2363,13 +2364,13 @@ static int sdma_probe(struct platform_device *pdev) > > ret = dma_async_device_register(&sdma->dma_device); > if (ret) { > - dev_err(&pdev->dev, "unable to register\n"); > + dev_err(dev, "unable to register\n"); > goto err_init; > } > > ret = of_dma_controller_register(np, sdma_xlate, sdma); > if (ret) { > - dev_err(&pdev->dev, "failed to register controller\n"); > + dev_err(dev, "failed to register controller\n"); > goto err_register; > } > > @@ -2389,11 +2390,11 @@ static int sdma_probe(struct platform_device *pdev) > ret = of_property_read_string(np, "fsl,sdma-ram-script-name", > &fw_name); > if (ret) { > - dev_warn(&pdev->dev, "failed to get firmware name\n"); > + dev_warn(dev, "failed to get firmware name\n"); > } else { > ret = sdma_get_firmware(sdma, fw_name); > if (ret) > - dev_warn(&pdev->dev, "failed to get firmware from device tree\n"); > + dev_warn(dev, "failed to get firmware from device tree\n"); > } > > return 0; > > -- > 2.47.2 >
© 2016 - 2025 Red Hat, Inc.