From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Simon Horman <horms@kernel.org>
Cc: Dipendra Khadka <kdipendra88@gmail.com>,
florian.fainelli@broadcom.com,
bcm-kernel-feedback-list@broadcom.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
maxime.chevallier@bootlin.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5] net: systemport: Add error pointer checks in bcm_sysport_map_queues() and bcm_sysport_unmap_queues()
Date: Fri, 27 Sep 2024 15:00:37 +0300 [thread overview]
Message-ID: <20240927120037.ji2wlqeagwohlb5d@skbuf> (raw)
In-Reply-To: <20240927112958.46unqo3adnxin2in@skbuf>
On Fri, Sep 27, 2024 at 02:29:58PM +0300, Vladimir Oltean wrote:
> > > + dp = dsa_port_from_netdev(slave_dev);
> > > + if (IS_ERR(dp))
> > > + return PTR_ERR(dp);
>
> I don't see an explanation anywhere as for why dsa_port_from_netdev()
> could ever return a pointer-encoded error here? hmm? Did you follow the
> call path and found a problem?
To make my point even clearer. As the code goes:
bool dsa_user_dev_check(const struct net_device *dev)
{
// This dereferences "dev" without a NULL pointer check.
// If the kernel did not crash, it means that "dev" is not null.
return dev->netdev_ops == &dsa_user_netdev_ops;
}
static int bcm_sysport_netdevice_event(struct notifier_block *nb,
unsigned long event, void *ptr)
{
...
switch (event) {
case NETDEV_CHANGEUPPER:
...
if (!dsa_user_dev_check(info->upper_dev))
return NOTIFY_DONE;
// we know here that dsa_user_dev_check() is true, and
// no one changes dev->netdev_ops at runtime, to suspect
// it could become false after it just returned true.
// Even if it did, we are under rtnl_lock(), and whoever
// did that better also acquired rtnl_lock(). Thus,
// there is enough guarantee that this also remains true
// below.
if (info->linking)
ret = bcm_sysport_map_queues(dev, info->upper_dev);
else
ret = bcm_sysport_unmap_queues(dev, info->upper_dev);
}
...
}
struct dsa_port *dsa_port_from_netdev(struct net_device *netdev)
{
if (!netdev || !dsa_user_dev_check(netdev))
return ERR_PTR(-ENODEV);
return dsa_user_to_port(netdev);
}
static int bcm_sysport_map_queues(struct net_device *dev,
struct net_device *slave_dev)
{
struct dsa_port *dp = dsa_port_from_netdev(slave_dev);
...
}
So, if both conditions for dsa_port_from_netdev() to return ERR_PTR(-ENODEV)
can only be false, why would we add an error check? Is it to appease a
static analysis tool which doesn't analyze things very far? Or is there
an actual problem?
And why does this have a Fixes: tag and the expectation to be included
as a bug fix to stable kernels?
And why is the author of the blamed patch even CCed only at v5?!
next prev parent reply other threads:[~2024-09-27 12:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 16:05 [PATCH net v5] net: systemport: Add error pointer checks in bcm_sysport_map_queues() and bcm_sysport_unmap_queues() Dipendra Khadka
2024-09-27 11:02 ` Simon Horman
2024-09-27 11:29 ` Vladimir Oltean
2024-09-27 12:00 ` Vladimir Oltean [this message]
2024-09-30 18:07 ` Dipendra Khadka
2024-09-30 20:32 ` Vladimir Oltean
2024-10-01 4:37 ` Dipendra Khadka
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=20240927120037.ji2wlqeagwohlb5d@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=horms@kernel.org \
--cc=kdipendra88@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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