scsi: libsas: Remove an empty branch in sas_check_parent_topology()
authorJason Yan <yanaijie@huawei.com>
Fri, 21 Apr 2023 09:37:43 +0000 (17:37 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 8 May 2023 11:16:18 +0000 (07:16 -0400)
There is an empty "all good" branch in sas_check_parent_topology(). We can
reverse the test statement and remove the empty branch.

Moreover, factor out a helper sas_check_edge_expander_topo() to make the
code more readable.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Link: https://lore.kernel.org/r/20230421093744.1583609-3-yanaijie@huawei.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/libsas/sas_expander.c

index e6101a5..1b4eb01 100644 (file)
@@ -1240,6 +1240,37 @@ static int sas_check_eeds(struct domain_device *child,
        return res;
 }
 
+static int sas_check_edge_expander_topo(struct domain_device *child,
+                                       struct ex_phy *parent_phy)
+{
+       struct expander_device *child_ex = &child->ex_dev;
+       struct expander_device *parent_ex = &child->parent->ex_dev;
+       struct ex_phy *child_phy;
+
+       child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
+
+       if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) {
+               if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING ||
+                   child_phy->routing_attr != TABLE_ROUTING)
+                       goto error;
+       } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) {
+               if (child_phy->routing_attr == SUBTRACTIVE_ROUTING)
+                       return sas_check_eeds(child, parent_phy, child_phy);
+               else if (child_phy->routing_attr != TABLE_ROUTING)
+                       goto error;
+       } else if (parent_phy->routing_attr == TABLE_ROUTING) {
+               if (child_phy->routing_attr != SUBTRACTIVE_ROUTING &&
+                   (child_phy->routing_attr != TABLE_ROUTING ||
+                    !child_ex->t2t_supp || !parent_ex->t2t_supp))
+                       goto error;
+       }
+
+       return 0;
+error:
+       sas_print_parent_topology_bug(child, parent_phy, child_phy);
+       return -ENODEV;
+}
+
 /* Here we spill over 80 columns.  It is intentional.
  */
 static int sas_check_parent_topology(struct domain_device *child)
@@ -1272,29 +1303,8 @@ static int sas_check_parent_topology(struct domain_device *child)
 
                switch (child->parent->dev_type) {
                case SAS_EDGE_EXPANDER_DEVICE:
-                       if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) {
-                               if (parent_phy->routing_attr != SUBTRACTIVE_ROUTING ||
-                                   child_phy->routing_attr != TABLE_ROUTING) {
-                                       sas_print_parent_topology_bug(child, parent_phy, child_phy);
-                                       res = -ENODEV;
-                               }
-                       } else if (parent_phy->routing_attr == SUBTRACTIVE_ROUTING) {
-                               if (child_phy->routing_attr == SUBTRACTIVE_ROUTING) {
-                                       res = sas_check_eeds(child, parent_phy, child_phy);
-                               } else if (child_phy->routing_attr != TABLE_ROUTING) {
-                                       sas_print_parent_topology_bug(child, parent_phy, child_phy);
-                                       res = -ENODEV;
-                               }
-                       } else if (parent_phy->routing_attr == TABLE_ROUTING) {
-                               if (child_phy->routing_attr == SUBTRACTIVE_ROUTING ||
-                                   (child_phy->routing_attr == TABLE_ROUTING &&
-                                    child_ex->t2t_supp && parent_ex->t2t_supp)) {
-                                       /* All good */;
-                               } else {
-                                       sas_print_parent_topology_bug(child, parent_phy, child_phy);
-                                       res = -ENODEV;
-                               }
-                       }
+                       if (sas_check_edge_expander_topo(child, parent_phy))
+                               res = -ENODEV;
                        break;
                case SAS_FANOUT_EXPANDER_DEVICE:
                        if (parent_phy->routing_attr != TABLE_ROUTING ||