Commit e0c755a4 authored by George McCollister's avatar George McCollister Committed by David S. Miller

net: dsa: don't assign an error value to tag_ops

Use a temporary variable to hold the return value from
dsa_tag_driver_get() instead of assigning it to dst->tag_ops. Leaving
an error value in dst->tag_ops can result in deferencing an invalid
pointer when a deferred switch configuration happens later.

Fixes: 357f203b ("net: dsa: keep a copy of the tagging protocol in the DSA switch tree")
Signed-off-by: default avatarGeorge McCollister <george.mccollister@gmail.com>
Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8fb16e80
...@@ -1066,6 +1066,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) ...@@ -1066,6 +1066,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
{ {
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
struct dsa_switch_tree *dst = ds->dst; struct dsa_switch_tree *dst = ds->dst;
const struct dsa_device_ops *tag_ops;
enum dsa_tag_protocol tag_protocol; enum dsa_tag_protocol tag_protocol;
tag_protocol = dsa_get_tag_protocol(dp, master); tag_protocol = dsa_get_tag_protocol(dp, master);
...@@ -1080,14 +1081,16 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) ...@@ -1080,14 +1081,16 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
* nothing to do here. * nothing to do here.
*/ */
} else { } else {
dst->tag_ops = dsa_tag_driver_get(tag_protocol); tag_ops = dsa_tag_driver_get(tag_protocol);
if (IS_ERR(dst->tag_ops)) { if (IS_ERR(tag_ops)) {
if (PTR_ERR(dst->tag_ops) == -ENOPROTOOPT) if (PTR_ERR(tag_ops) == -ENOPROTOOPT)
return -EPROBE_DEFER; return -EPROBE_DEFER;
dev_warn(ds->dev, "No tagger for this switch\n"); dev_warn(ds->dev, "No tagger for this switch\n");
dp->master = NULL; dp->master = NULL;
return PTR_ERR(dst->tag_ops); return PTR_ERR(tag_ops);
} }
dst->tag_ops = tag_ops;
} }
dp->master = master; dp->master = master;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment