linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cleanup after a discovery error
@ 2006-10-19  3:19 malahal
  2006-10-19 19:08 ` James Bottomley
  0 siblings, 1 reply; 4+ messages in thread
From: malahal @ 2006-10-19  3:19 UTC (permalink / raw)
  To: linux-scsi

Domain device is freed but the port dev list is not adjusted on some
discovery errors. Module unload will Oops if this happens.

Signed-off-by: Malahal Naineni <malahal@us.ibm.com>

diff -r 4e1720b3c71b drivers/scsi/libsas/sas_discover.c
--- a/drivers/scsi/libsas/sas_discover.c	Thu Oct 05 10:02:13 2006 -0700
+++ b/drivers/scsi/libsas/sas_discover.c	Fri Oct 13 19:58:54 2006 -0700
@@ -684,7 +684,23 @@ static void sas_discover_domain(void *da
 	}
 
 	if (error) {
-		kfree(port->port_dev); /* not kobject_register-ed yet */
+		struct domain_device *dev = port->port_dev;
+		
+		if (dev->rphy) {
+			sas_remove_children(&dev->rphy->dev);
+			sas_rphy_delete(dev->rphy);
+			dev->rphy = NULL;
+		}
+		if (dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV) {
+			if (dev->ex_dev.ex_phy) {
+				kfree(dev->ex_dev.ex_phy);
+				dev->ex_dev.ex_phy = NULL;
+			}
+		}
+		spin_lock(&port->dev_list_lock);
+		list_del_init(&dev->dev_list_node);
+		spin_unlock(&port->dev_list_lock);
+		kfree(dev); /* not kobject_register-ed yet */
 		port->port_dev = NULL;
 	}
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cleanup after a discovery error
  2006-10-19  3:19 [PATCH] cleanup after a discovery error malahal
@ 2006-10-19 19:08 ` James Bottomley
  2006-10-30 20:23   ` malahal
  0 siblings, 1 reply; 4+ messages in thread
From: James Bottomley @ 2006-10-19 19:08 UTC (permalink / raw)
  To: malahal; +Cc: linux-scsi

On Wed, 2006-10-18 at 20:19 -0700, malahal@us.ibm.com wrote:
> Domain device is freed but the port dev list is not adjusted on some
> discovery errors. Module unload will Oops if this happens.
> 
> Signed-off-by: Malahal Naineni <malahal@us.ibm.com>
> 
> diff -r 4e1720b3c71b drivers/scsi/libsas/sas_discover.c
> --- a/drivers/scsi/libsas/sas_discover.c	Thu Oct 05 10:02:13 2006 -0700
> +++ b/drivers/scsi/libsas/sas_discover.c	Fri Oct 13 19:58:54 2006 -0700
> @@ -684,7 +684,23 @@ static void sas_discover_domain(void *da
>  	}
>  
>  	if (error) {
> -		kfree(port->port_dev); /* not kobject_register-ed yet */
> +		struct domain_device *dev = port->port_dev;
> +		
> +		if (dev->rphy) {
> +			sas_remove_children(&dev->rphy->dev);
> +			sas_rphy_delete(dev->rphy);
> +			dev->rphy = NULL;
> +		}
> +		if (dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV) {
> +			if (dev->ex_dev.ex_phy) {
> +				kfree(dev->ex_dev.ex_phy);
> +				dev->ex_dev.ex_phy = NULL;
> +			}
> +		}
> +		spin_lock(&port->dev_list_lock);
> +		list_del_init(&dev->dev_list_node);
> +		spin_unlock(&port->dev_list_lock);
> +		kfree(dev); /* not kobject_register-ed yet */

This is a bit of a layering violation

if the various discover functions are going to return an error, I think
it's their job to clean up whatever they did before returning.

James



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cleanup after a discovery error
  2006-10-19 19:08 ` James Bottomley
@ 2006-10-30 20:23   ` malahal
  2006-11-07 20:01     ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: malahal @ 2006-10-30 20:23 UTC (permalink / raw)
  To: James Bottomley; +Cc: linux-scsi

James Bottomley [James.Bottomley@SteelEye.com] wrote:
> 
> This is a bit of a layering violation
> 
> if the various discover functions are going to return an error, I think
> it's their job to clean up whatever they did before returning.
> 
> James

Hope this works better.
Signed-off-by: Malahal Naineni <malahal@us.ibm.com>

diff -r 80de69a94159 drivers/scsi/libsas/sas_discover.c
--- a/drivers/scsi/libsas/sas_discover.c	Wed Oct 25 13:28:31 2006 -0700
+++ b/drivers/scsi/libsas/sas_discover.c	Mon Oct 30 11:55:21 2006 -0800
@@ -684,6 +684,11 @@ static void sas_discover_domain(void *da
 	}
 
 	if (error) {
+		sas_rphy_delete(port->port_dev->rphy);
+		port->port_dev->rphy = NULL;
+		spin_lock(&port->dev_list_lock);
+		list_del_init(&port->port_dev->dev_list_node);
+		spin_unlock(&port->dev_list_lock);
 		kfree(port->port_dev); /* not kobject_register-ed yet */
 		port->port_dev = NULL;
 	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cleanup after a discovery error
  2006-10-30 20:23   ` malahal
