* [PATCH] net: ll_temac: check the return value of devm_kmalloc()
@ 2022-02-16 10:46 xkernel.wang
2022-02-17 16:52 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-02-16 10:46 UTC (permalink / raw)
To: davem, kuba
Cc: michal.simek, netdev, linux-arm-kernel, linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
devm_kmalloc() returns a pointer to allocated memory on success, NULL
on failure. While lp->indirect_lock is allocated by devm_kmalloc()
without proper check. It is better to check the value of it to
prevent potential wrong memory access.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
drivers/net/ethernet/xilinx/ll_temac_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 463094c..7c5dd39 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -1427,6 +1427,11 @@ static int temac_probe(struct platform_device *pdev)
lp->indirect_lock = devm_kmalloc(&pdev->dev,
sizeof(*lp->indirect_lock),
GFP_KERNEL);
+ if (!lp->indirect_lock) {
+ dev_err(&pdev->dev,
+ "indirect register lock allocation failed\n");
+ return -ENOMEM;
+ }
spin_lock_init(lp->indirect_lock);
}
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: ll_temac: check the return value of devm_kmalloc()
2022-02-16 10:46 [PATCH] net: ll_temac: check the return value of devm_kmalloc() xkernel.wang
@ 2022-02-17 16:52 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2022-02-17 16:52 UTC (permalink / raw)
To: xkernel.wang; +Cc: davem, michal.simek, netdev, linux-arm-kernel, linux-kernel
On Wed, 16 Feb 2022 18:46:42 +0800 xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> devm_kmalloc() returns a pointer to allocated memory on success, NULL
> on failure. While lp->indirect_lock is allocated by devm_kmalloc()
> without proper check. It is better to check the value of it to
> prevent potential wrong memory access.
>
Consider adding a Fixes tag, although I guess this is not a real bug
since tiny allocations don't really fail.
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> drivers/net/ethernet/xilinx/ll_temac_main.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
> index 463094c..7c5dd39 100644
> --- a/drivers/net/ethernet/xilinx/ll_temac_main.c
> +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
> @@ -1427,6 +1427,11 @@ static int temac_probe(struct platform_device *pdev)
> lp->indirect_lock = devm_kmalloc(&pdev->dev,
> sizeof(*lp->indirect_lock),
> GFP_KERNEL);
> + if (!lp->indirect_lock) {
> + dev_err(&pdev->dev,
> + "indirect register lock allocation failed\n");
There's no need for this message, kmalloc() will display an error
already.
> + return -ENOMEM;
> + }
> spin_lock_init(lp->indirect_lock);
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-17 16:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 10:46 [PATCH] net: ll_temac: check the return value of devm_kmalloc() xkernel.wang
2022-02-17 16:52 ` Jakub Kicinski
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).