2022-06-12 13:44:52

by Li Qiong

[permalink] [raw]
Subject: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()

As the possible failure of the devm_ioremap(), the return value
could be NULL. Therefore it should be better to check it and
print error message, return '-ENOMEM' error code.

Signed-off-by: Li Qiong <[email protected]>
Reviewed-by: Sergey Shtylyov <[email protected]>
---
v2:
- add driver's name (pata_pxa) to subject.
---
drivers/ata/pata_pxa.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c
index 985f42c4fd70..cd1a8f37f920 100644
--- a/drivers/ata/pata_pxa.c
+++ b/drivers/ata/pata_pxa.c
@@ -228,6 +228,11 @@ static int pxa_ata_probe(struct platform_device *pdev)
ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
resource_size(dma_res));

+ if (!ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr || !ap->ioaddr.bmdma_addr) {
+ dev_err(&pdev->dev, "failed to map ap->ioaddr\n");
+ return -ENOMEM;
+ }
+
/*
* Adjust register offsets
*/
--
2.11.0


2022-06-12 18:42:16

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()

On 6/12/22 3:57 PM, Li Qiong wrote:

> As the possible failure of the devm_ioremap(), the return value
> could be NULL. Therefore it should be better to check it and
> print error message, return '-ENOMEM' error code.
>
> Signed-off-by: Li Qiong <[email protected]>
> Reviewed-by: Sergey Shtylyov <[email protected]>
> ---
> v2:
> - add driver's name (pata_pxa) to subject.
> ---
> drivers/ata/pata_pxa.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c
> index 985f42c4fd70..cd1a8f37f920 100644
> --- a/drivers/ata/pata_pxa.c
> +++ b/drivers/ata/pata_pxa.c
> @@ -228,6 +228,11 @@ static int pxa_ata_probe(struct platform_device *pdev)
> ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
> resource_size(dma_res));

Looking again into this driver, this statement doesn't make sense: dma_res
points to a DMA resource, calling devm_ioremap() on it is just wrong... and
'ap->ioaddr.bmdma_addr' doesn;t seem to be used anyways...

MBR, Sergey