diff mbox series

[RFC,net-next,09/13] net: dsa: mroute: don't panic the kernel if called without the prepare phase

Message ID 20200521211036.668624-10-olteanv@gmail.com
State RFC
Delegated to: David Miller
Headers show
Series RX filtering for DSA switches | expand

Commit Message

Vladimir Oltean May 21, 2020, 9:10 p.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

Currently, this function would check the port_egress_floods pointer only
in the preparation phase, the assumption being that the caller wouldn't
proceed to a second call since it returned -EOPNOTSUPP. If the function
were to be called a second time though, the port_egress_floods pointer
would not be checked and the driver would proceed to dereference it.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/port.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/dsa/port.c b/net/dsa/port.c
index e23ece229c7e..c4032f79225a 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -324,8 +324,11 @@  int dsa_port_mrouter(struct dsa_port *dp, bool mrouter,
 	struct dsa_switch *ds = dp->ds;
 	int port = dp->index;
 
+	if (!ds->ops->port_egress_floods)
+		return -EOPNOTSUPP;
+
 	if (switchdev_trans_ph_prepare(trans))
-		return ds->ops->port_egress_floods ? 0 : -EOPNOTSUPP;
+		return 0;
 
 	return ds->ops->port_egress_floods(ds, port, true, mrouter);
 }