]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
thunderbolt: Drop duplicated get_switch_at_route()
authorMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 15 Mar 2019 12:56:21 +0000 (14:56 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 15:37:40 +0000 (17:37 +0200)
[ Upstream commit 8f965efd215a09c20b0b5e5bb4e20009a954472e ]

tb_switch_find_by_route() does the same already so use it instead and
remove duplicated get_switch_at_route().

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/thunderbolt/icm.c
drivers/thunderbolt/switch.c
drivers/thunderbolt/tb.c
drivers/thunderbolt/tb.h

index 8490a1b6b61564320768012605f4837c77cf0663..2b83d8b02f8186d416be45e5e28ef1a3026559e4 100644 (file)
@@ -801,9 +801,11 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
         * connected another host to the same port, remove the switch
         * first.
         */
-       sw = get_switch_at_route(tb->root_switch, route);
-       if (sw)
+       sw = tb_switch_find_by_route(tb, route);
+       if (sw) {
                remove_switch(sw);
+               tb_switch_put(sw);
+       }
 
        sw = tb_switch_find_by_link_depth(tb, link, depth);
        if (!sw) {
@@ -1146,9 +1148,11 @@ icm_tr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
         * connected another host to the same port, remove the switch
         * first.
         */
-       sw = get_switch_at_route(tb->root_switch, route);
-       if (sw)
+       sw = tb_switch_find_by_route(tb, route);
+       if (sw) {
                remove_switch(sw);
+               tb_switch_put(sw);
+       }
 
        sw = tb_switch_find_by_route(tb, get_parent_route(route));
        if (!sw) {
index 42d90ceec2794496e71de589a5cb0475b43e7d30..010a50ac4881cebb3ed031803600ca6105fd9bc3 100644 (file)
@@ -664,24 +664,6 @@ int tb_switch_reset(struct tb *tb, u64 route)
        return res.err;
 }
 
-struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route)
-{
-       u8 next_port = route; /*
-                              * Routes use a stride of 8 bits,
-                              * eventhough a port index has 6 bits at most.
-                              * */
-       if (route == 0)
-               return sw;
-       if (next_port > sw->config.max_port_number)
-               return NULL;
-       if (tb_is_upstream_port(&sw->ports[next_port]))
-               return NULL;
-       if (!sw->ports[next_port].remote)
-               return NULL;
-       return get_switch_at_route(sw->ports[next_port].remote->sw,
-                                  route >> TB_ROUTE_SHIFT);
-}
-
 /**
  * tb_plug_events_active() - enable/disable plug events on a switch
  *
index 1424581fd9af5cb283b3ffd2fce3d4ac55e13d22..146f261bf2c33b92c1420a46e5de480a8313fd5f 100644 (file)
@@ -258,7 +258,7 @@ static void tb_handle_hotplug(struct work_struct *work)
        if (!tcm->hotplug_active)
                goto out; /* during init, suspend or shutdown */
 
-       sw = get_switch_at_route(tb->root_switch, ev->route);
+       sw = tb_switch_find_by_route(tb, ev->route);
        if (!sw) {
                tb_warn(tb,
                        "hotplug event from non existent switch %llx:%x (unplug: %d)\n",
@@ -269,14 +269,14 @@ static void tb_handle_hotplug(struct work_struct *work)
                tb_warn(tb,
                        "hotplug event from non existent port %llx:%x (unplug: %d)\n",
                        ev->route, ev->port, ev->unplug);
-               goto out;
+               goto put_sw;
        }
        port = &sw->ports[ev->port];
        if (tb_is_upstream_port(port)) {
                tb_warn(tb,
                        "hotplug event for upstream port %llx:%x (unplug: %d)\n",
                        ev->route, ev->port, ev->unplug);
-               goto out;
+               goto put_sw;
        }
        if (ev->unplug) {
                if (port->remote) {
@@ -306,6 +306,9 @@ static void tb_handle_hotplug(struct work_struct *work)
                        tb_activate_pcie_devices(tb);
                }
        }
+
+put_sw:
+       tb_switch_put(sw);
 out:
        mutex_unlock(&tb->lock);
        kfree(ev);
index 7a0ee9836a8a76a023d50241ea012fb2b6a6f54d..d927cf7b14d2e56f48466a5fed81f5f12e478d17 100644 (file)
@@ -397,7 +397,6 @@ void tb_switch_suspend(struct tb_switch *sw);
 int tb_switch_resume(struct tb_switch *sw);
 int tb_switch_reset(struct tb *tb, u64 route);
 void tb_sw_set_unplugged(struct tb_switch *sw);
-struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route);
 struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,
                                               u8 depth);
 struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid);