Commit 423f7cf4 authored by Darrick J. Wong's avatar Darrick J. Wong Committed by James Bottomley
Browse files

[SCSI] libsas: Don't BUG when connecting two expanders via wide port

libsas: Don't BUG when connecting two expanders via wide port

When a device is connected to an expander, the discovery process goes through
sas_ex_discover_dev to figure out what's attached to the phy.  If it is the
case that the phy being discovered happens to be the second phy of a wide link
to an expander, that discover_dev function will incorrectly call
sas_ex_discover_expander, which creates another sas_port and tries to attach the
other sas_phys to the new port, thus triggering a BUG.  The correct thing to do is
to check the other ex_phys of the expander to see if there's a sas_port for this
sas_phy, and attach the sas_phy to the existing sas_port.

This is easily triggered if one enables the phys of a wide port between
expanders one by one.

This second version of the patch fixes a small regression in the case where
all the phys show up at once and we accidentally try to attach to a port
that hasn't been created yet.
Signed-off-by: default avatarDarrick J. Wong <>
Signed-off-by: default avatarJames Bottomley <>
parent 9abe16c6
......@@ -678,6 +678,29 @@ static struct domain_device *sas_ex_discover_end_dev(
return NULL;
/* See if this phy is part of a wide port */
static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
int i;
for (i = 0; i < parent->ex_dev.num_phys; i++) {
struct ex_phy *ephy = &parent->ex_dev.ex_phy[i];
if (ephy == phy)
if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr,
SAS_ADDR_SIZE) && ephy->port) {
sas_port_add_phy(ephy->port, phy->phy);
phy->phy_state = PHY_DEVICE_DISCOVERED;
return 0;
return -ENODEV;
static struct domain_device *sas_ex_discover_expander(
struct domain_device *parent, int phy_id)
......@@ -810,6 +833,13 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
return res;
res = sas_ex_join_wide_port(dev, phy_id);
if (!res) {
SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n",
phy_id, SAS_ADDR(ex_phy->attached_sas_addr));
return res;
switch (ex_phy->attached_dev_type) {
child = sas_ex_discover_end_dev(dev, phy_id);
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