* [PATCH v2] tty/serial: Check for null pointer after calling devm_ioremap
@ 2022-01-07 14:48 Jiasheng Jiang
2022-01-13 7:35 ` Jiri Slaby
0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-07 14:48 UTC (permalink / raw)
To: gregkh; +Cc: jirislaby, linux-serial, linux-kernel, Jiasheng Jiang
As the possible failure of the devres_alloc(), the devm_ioremap()
may return NULL pointer.
And the 'port->membase' will be used in mlb_usio_startup() without the
check.
Therefore, in order to avoid the dereference of the NULL pointer, it
should be better to add the check to guarantee the success of the probe.
Fixes: ba44dc043004 ("serial: Add Milbeaut serial control")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog
v1 -> v2
* Change 1. Refine the commit message to be more clear.
---
drivers/tty/serial/milbeaut_usio.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/tty/serial/milbeaut_usio.c b/drivers/tty/serial/milbeaut_usio.c
index 8f2cab7f66ad..1ecbf6d0dc79 100644
--- a/drivers/tty/serial/milbeaut_usio.c
+++ b/drivers/tty/serial/milbeaut_usio.c
@@ -523,6 +523,10 @@ static int mlb_usio_probe(struct platform_device *pdev)
}
port->membase = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
+ if (!port->membase) {
+ ret = -ENOMEM;
+ goto failed;
+ }
ret = platform_get_irq_byname(pdev, "rx");
mlb_usio_irq[index][RX] = ret;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tty/serial: Check for null pointer after calling devm_ioremap
2022-01-07 14:48 [PATCH v2] tty/serial: Check for null pointer after calling devm_ioremap Jiasheng Jiang
@ 2022-01-13 7:35 ` Jiri Slaby
0 siblings, 0 replies; 2+ messages in thread
From: Jiri Slaby @ 2022-01-13 7:35 UTC (permalink / raw)
To: Jiasheng Jiang, gregkh; +Cc: linux-serial, linux-kernel
On 07. 01. 22, 15:48, Jiasheng Jiang wrote:
> As the possible failure of the devres_alloc(), the devm_ioremap()
> may return NULL pointer.
> And the 'port->membase' will be used in mlb_usio_startup() without the
> check.
> Therefore, in order to avoid the dereference of the NULL pointer, it
> should be better to add the check to guarantee the success of the probe.
>
> Fixes: ba44dc043004 ("serial: Add Milbeaut serial control")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog
>
> v1 -> v2
>
> * Change 1. Refine the commit message to be more clear.
> ---
> drivers/tty/serial/milbeaut_usio.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/tty/serial/milbeaut_usio.c b/drivers/tty/serial/milbeaut_usio.c
> index 8f2cab7f66ad..1ecbf6d0dc79 100644
> --- a/drivers/tty/serial/milbeaut_usio.c
> +++ b/drivers/tty/serial/milbeaut_usio.c
> @@ -523,6 +523,10 @@ static int mlb_usio_probe(struct platform_device *pdev)
> }
> port->membase = devm_ioremap(&pdev->dev, res->start,
> resource_size(res));
> + if (!port->membase) {
> + ret = -ENOMEM;
> + goto failed;
> + }
Hi,
what about using devm_ioremap_resource() and have only one if there?
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-13 7:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 14:48 [PATCH v2] tty/serial: Check for null pointer after calling devm_ioremap Jiasheng Jiang
2022-01-13 7:35 ` Jiri Slaby
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).