net: systemport: Add error pointer checks in bcm_sysport_map_queues() and bcm_sysport_unmap_queues()
Subsystems (3)
PATCH v5 1/1 net: systemport: Add error pointer checks in bcm_sysport_map_queues() and bcm_sysport_unmap_queues()
Add error pointer checks in bcm_sysport_map_queues() and bcm_sysport_unmap_queues() after calling dsa_port_from_netdev().
---
v5:
-Removed extra parentheses
v4: https://lore.kernel.org/all/[email protected]/
- Removed wrong and used correct Fixes: tag
v3: https://lore.kernel.org/all/[email protected]/
- Updated patch subject
- Updated patch description
- Added Fixes: tags
- Fixed typo from PRT_ERR to PTR_ERR
- Error is checked just after assignment
v2: https://lore.kernel.org/all/[email protected]/
- Change the subject of the patch to net
v1: https://lore.kernel.org/all/[email protected]/
drivers/net/ethernet/broadcom/bcmsysport.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bcmsysport.c +10 -2
@@ -2331,11 +2331,15 @@ static const struct net_device_ops bcm_sysport_netdev_ops = {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);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + dp =dsa_port_from_netdev (slave_dev); +if (IS_ERR (dp)) +return PTR_ERR (dp);/* We can't be setting up queue inspection for non directly attached * switches
@@ -2386,11 +2390,15 @@ static int bcm_sysport_map_queues(struct net_device *dev,static int bcm_sysport_unmap_queues (struct net_device *dev,struct net_device *slave_dev) { -struct dsa_port *dp =dsa_port_from_netdev (slave_dev);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + dp =dsa_port_from_netdev (slave_dev); +if (IS_ERR (dp)) +return PTR_ERR (dp); port = dp->index;
Signature · 1 line
2.43.0
+ Vladimir
Quoted 5 lines · Dipendra Khadka
Add error pointer checks in
bcm_sysport_map_queues()andbcm_sysport_unmap_queues()after callingdsa_port_from_netdev().Fixes 1593cd40d785 ("net: systemport: use standard netdevice notifier to detect DSA presence")Signed-off-by Dipendra Khadka <[email protected]>
Quoted 58 lines
---
v5:
-Removed extra parentheses
v4: https://lore.kernel.org/all/[email protected]/
- Removed wrong and used correct Fixes: tag
v3: https://lore.kernel.org/all/[email protected]/
- Updated patch subject
- Updated patch description
- Added Fixes: tags
- Fixed typo fromPRT_ERRtoPTR_ERR
- Error is checked just after assignment
v2: https://lore.kernel.org/all/[email protected]/
- Change the subject of the patch to net
v1: https://lore.kernel.org/all/[email protected]/drivers/net/ethernet/broadcom/bcmsysport.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ethernet/broadcom/bcmsysport.c +10
-2@@ -2331,11 +2331,15 @@ static const struct net_device_ops bcm_sysport_netdev_ops = {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);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + dp =dsa_port_from_netdev (slave_dev); +if (IS_ERR (dp)) +return PTR_ERR (dp);/* We can't be setting up queue inspection for non directly attached * switches @@ -2386,11 +2390,15 @@ static int bcm_sysport_map_queues(struct net_device *dev,static int bcm_sysport_unmap_queues (struct net_device *dev,struct net_device *slave_dev) { -struct dsa_port *dp =dsa_port_from_netdev (slave_dev);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + dp =dsa_port_from_netdev (slave_dev); +if (IS_ERR (dp)) +return PTR_ERR (dp); port = dp->index;Signature · 1 line
2.43.0
Quoted 1 line · Simon Horman
+ Vladimir
Thanks for adding me, Simon.
Quoted 45 lines · Dipendra Khadka
Quoted 5 lines
Add error pointer checks in
bcm_sysport_map_queues()andbcm_sysport_unmap_queues()after callingdsa_port_from_netdev().Fixes 1593cd40d785 ("net: systemport: use standard netdevice notifier to detect DSA presence")Signed-off-by Dipendra Khadka <[email protected]>Reviewed-by Simon Horman <[email protected]>Quoted 36 lines
---
v5:
-Removed extra parentheses
v4: https://lore.kernel.org/all/[email protected]/
- Removed wrong and used correct Fixes: tag
v3: https://lore.kernel.org/all/[email protected]/
- Updated patch subject
- Updated patch description
- Added Fixes: tags
- Fixed typo fromPRT_ERRtoPTR_ERR
- Error is checked just after assignment
v2: https://lore.kernel.org/all/[email protected]/
- Change the subject of the patch to net
v1: https://lore.kernel.org/all/[email protected]/drivers/net/ethernet/broadcom/bcmsysport.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/ethernet/broadcom/bcmsysport.c +5
-1@@ -2331,11 +2331,15 @@ static const struct net_device_ops bcm_sysport_netdev_ops = {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);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + dp =dsa_port_from_netdev (slave_dev); +if (IS_ERR (dp)) +return PTR_ERR (dp);
Quoted 16 lines
Quoted 6 lines
drivers/net/ethernet/broadcom/bcmsysport.c +0
-0/* We can't be setting up queue inspection for non directly attached * switches @@ -2386,11 +2390,15 @@ static int bcm_sysport_map_queues(struct net_device *dev,static int bcm_sysport_unmap_queues (struct net_device *dev,struct net_device *slave_dev) {drivers/net/ethernet/broadcom/bcmsysport.c static int bcm_sysport_map_queues(struct net_device *dev, · line 2401
Quoted 10 lines
drivers/net/ethernet/broadcom/bcmsysport.c +5
-1-struct dsa_port *dp =dsa_port_from_netdev (slave_dev);struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring;unsigned int num_tx_queues;unsigned int q, qp, port; +struct dsa_port *dp; + + 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?
Quoted 7 lines · Vladimir Oltean
Quoted 3 lines
drivers/net/ethernet/broadcom/bcmsysport.c static const struct net_device_ops bcm_sysport_netdev_ops = { · line 2342
Quoted 3 lines
drivers/net/ethernet/broadcom/bcmsysport.c +3
-0+ 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?!
Hi Vladimir,
Quoted 10 lines · Vladimir Oltean
Quoted 7 lines · Vladimir Oltean
Quoted 3 lines
Quoted 3 lines
+ dp =
dsa_port_from_netdev(slave_dev);
+ if (IS_ERR(dp))
+ returnPTR_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?
Yeah, you are right. I ran smatch to find this and saw there is no validation. I did not see any problem as you said. I thought it would be better to include this change. If you say there is no point for this change, then that's also fine for me. I got the chance to learn new things.
Quoted 54 lines
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(structnet_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,
structnet_device*slave_dev){ struct dsa_port *dp = dsa_port_from_netdev(slave_dev); ... }So, if both conditions for
dsa_port_from_netdev()to returnERR_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?
Quoted 4 lines
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?!
Sorry to know this, I ran the script and there I did not find your name.
./scripts/get_maintainer.pl drivers/net/ethernet/broadcom/bcmsysport.c Florian Fainelli <[email protected]> (supporter:BROADCOM SYSTEMPORT ETHERNET DRIVER)
Broadcom internal kernel review list <[email protected]> (reviewer:BROADCOM SYSTEMPORT ETHERNET DRIVER)
"David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:BROADCOM SYSTEMPORT ETHERNET DRIVER) [email protected] (open list)
Thank you so much for your time and effort , special thanks to Simon for everything ,thanks Vladimir for the way you explained. and thanks Florian for your help.
Best regards,
Dipendra Khadka
Quoted 4 lines · Dipendra Khadka
Quoted 1 line
And why is the author of the blamed patch even CCed only at v5?!
Sorry to know this, I ran the script and there I did not find your name.
Quoted 9 lines
./scripts/get_maintainer.pldrivers/net/ethernet/broadcom/bcmsysport.c
Florian Fainelli <[email protected]> (supporter:BROADCOM SYSTEMPORT ETHERNET DRIVER) Broadcom internal kernel review list <[email protected]> (reviewer:BROADCOM SYSTEMPORT ETHERNET DRIVER) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS)
Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS)
Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS)
Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS)
[email protected] (open list:BROADCOM SYSTEMPORT ETHERNET DRIVER)
[email protected] (open list)
It's in the question you ask. Am I a maintainer of bcmsysport? No, and I haven't made significant contributions on it either. But if you run get_maintainer.pl on the _patch_ file that you will run through git send-email, my name will be listed (the "--fixes" option defaults to 1).
The netdev CI also runs get_maintainers.pl on the actual patch, and that triggers one of its red flags: "1 blamed authors not CCed: [email protected]"
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Hi,
Quoted 16 lines · Vladimir Oltean
Quoted 4 lines · Dipendra Khadka
Quoted 1 line
And why is the author of the blamed patch even CCed only at v5?!
Sorry to know this, I ran the script and there I did not find your name.
Quoted 9 lines
./scripts/get_maintainer.pldrivers/net/ethernet/broadcom/bcmsysport.c
Florian Fainelli <[email protected]> (supporter:BROADCOM SYSTEMPORT ETHERNET DRIVER) Broadcom internal kernel review list <[email protected]> (reviewer:BROADCOM SYSTEMPORT ETHERNET DRIVER) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS)
Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS)
Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS)
Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS)
[email protected] (open list:BROADCOM SYSTEMPORT ETHERNET DRIVER)
[email protected] (open list)
Quoted 5 lines
It's in the question you ask. Am I a maintainer of bcmsysport? No, and I haven't made significant contributions on it either. But if you run get_maintainer.pl on the _patch_ file that you will run through git send-email, my name will be listed (the "--fixes" option defaults to 1).
Oh, thank you for this. I only used to run get_maintainers.pl on the file which got changed. I will run on the patch file as well from now.
Quoted 3 lines
The netdev CI also runs get_maintainers.pl on the actual patch, and that triggers one of its red flags: "1 blamed authors not CCed: [email protected]"
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Best regards,
Dipendra Khadka