From: Andrew Lunn <andrew@lunn.ch>
To: Hui Tang <tanghui20@huawei.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
mw@semihalf.com, linux@armlinux.org.uk, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
yusongping@huawei.com
Subject: Re: [PATCH net v2] net: mdio-ipq4019: fix possible invalid pointer dereference
Date: Thu, 17 Nov 2022 14:57:55 +0100 [thread overview]
Message-ID: <Y3Y94/My9Al4pw+h@lunn.ch> (raw)
In-Reply-To: <20221117090514.118296-1-tanghui20@huawei.com>
On Thu, Nov 17, 2022 at 05:05:14PM +0800, Hui Tang wrote:
> priv->eth_ldo_rdy is saved the return value of devm_ioremap_resource(),
> which !IS_ERR() should be used to check.
>
> Fixes: 23a890d493e3 ("net: mdio: Add the reset function for IPQ MDIO driver")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>
> ---
> v1 -> v2: set priv->eth_ldo_rdy NULL, if devm_ioremap_resource() failed
> ---
> drivers/net/mdio/mdio-ipq4019.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mdio/mdio-ipq4019.c b/drivers/net/mdio/mdio-ipq4019.c
> index 4eba5a91075c..dfd1647eac36 100644
> --- a/drivers/net/mdio/mdio-ipq4019.c
> +++ b/drivers/net/mdio/mdio-ipq4019.c
> @@ -231,8 +231,11 @@ static int ipq4019_mdio_probe(struct platform_device *pdev)
> /* The platform resource is provided on the chipset IPQ5018 */
> /* This resource is optional */
> res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> - if (res)
> + if (res) {
> priv->eth_ldo_rdy = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(priv->eth_ldo_rdy))
> + priv->eth_ldo_rdy = NULL;
> + }
As i said, please add devm_ioremap_resource_optional(). Follow the
concept of devm_clk_get_optional(), devm_gpiod_get_optional(),
devm_reset_control_get_optional(), devm_reset_control_get_optional(),
platform_get_irq_byname_optional() etc.
All these will not return an error if the resource you are trying to
get does not exist. They instead return NULL, or something which other
API members understand as does not exist, but thats O.K.
These functions however do return errors for real problem, ENOMEM,
EINVAL etc. These should not be ignored.
You should then use this new function for all your other patches where
the resource is optional.
Andrew
next prev parent reply other threads:[~2022-11-17 13:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 9:05 [PATCH net v2] net: mdio-ipq4019: fix possible invalid pointer dereference Hui Tang
2022-11-17 13:57 ` Andrew Lunn [this message]
2022-11-18 7:21 ` Hui Tang
2022-11-18 13:44 ` Andrew Lunn
2022-11-19 5:41 ` Hui Tang
2022-11-21 14:36 ` Andrew Lunn
2022-11-23 1:10 ` Hui Tang
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=Y3Y94/My9Al4pw+h@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mw@semihalf.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tanghui20@huawei.com \
--cc=yusongping@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).