From: Jakub Kicinski <kuba@kernel.org>
To: xkernel.wang@foxmail.com
Cc: davem@davemloft.net, michal.simek@xilinx.com,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: ll_temac: check the return value of devm_kmalloc()
Date: Thu, 17 Feb 2022 08:52:02 -0800 [thread overview]
Message-ID: <20220217085202.00173453@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <tencent_A528B1FF77813031ABE6C6738453F084570A@qq.com>
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);
> }
>
prev parent reply other threads:[~2022-02-17 16:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220217085202.00173453@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@xilinx.com \
--cc=netdev@vger.kernel.org \
--cc=xkernel.wang@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).