return NOTIFY_DONE;
 }
 
+static int
+dsa_master_prechangeupper_sanity_check(struct net_device *master,
+                                      struct netdev_notifier_changeupper_info *info)
+{
+       struct netlink_ext_ack *extack;
+
+       if (!netdev_uses_dsa(master))
+               return NOTIFY_DONE;
+
+       if (!info->linking)
+               return NOTIFY_DONE;
+
+       /* Allow DSA switch uppers */
+       if (dsa_slave_dev_check(info->upper_dev))
+               return NOTIFY_DONE;
+
+       /* Allow bridge uppers of DSA masters, subject to further
+        * restrictions in dsa_bridge_prechangelower_sanity_check()
+        */
+       if (netif_is_bridge_master(info->upper_dev))
+               return NOTIFY_DONE;
+
+       extack = netdev_notifier_info_to_extack(&info->info);
+
+       NL_SET_ERR_MSG_MOD(extack,
+                          "DSA master cannot join unknown upper interfaces");
+       return notifier_from_errno(-EBUSY);
+}
+
 /* Don't allow bridging of DSA masters, since the bridge layer rx_handler
  * prevents the DSA fake ethertype handler to be invoked, so we don't get the
  * chance to strip off and parse the DSA switch tag protocol header (the bridge
                if (notifier_to_errno(err))
                        return err;
 
+               err = dsa_master_prechangeupper_sanity_check(dev, info);
+               if (notifier_to_errno(err))
+                       return err;
+
                err = dsa_bridge_prechangelower_sanity_check(dev, info);
                if (notifier_to_errno(err))
                        return err;