@ 2006-11-07 20:01     ` Darrick J. Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2006-11-07 20:01 UTC (permalink / raw)
  To: James Bottomley, linux-scsi

> James Bottomley [James.Bottomley@SteelEye.com] wrote:
>> This is a bit of a layering violation
>>
>> if the various discover functions are going to return an error, I think
>> it's their job to clean up whatever they did before returning.

Here's a reworked version of Malahal's patch that pushes the sas_rphy
cleanups into the sas_discover_{sas,sata,expander}.* functions.  It also
checks the return value of sas_notify_lldd_dev_found().  This patch
(since it includes discovery error cleanup for SATA) is against
2.6.19-rc4 + scsi-misc + scsi-rc-fixes + aic94xx-sas, though I can
respin it without the SATA bits if desired.

--

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>

diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
index 23461dc..0f790ea 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -564,12 +564,25 @@ int sas_discover_sata(struct domain_devi
 	default:
 		break;
 	}
+	if (res)
+		goto out_err;
 
 	sas_notify_lldd_dev_gone(dev);
-	if (!res) {
-		sas_notify_lldd_dev_found(dev);
-		res = sas_rphy_add(dev->rphy);
-	}
+	res = sas_notify_lldd_dev_found(dev);
+	if (res)
+		goto out_err2;
+
+	res = sas_rphy_add(dev->rphy);
+	if (res)
+		goto out_err;
+
+	return res;
+
+out_err:
+	sas_notify_lldd_dev_gone(dev);
+out_err2:
+	sas_rphy_free(dev->rphy);
+	dev->rphy = NULL;
 	return res;
 }
 
@@ -594,12 +607,20 @@ int sas_discover_end_dev(struct domain_d
 	/* do this to get the end device port attributes which will have
 	 * been scanned in sas_rphy_add */
 	sas_notify_lldd_dev_gone(dev);
-	sas_notify_lldd_dev_found(dev);
+	res = sas_notify_lldd_dev_found(dev);
+	if (res)
+		goto out_err2;
 
 	return 0;
 
 out_err:
 	sas_notify_lldd_dev_gone(dev);
+	sas_rphy_free(dev->rphy);
+	dev->rphy = NULL;
+	return res;
+out_err2:
+	sas_rphy_delete(dev->rphy);
+	dev->rphy = NULL;
 	return res;
 }
 
@@ -689,6 +710,10 @@ static void sas_discover_domain(void *da
 	}
 
 	if (error) {
+		spin_lock(&port->dev_list_lock);
+		list_del_init(&port->port_dev->dev_list_node);
+		spin_unlock(&port->dev_list_lock);
+
 		kfree(port->port_dev); /* not kobject_register-ed yet */
 		port->port_dev = NULL;
 	}
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 4cc7457..a79e89c 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -1474,14 +1474,27 @@ int sas_discover_root_expander(struct do
 	int res;
 	struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
 
-	sas_rphy_add(dev->rphy);
+	res = sas_rphy_add(dev->rphy);
+	if (res)
+		goto out_err;
 
 	ex->level = dev->port->disc.max_level; /* 0 */
 	res = sas_discover_expander(dev);
-	if (!res)
-		sas_ex_bfs_disc(dev->port);
+	if (res)
+		goto out_err2;
+
+	sas_ex_bfs_disc(dev->port);
 
 	return res;
+
+out_err2:
+	sas_rphy_delete(dev->rphy);
+	dev->rphy = NULL;
+	return res;
+out_err:
+	sas_rphy_free(dev->rphy);
+	dev->rphy = NULL;
+	return res;
 }
 
 /* ---------- Domain revalidation ---------- */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-11-07 20:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-19  3:19 [PATCH] cleanup after a discovery error malahal
2006-10-19 19:08 ` James Bottomley
2006-10-30 20:23   ` malahal
2006-11-07 20:01     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).