* [PATCH v3] ide: Check for null pointer after calling devm_ioremap
@ 2022-01-07 12:53 Jiasheng Jiang
2022-01-08 2:53 ` Damien Le Moal
0 siblings, 1 reply; 7+ messages in thread
From: Jiasheng Jiang @ 2022-01-07 12:53 UTC (permalink / raw)
To: damien.lemoal, David.Laight, davem
Cc: linux-ide, linux-kernel, Jiasheng Jiang, stable
In linux-stable-5.15.13, this file has been removed and combined
to `drivers/ata/pata_platform.c` without this bug.
But in the older LTS kernels, like 5.10.90, this bug still exists.
As the possible failure of the devres_alloc(), the devm_ioremap() and
devm_ioport_map() may return NULL pointer.
And then, the 'base' and 'alt_base' are used in plat_ide_setup_ports().
Therefore, it should be better to add the check in order to avoid the
dereference of the NULL pointer.
Actually, it introduced the bug from commit 8cb1f567f4c0
("ide: Platform IDE driver") and we can know from the commit message
that it tended to be similar to the `drivers/ata/pata_platform.c`.
But actually, even the first time pata_platform was built,
commit a20c9e820864 ("[PATCH] ata: Generic platform_device libata driver"),
there was no the bug, as there was a check after the ioremap().
So possibly the bug was caused by ide itself.
Fixes: 8cb1f567f4c0 ("ide: Platform IDE driver")
Cc: stable@vger.kernel.org#5.10
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog
v1 -> v2
* Change 1. Correct the fixes tag and commit message.
v2 -> v3
* Change 1. Correct the code.
---
drivers/ide/ide_platform.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ide/ide_platform.c b/drivers/ide/ide_platform.c
index 91639fd6c276..5500c5afb3ca 100644
--- a/drivers/ide/ide_platform.c
+++ b/drivers/ide/ide_platform.c
@@ -85,6 +85,10 @@ static int plat_ide_probe(struct platform_device *pdev)
alt_base = devm_ioport_map(&pdev->dev,
res_alt->start, resource_size(res_alt));
}
+ if (!base || !alt_base) {
+ ret = -ENOMEM;
+ goto out;
+ }
memset(&hw, 0, sizeof(hw));
plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] ide: Check for null pointer after calling devm_ioremap
2022-01-07 12:53 [PATCH v3] ide: Check for null pointer after calling devm_ioremap Jiasheng Jiang
@ 2022-01-08 2:53 ` Damien Le Moal
0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2022-01-08 2:53 UTC (permalink / raw)
To: Jiasheng Jiang, David.Laight, davem, Greg Kroah-Hartman, stable
Cc: linux-ide, linux-kernel
On 2022/01/07 21:53, Jiasheng Jiang wrote:
> In linux-stable-5.15.13, this file has been removed and combined
> to `drivers/ata/pata_platform.c` without this bug.
> But in the older LTS kernels, like 5.10.90, this bug still exists.
> As the possible failure of the devres_alloc(), the devm_ioremap() and
> devm_ioport_map() may return NULL pointer.
> And then, the 'base' and 'alt_base' are used in plat_ide_setup_ports().
> Therefore, it should be better to add the check in order to avoid the
> dereference of the NULL pointer.
> Actually, it introduced the bug from commit 8cb1f567f4c0
> ("ide: Platform IDE driver") and we can know from the commit message
> that it tended to be similar to the `drivers/ata/pata_platform.c`.
> But actually, even the first time pata_platform was built,
> commit a20c9e820864 ("[PATCH] ata: Generic platform_device libata driver"),
> there was no the bug, as there was a check after the ioremap().
> So possibly the bug was caused by ide itself.
>
> Fixes: 8cb1f567f4c0 ("ide: Platform IDE driver")
> Cc: stable@vger.kernel.org#5.10
Please keep the space before the #
Cc: stable@vger.kernel.org #5.10
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog
>
> v1 -> v2
>
> * Change 1. Correct the fixes tag and commit message.
>
> v2 -> v3
>
> * Change 1. Correct the code.
As commented before, what exactly was corrected ? That is what needs to be
mentioned here. In any case, I fail to see what code change you added between v2
and v3. The code changes are identical in the 2 versions.
> ---
> drivers/ide/ide_platform.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/ide/ide_platform.c b/drivers/ide/ide_platform.c
> index 91639fd6c276..5500c5afb3ca 100644
> --- a/drivers/ide/ide_platform.c
> +++ b/drivers/ide/ide_platform.c
> @@ -85,6 +85,10 @@ static int plat_ide_probe(struct platform_device *pdev)
> alt_base = devm_ioport_map(&pdev->dev,
> res_alt->start, resource_size(res_alt));
> }
> + if (!base || !alt_base) {
> + ret = -ENOMEM;
> + goto out;
> + }
>
> memset(&hw, 0, sizeof(hw));
> plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
Greg,
The above patch is OK but cannot be applied in the current kernel:
* The Legacy IDE drivers were removed in 5.14, replaced by the already existing
* The current equivalent libata driver (drivers/ata/pata_platform.c) already has
the above error check.
So I think this patch needs to go directly to stable # 5.10 and earlier LTS
kernels. Can you take it ?
Feel free to add:
Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Note that I was not the maintainer of the IDE drivers. If more appropriate
please feel free to replace that with a Reviewed-by tag.
Thanks !
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] ide: Check for null pointer after calling devm_ioremap
@ 2022-01-11 3:01 Jiasheng Jiang
0 siblings, 0 replies; 7+ messages in thread
From: Jiasheng Jiang @ 2022-01-11 3:01 UTC (permalink / raw)
To: damien.lemoal, David.Laight, davem, gregkh, stable, Naohiro.Aota
Cc: linux-ide, linux-kernel, Jiasheng Jiang
In linux-stable-5.15.13, this file has been removed and combined
to `drivers/ata/pata_platform.c` without this bug.
But in the older LTS kernels, like 5.10.90, this bug still exists.
As the possible failure of the devres_alloc(), the devm_ioremap() and
devm_ioport_map() may return NULL pointer.
And then, the 'base' and 'alt_base' are used in plat_ide_setup_ports().
Therefore, it should be better to add the check in order to avoid the
dereference of the NULL pointer.
Actually, it introduced the bug from commit 8cb1f567f4c0
("ide: Platform IDE driver") and we can know from the commit message
that it tended to be similar to the `drivers/ata/pata_platform.c`.
But actually, even the first time pata_platform was built,
commit a20c9e820864 ("[PATCH] ata: Generic platform_device libata driver"),
there was no the bug, as there was a check after the ioremap().
So possibly the bug was caused by ide itself.
Fixes: 8cb1f567f4c0 ("ide: Platform IDE driver")
Cc: stable@vger.kernel.org # 5.10
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog
v1 -> v2
* Change 1. Correct the fixes tag and commit message.
v2 -> v3
* Change 1. Correct the code.
---
drivers/ide/ide_platform.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ide/ide_platform.c b/drivers/ide/ide_platform.c
index 91639fd6c276..5500c5afb3ca 100644
--- a/drivers/ide/ide_platform.c
+++ b/drivers/ide/ide_platform.c
@@ -85,6 +85,10 @@ static int plat_ide_probe(struct platform_device *pdev)
alt_base = devm_ioport_map(&pdev->dev,
res_alt->start, resource_size(res_alt));
}
+ if (!base || !alt_base) {
+ ret = -ENOMEM;
+ goto out;
+ }
memset(&hw, 0, sizeof(hw));
plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] ide: Check for null pointer after calling devm_ioremap
2022-01-09 14:01 Jiasheng Jiang
@ 2022-01-11 2:23 ` Naohiro Aota
0 siblings, 0 replies; 7+ messages in thread
From: Naohiro Aota @ 2022-01-11 2:23 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: damien.lemoal, David.Laight, davem, gregkh, stable, linux-ide,
linux-kernel
On Sun, Jan 09, 2022 at 10:01:42PM +0800, Jiasheng Jiang wrote:
> On Sun, Jan 09, 2022 at 04:53:39PM +0800, Damien Le Moal wrote:
> >>>> Cc: stable@vger.kernel.org#5.10
> >>>
> >>> Please keep the space before the #
> >>>
> >>> Cc: stable@vger.kernel.org #5.10
> >>
> >> Actually, I added the space before, but the when I use the tool
> >> 'scripts/checkpatch.pl' to check my format, it told me a warning
> >> that it should not have space.
> >>
> >> The warning is as follow:
> >> WARNING: email address 'stable@vger.kernel.org #5.10' might be
> >> better as 'stable@vger.kernel.org#5.10'
> >
> > Cc: stable@vger.kernel.org # 5.10
> >
> > Should work.
>
> I used 'scripts/checkpatch.pl' to check it, giving me the warning again.
>
> The warning is as follow:
> WARNING: email address 'stable@vger.kernel.org # 5.10' might be better as
> 'stable@vger.kernel.org# 5.10'
>
> And if I use the 'stable@vger.kernel.org# 5.10', warning too.
>
> The warning is as follow:
> WARNING: email address 'stable@vger.kernel.org# 5.10' might be better as
> 'stable@vger.kernel.org#5.10'
>
> It seems that the only non-warning format is 'stable@vger.kernel.org#5.10'.
>
> Sincerely thanks,
> Jiang
>
The checkpatch.pl in 5.10.90 fails to parse the line as shown
above. That is fixed in commit fccaebf00e60 ("checkpatch: improve
email parsing") in the current tree.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] ide: Check for null pointer after calling devm_ioremap
2022-01-08 3:55 Jiasheng Jiang
@ 2022-01-09 8:53 ` Damien Le Moal
0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2022-01-09 8:53 UTC (permalink / raw)
To: Jiasheng Jiang, David.Laight, davem, gregkh, stable
Cc: linux-ide, linux-kernel
On 2022/01/08 12:55, Jiasheng Jiang wrote:
> On Sat, Jan 08, 2022 at 10:53:42PM +0800, Damien Le Moal wrote:
>>> Cc: stable@vger.kernel.org#5.10
>>
>> Please keep the space before the #
>>
>> Cc: stable@vger.kernel.org #5.10
>
> Actually, I added the space before, but the when I use the tool
> 'scripts/checkpatch.pl' to check my format, it told me a warning
> that it should not have space.
>
> The warning is as follow:
> WARNING: email address 'stable@vger.kernel.org #5.10' might be
> better as 'stable@vger.kernel.org#5.10'
>
> So I have no idea what is correct.
> Is the tool outdated?
> If so, I will correct my cc and please update the tool.
>
>> As commented before, what exactly was corrected ? That is what needs to be
>> mentioned here. In any case, I fail to see what code change you added between v2
>> and v3. The code changes are identical in the 2 versions.
>
> Thanks, I will make the changelog more clear.
> In fact, in the v2 I was careless to write '!!alt_base'.
> So I removed the redundant '!' in v3.
>
> Please tell me the right cc format, and then I will submit a new v3,
> without the problems above.
Cc: stable@vger.kernel.org # 5.10
Should work.
>
> Sincerely thanks,
> Jiang
>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] ide: Check for null pointer after calling devm_ioremap
2022-01-07 11:50 Jiasheng Jiang
@ 2022-01-07 12:07 ` Damien Le Moal
0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2022-01-07 12:07 UTC (permalink / raw)
To: Jiasheng Jiang, David.Laight, davem; +Cc: linux-ide, linux-kernel
On 1/7/22 20:50, Jiasheng Jiang wrote:
> In linux-stable-5.15.13, this file has been removed and combined
> to `drivers/ata/pata_platform.c` without this bug.
> But in the older LTS kernels, like 5.10.90, this bug still exists.
> As the possible failure of the devres_alloc(), the devm_ioremap() and
> devm_ioport_map() may return NULL pointer.
> And then, the 'base' and 'alt_base' are used in plat_ide_setup_ports().
> Therefore, it should be better to add the check in order to avoid the
> dereference of the NULL pointer.
> Actually, it introduced the bug from commit 8cb1f567f4c0
> ("ide: Platform IDE driver") and we can know from the commit message
> that it tended to be similar to the `drivers/ata/pata_platform.c`.
> But actually, even the first time pata_platform was built,
> commit a20c9e820864 ("[PATCH] ata: Generic platform_device libata driver"),
> there was no the bug, as there was a check after the ioremap().
> So possibly the bug was caused by ide itself.
>
> Fixes: 8cb1f567f4c0 ("ide: Platform IDE driver")
> Cc: stable@vger.kernel.org#5.10.90
This should be:
Cc: stable@vger.kernel.org #5.10
(no release number specified)
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog
>
> v2 -> v3
>
> * Change 1. Correct the fixes tag and commit message.
> * Change 2. Correct the code.
What exactly was corrected should be the change log.
And please keep the history for all versions of the patch (keep v1 -> v2
changes listed here).
> ---
> drivers/ide/ide_platform.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/ide/ide_platform.c b/drivers/ide/ide_platform.c
> index 91639fd6c276..5500c5afb3ca 100644
> --- a/drivers/ide/ide_platform.c
> +++ b/drivers/ide/ide_platform.c
> @@ -85,6 +85,10 @@ static int plat_ide_probe(struct platform_device *pdev)
> alt_base = devm_ioport_map(&pdev->dev,
> res_alt->start, resource_size(res_alt));
> }
> + if (!base || !alt_base) {
> + ret = -ENOMEM;
> + goto out;
> + }
>
> memset(&hw, 0, sizeof(hw));
> plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] ide: Check for null pointer after calling devm_ioremap
@ 2022-01-07 11:50 Jiasheng Jiang
2022-01-07 12:07 ` Damien Le Moal
0 siblings, 1 reply; 7+ messages in thread
From: Jiasheng Jiang @ 2022-01-07 11:50 UTC (permalink / raw)
To: David.Laight, damien.lemoal, davem
Cc: linux-ide, linux-kernel, stable, Jiasheng Jiang
In linux-stable-5.15.13, this file has been removed and combined
to `drivers/ata/pata_platform.c` without this bug.
But in the older LTS kernels, like 5.10.90, this bug still exists.
As the possible failure of the devres_alloc(), the devm_ioremap() and
devm_ioport_map() may return NULL pointer.
And then, the 'base' and 'alt_base' are used in plat_ide_setup_ports().
Therefore, it should be better to add the check in order to avoid the
dereference of the NULL pointer.
Actually, it introduced the bug from commit 8cb1f567f4c0
("ide: Platform IDE driver") and we can know from the commit message
that it tended to be similar to the `drivers/ata/pata_platform.c`.
But actually, even the first time pata_platform was built,
commit a20c9e820864 ("[PATCH] ata: Generic platform_device libata driver"),
there was no the bug, as there was a check after the ioremap().
So possibly the bug was caused by ide itself.
Fixes: 8cb1f567f4c0 ("ide: Platform IDE driver")
Cc: stable@vger.kernel.org#5.10.90
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog
v2 -> v3
* Change 1. Correct the fixes tag and commit message.
* Change 2. Correct the code.
---
drivers/ide/ide_platform.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ide/ide_platform.c b/drivers/ide/ide_platform.c
index 91639fd6c276..5500c5afb3ca 100644
--- a/drivers/ide/ide_platform.c
+++ b/drivers/ide/ide_platform.c
@@ -85,6 +85,10 @@ static int plat_ide_probe(struct platform_device *pdev)
alt_base = devm_ioport_map(&pdev->dev,
res_alt->start, resource_size(res_alt));
}
+ if (!base || !alt_base) {
+ ret = -ENOMEM;
+ goto out;
+ }
memset(&hw, 0, sizeof(hw));
plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-01-11 3:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 12:53 [PATCH v3] ide: Check for null pointer after calling devm_ioremap Jiasheng Jiang
2022-01-08 2:53 ` Damien Le Moal
-- strict thread matches above, loose matches on Subject: below --
2022-01-11 3:01 Jiasheng Jiang
2022-01-09 14:01 Jiasheng Jiang
2022-01-11 2:23 ` Naohiro Aota
2022-01-08 3:55 Jiasheng Jiang
2022-01-09 8:53 ` Damien Le Moal
2022-01-07 11:50 Jiasheng Jiang
2022-01-07 12:07 ` 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;
as well as URLs for NNTP newsgroup(s).