* [PATCH] ata: handle failure of devm_ioremap()
@ 2022-06-12 7:32 Li Qiong
2022-06-12 9:06 ` Sergey Shtylyov
2022-06-12 12:57 ` [PATCH v2] ata: pata_pxa: " Li Qiong
0 siblings, 2 replies; 9+ messages in thread
From: Li Qiong @ 2022-06-12 7:32 UTC (permalink / raw)
To: Sergey Shtylyov, Damien Le Moal
Cc: linux-ide, linux-kernel, hukun, qixu, yuzhe, renyu, Li Qiong
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 <liqiong@nfschina.com>
---
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] ata: handle failure of devm_ioremap()
2022-06-12 7:32 [PATCH] ata: handle failure of devm_ioremap() Li Qiong
@ 2022-06-12 9:06 ` Sergey Shtylyov
2022-06-12 12:34 ` liqiong
2022-06-12 12:57 ` [PATCH v2] ata: pata_pxa: " Li Qiong
1 sibling, 1 reply; 9+ messages in thread
From: Sergey Shtylyov @ 2022-06-12 9:06 UTC (permalink / raw)
To: Li Qiong, Damien Le Moal
Cc: linux-ide, linux-kernel, hukun, qixu, yuzhe, renyu
Hello!
The subject should include the driver's name, like below:
ata: pata_pxa: handle failure of devm_ioremap()
On 6/12/22 10:32 AM, 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 <liqiong@nfschina.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ata: handle failure of devm_ioremap()
2022-06-12 9:06 ` Sergey Shtylyov
@ 2022-06-12 12:34 ` liqiong
0 siblings, 0 replies; 9+ messages in thread
From: liqiong @ 2022-06-12 12:34 UTC (permalink / raw)
To: Sergey Shtylyov, Damien Le Moal
Cc: linux-ide, linux-kernel, hukun, qixu, yuzhe, renyu
在 2022年06月12日 17:06, Sergey Shtylyov 写道:
> Hello!
>
> The subject should include the driver's name, like below:
>
> ata: pata_pxa: handle failure of devm_ioremap()
>
> On 6/12/22 10:32 AM, 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 <liqiong@nfschina.com>
>
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>
> [...]
>
> MBR, Sergey
Thanks, I will submit a v2 patch.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-12 7:32 [PATCH] ata: handle failure of devm_ioremap() Li Qiong
2022-06-12 9:06 ` Sergey Shtylyov
@ 2022-06-12 12:57 ` Li Qiong
2022-06-12 18:37 ` Sergei Shtylyov
1 sibling, 1 reply; 9+ messages in thread
From: Li Qiong @ 2022-06-12 12:57 UTC (permalink / raw)
To: Sergey Shtylyov, Damien Le Moal
Cc: linux-ide, linux-kernel, yuzhe, renyu, Li Qiong
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 <liqiong@nfschina.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-12 12:57 ` [PATCH v2] ata: pata_pxa: " Li Qiong
@ 2022-06-12 18:37 ` Sergei Shtylyov
2022-06-12 22:47 ` Damien Le Moal
0 siblings, 1 reply; 9+ messages in thread
From: Sergei Shtylyov @ 2022-06-12 18:37 UTC (permalink / raw)
To: Li Qiong, Sergey Shtylyov, Damien Le Moal
Cc: linux-ide, linux-kernel, yuzhe, renyu
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 <liqiong@nfschina.com>
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> ---
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-12 18:37 ` Sergei Shtylyov
@ 2022-06-12 22:47 ` Damien Le Moal
2022-06-13 1:07 ` liqiong
2022-06-13 11:50 ` Sergey Shtylyov
0 siblings, 2 replies; 9+ messages in thread
From: Damien Le Moal @ 2022-06-12 22:47 UTC (permalink / raw)
To: Sergei Shtylyov, Li Qiong, Sergey Shtylyov; +Cc: linux-ide, yuzhe, renyu
On 6/13/22 03:37, Sergei Shtylyov wrote:
> 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.
This error is very unlikely. So unless you are seeing actual problems in
the field, I do not think it is worth fixing.
>>
>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>> ---
>> 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
Yes, having to do an ioremap of an IORESOURCE_DMA resource is rather
unusual. dmaengine_slave_config() should be doing anything that is
required for that resource.
> 'ap->ioaddr.bmdma_addr' doesn;t seem to be used anyways...
It is used in lbata-sff.c.
A much cleaner fix would be to use
devm_platform_get_and_ioremap_resource() or
devm_platform_ioremap_resource() which will also remove the call to
platform_get_resource((). But as mentioned above, unless this is fixing an
actual bug in production, I do not think this is worth it.
>
> MBR, Sergey
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-12 22:47 ` Damien Le Moal
@ 2022-06-13 1:07 ` liqiong
2022-06-13 11:50 ` Sergey Shtylyov
1 sibling, 0 replies; 9+ messages in thread
From: liqiong @ 2022-06-13 1:07 UTC (permalink / raw)
To: Damien Le Moal, Sergei Shtylyov, Sergey Shtylyov; +Cc: linux-ide, yuzhe, renyu
在 2022年06月13日 06:47, Damien Le Moal 写道:
> On 6/13/22 03:37, Sergei Shtylyov wrote:
>> 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.
> This error is very unlikely. So unless you are seeing actual problems in
> the field, I do not think it is worth fixing.
Agree, It's very unlikely.
This patch follows the guide of "KernelJanitors", wants to refine the code a little bit .
I searched and found that most of the other codes had checked the return value.
Actually, no actual bug relation to this patch.
Thanks,
Li Qiong
>
>>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>>> ---
>>> 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
> Yes, having to do an ioremap of an IORESOURCE_DMA resource is rather
> unusual. dmaengine_slave_config() should be doing anything that is
> required for that resource.
>
>> 'ap->ioaddr.bmdma_addr' doesn;t seem to be used anyways...
> It is used in lbata-sff.c.
>
> A much cleaner fix would be to use
> devm_platform_get_and_ioremap_resource() or
> devm_platform_ioremap_resource() which will also remove the call to
> platform_get_resource((). But as mentioned above, unless this is fixing an
> actual bug in production, I do not think this is worth it.
>
>> MBR, Sergey
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-12 22:47 ` Damien Le Moal
2022-06-13 1:07 ` liqiong
@ 2022-06-13 11:50 ` Sergey Shtylyov
2022-06-13 11:56 ` Damien Le Moal
1 sibling, 1 reply; 9+ messages in thread
From: Sergey Shtylyov @ 2022-06-13 11:50 UTC (permalink / raw)
To: Damien Le Moal, Sergei Shtylyov, Li Qiong; +Cc: linux-ide, yuzhe, renyu
On 6/13/22 1:47 AM, Damien Le Moal 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.
>
> This error is very unlikely. So unless you are seeing actual problems in
> the field, I do not think it is worth fixing.
The error paths should absolutely be fixed. It helps avoid an oops later...
>>>
>>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>>> ---
>>> 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
>
> Yes, having to do an ioremap of an IORESOURCE_DMA resource is rather
> unusual. dmaengine_slave_config() should be doing anything that is
> required for that resource.
>
>> 'ap->ioaddr.bmdma_addr' doesn;t seem to be used anyways...
>
> It is used in lbata-sff.c.
Where exactly? To me, it looked like all ata_bmdma_port_ops were overridden
by the driver... Even if not so, I don't think such code is correct...
>
> A much cleaner fix would be to use
> devm_platform_get_and_ioremap_resource() or
> devm_platform_ioremap_resource() which will also remove the call to
> platform_get_resource(().
This is an -rc1 material.
> But as mentioned above, unless this is fixing an
> actual bug in production, I do not think this is worth it.
I strongly disagree here.
MBR, Sergey
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ata: pata_pxa: handle failure of devm_ioremap()
2022-06-13 11:50 ` Sergey Shtylyov
@ 2022-06-13 11:56 ` Damien Le Moal
0 siblings, 0 replies; 9+ messages in thread
From: Damien Le Moal @ 2022-06-13 11:56 UTC (permalink / raw)
To: Sergey Shtylyov, Sergei Shtylyov, Li Qiong; +Cc: linux-ide, yuzhe, renyu
On 6/13/22 20:50, Sergey Shtylyov wrote:
> On 6/13/22 1:47 AM, Damien Le Moal 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.
>>
>> This error is very unlikely. So unless you are seeing actual problems in
>> the field, I do not think it is worth fixing.
>
> The error paths should absolutely be fixed. It helps avoid an oops later...
>
>>>>
>>>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>>>> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>>>> ---
>>>> 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
>>
>> Yes, having to do an ioremap of an IORESOURCE_DMA resource is rather
>> unusual. dmaengine_slave_config() should be doing anything that is
>> required for that resource.
>>
>>> 'ap->ioaddr.bmdma_addr' doesn;t seem to be used anyways...
>>
>> It is used in lbata-sff.c.
>
> Where exactly? To me, it looked like all ata_bmdma_port_ops were overridden
> by the driver... Even if not so, I don't think such code is correct...
>
>>
>> A much cleaner fix would be to use
>> devm_platform_get_and_ioremap_resource() or
>> devm_platform_ioremap_resource() which will also remove the call to
>> platform_get_resource(().
>
> This is an -rc1 material.
>
>> But as mentioned above, unless this is fixing an
>> actual bug in production, I do not think this is worth it.
>
> I strongly disagree here.
Not opposed to fixing this driver. But definitely low priority.
>
> MBR, Sergey
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-06-13 14:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-12 7:32 [PATCH] ata: handle failure of devm_ioremap() Li Qiong
2022-06-12 9:06 ` Sergey Shtylyov
2022-06-12 12:34 ` liqiong
2022-06-12 12:57 ` [PATCH v2] ata: pata_pxa: " Li Qiong
2022-06-12 18:37 ` Sergei Shtylyov
2022-06-12 22:47 ` Damien Le Moal
2022-06-13 1:07 ` liqiong
2022-06-13 11:50 ` Sergey Shtylyov
2022-06-13 11:56 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox