All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SCSI: fix /proc memory leak in the SCSI core
@ 2008-12-01 15:26 Alan Stern
  2008-12-01 15:43 ` Boaz Harrosh
  2009-01-13 16:59 ` James Bottomley
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Stern @ 2008-12-01 15:26 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

The SCSI core calls scsi_proc_hostdir_add() from within
scsi_host_alloc(), but the corresponding scsi_proc_hostdir_rm()
routine is called from within scsi_remove_host().  As a result, if a
host is allocated and then deallocated without ever being registered,
the host's directory in /proc is leaked.

This patch (as1181) fixes this bug in the SCSI core by moving
scsi_proc_hostdir_add() into scsi_host_add().

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Can somebody check to make sure this is compatible with legacy drivers 
using the non-hotplug API?



Index: usb-2.6/drivers/scsi/hosts.c
===================================================================
--- usb-2.6.orig/drivers/scsi/hosts.c
+++ usb-2.6/drivers/scsi/hosts.c
@@ -206,9 +206,10 @@ int scsi_add_host(struct Scsi_Host *shos
 	if (error)
 		goto fail;
 
+	scsi_proc_hostdir_add(shost->hostt);
+
 	if (!shost->shost_gendev.parent)
 		shost->shost_gendev.parent = dev ? dev : &platform_bus;
-
 	error = device_add(&shost->shost_gendev);
 	if (error)
 		goto out;
@@ -259,6 +260,7 @@ int scsi_add_host(struct Scsi_Host *shos
  out_del_gendev:
 	device_del(&shost->shost_gendev);
  out:
+	scsi_proc_hostdir_rm(shost->hostt);
 	scsi_destroy_command_freelist(shost);
  fail:
 	return error;
@@ -407,7 +409,6 @@ struct Scsi_Host *scsi_host_alloc(struct
 		goto fail_kfree;
 	}
 
-	scsi_proc_hostdir_add(shost->hostt);
 	return shost;
 
  fail_kfree:


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

* Re: [PATCH] SCSI: fix /proc memory leak in the SCSI core
  2008-12-01 15:26 [PATCH] SCSI: fix /proc memory leak in the SCSI core Alan Stern
@ 2008-12-01 15:43 ` Boaz Harrosh
  2008-12-01 15:51   ` Alan Stern
  2009-01-13 16:59 ` James Bottomley
  1 sibling, 1 reply; 5+ messages in thread
From: Boaz Harrosh @ 2008-12-01 15:43 UTC (permalink / raw)
  To: Alan Stern; +Cc: James Bottomley, SCSI development list

Alan Stern wrote:
> The SCSI core calls scsi_proc_hostdir_add() from within
> scsi_host_alloc(), but the corresponding scsi_proc_hostdir_rm()
> routine is called from within scsi_remove_host().  As a result, if a
> host is allocated and then deallocated without ever being registered,
> the host's directory in /proc is leaked.
> 
> This patch (as1181) fixes this bug in the SCSI core by moving
> scsi_proc_hostdir_add() into scsi_host_add().
> 
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> 

Nice this also fixes the premature visibility of the directory
and the theoretical races, that can cause.

> ---
> 
> Can somebody check to make sure this is compatible with legacy drivers 
> using the non-hotplug API?
> 
> 
> 
> Index: usb-2.6/drivers/scsi/hosts.c
> ===================================================================
> --- usb-2.6.orig/drivers/scsi/hosts.c
> +++ usb-2.6/drivers/scsi/hosts.c
> @@ -206,9 +206,10 @@ int scsi_add_host(struct Scsi_Host *shos
>  	if (error)
>  		goto fail;
>  
> +	scsi_proc_hostdir_add(shost->hostt);
> +
>  	if (!shost->shost_gendev.parent)
>  		shost->shost_gendev.parent = dev ? dev : &platform_bus;
> -
>  	error = device_add(&shost->shost_gendev);
>  	if (error)
>  		goto out;
> @@ -259,6 +260,7 @@ int scsi_add_host(struct Scsi_Host *shos
>   out_del_gendev:
>  	device_del(&shost->shost_gendev);
>   out:
> +	scsi_proc_hostdir_rm(shost->hostt);
>  	scsi_destroy_command_freelist(shost);
>   fail:
>  	return error;
> @@ -407,7 +409,6 @@ struct Scsi_Host *scsi_host_alloc(struct
>  		goto fail_kfree;
>  	}
>  
> -	scsi_proc_hostdir_add(shost->hostt);
>  	return shost;
>  
>   fail_kfree:
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

* Re: [PATCH] SCSI: fix /proc memory leak in the SCSI core
  2008-12-01 15:43 ` Boaz Harrosh
@ 2008-12-01 15:51   ` Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2008-12-01 15:51 UTC (permalink / raw)
  To: Boaz Harrosh; +Cc: James Bottomley, SCSI development list

On Mon, 1 Dec 2008, Boaz Harrosh wrote:

> Alan Stern wrote:
> > The SCSI core calls scsi_proc_hostdir_add() from within
> > scsi_host_alloc(), but the corresponding scsi_proc_hostdir_rm()
> > routine is called from within scsi_remove_host().  As a result, if a
> > host is allocated and then deallocated without ever being registered,
> > the host's directory in /proc is leaked.
> > 
> > This patch (as1181) fixes this bug in the SCSI core by moving
> > scsi_proc_hostdir_add() into scsi_host_add().
> > 
> > Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> > 
> 
> Nice this also fixes the premature visibility of the directory
> and the theoretical races, that can cause.

I'm not so sure about that...  There's still a window in which the
directory is visible but empty; it's just smaller than before.

Besides, the window that really matters is between sending out the
uevent notification (during device_add) and populating the directory.
The patch doesn't address that problem.  Should it?

Alan Stern


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

* Re: [PATCH] SCSI: fix /proc memory leak in the SCSI core
  2008-12-01 15:26 [PATCH] SCSI: fix /proc memory leak in the SCSI core Alan Stern
  2008-12-01 15:43 ` Boaz Harrosh
@ 2009-01-13 16:59 ` James Bottomley
  2009-01-13 17:16   ` Alan Stern
  1 sibling, 1 reply; 5+ messages in thread
From: James Bottomley @ 2009-01-13 16:59 UTC (permalink / raw)
  To: Alan Stern; +Cc: SCSI development list

On Mon, 2008-12-01 at 10:26 -0500, Alan Stern wrote:
> Can somebody check to make sure this is compatible with legacy drivers 
> using the non-hotplug API?

I have this one marked for inclusion pending confirmation of this
request ... has anyone tried it?

James



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

* Re: [PATCH] SCSI: fix /proc memory leak in the SCSI core
  2009-01-13 16:59 ` James Bottomley
@ 2009-01-13 17:16   ` Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2009-01-13 17:16 UTC (permalink / raw)
  To: James Bottomley; +Cc: SCSI development list

On Tue, 13 Jan 2009, James Bottomley wrote:

> On Mon, 2008-12-01 at 10:26 -0500, Alan Stern wrote:
> > Can somebody check to make sure this is compatible with legacy drivers 
> > using the non-hotplug API?
> 
> I have this one marked for inclusion pending confirmation of this
> request ... has anyone tried it?

Not that I've heard.

Alan Stern


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

end of thread, other threads:[~2009-01-13 17:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-01 15:26 [PATCH] SCSI: fix /proc memory leak in the SCSI core Alan Stern
2008-12-01 15:43 ` Boaz Harrosh
2008-12-01 15:51   ` Alan Stern
2009-01-13 16:59 ` James Bottomley
2009-01-13 17:16   ` Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.