From: Florian Fainelli <f.fainelli@gmail.com>
To: Xu Wang <vulab@iscas.ac.cn>,
davem@davemloft.net, kuba@kernel.org, michal.simek@xilinx.com,
esben@geanix.com, hkallweit1@gmail.com, weiyongjun1@huawei.com,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: xilinx: fix potential NULL dereference in temac_probe()
Date: Mon, 13 Jul 2020 19:55:32 -0700 [thread overview]
Message-ID: <683a0713-2587-17e4-6280-b2f905b3a230@gmail.com> (raw)
In-Reply-To: <20200714022304.4003-1-vulab@iscas.ac.cn>
On 7/13/2020 7:23 PM, Xu Wang wrote:
> platform_get_resource() may return NULL, add proper
> check to avoid potential NULL dereferencing.
>
> Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
> ---
If you use devm_ioremap_resource() you can remove the !res check
entirely which would be equally acceptable as a fix.
> drivers/net/ethernet/xilinx/ll_temac_main.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
> index 929244064abd..85a767fa2ecf 100644
> --- a/drivers/net/ethernet/xilinx/ll_temac_main.c
> +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
> @@ -1408,6 +1408,8 @@ static int temac_probe(struct platform_device *pdev)
>
> /* map device registers */
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res)
> + return -EINVAL;
> lp->regs = devm_ioremap(&pdev->dev, res->start,
> resource_size(res));
> if (!lp->regs) {
> @@ -1503,6 +1505,8 @@ static int temac_probe(struct platform_device *pdev)
> } else if (pdata) {
> /* 2nd memory resource specifies DMA registers */
> res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + if (!res)
> + return -EINVAL;
> lp->sdma_regs = devm_ioremap(&pdev->dev, res->start,
> resource_size(res));
> if (!lp->sdma_regs) {
>
--
Florian
next prev parent reply other threads:[~2020-07-14 2:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 2:23 [PATCH] net: xilinx: fix potential NULL dereference in temac_probe() Xu Wang
2020-07-14 2:55 ` Florian Fainelli [this message]
2020-07-14 9:42 Markus Elfring
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=683a0713-2587-17e4-6280-b2f905b3a230@gmail.com \
--to=f.fainelli@gmail.com \
--cc=davem@davemloft.net \
--cc=esben@geanix.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@xilinx.com \
--cc=netdev@vger.kernel.org \
--cc=vulab@iscas.ac.cn \
--cc=weiyongjun1@huawei.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).