All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 12/15] scsi: fix /proc memory leak in the SCSI core
@ 2009-03-04 20:06 akpm
  2009-03-04 20:57 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: akpm @ 2009-03-04 20:06 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, akpm, stern

From: Alan Stern <stern@rowland.harvard.edu>

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>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/scsi/hosts.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff -puN drivers/scsi/hosts.c~scsi-fix-proc-memory-leak-in-the-scsi-core drivers/scsi/hosts.c
--- a/drivers/scsi/hosts.c~scsi-fix-proc-memory-leak-in-the-scsi-core
+++ a/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] 2+ messages in thread

* Re: [patch 12/15] scsi: fix /proc memory leak in the SCSI core
  2009-03-04 20:06 [patch 12/15] scsi: fix /proc memory leak in the SCSI core akpm
@ 2009-03-04 20:57 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2009-03-04 20:57 UTC (permalink / raw)
  To: akpm; +Cc: James.Bottomley, linux-scsi

On Wed, 4 Mar 2009 akpm@linux-foundation.org wrote:

> From: Alan Stern <stern@rowland.harvard.edu>
> 
> 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().

Andrew:

I sent James an updated version of this patch, but I forgot to CC you
-- sorry!  He seemed to think that the approach used in the revised
patch is superior, but I haven't gotten any definite feedback about it
yet.

The revised patch is below.

Alan Stern



---------------------------------------------------------------------

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 (as1181b) fixes this bug in the SCSI core by moving
scsi_proc_hostdir_rm() into scsi_host_dev_release().

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

---

Index: usb-2.6/drivers/scsi/hosts.c
===================================================================
--- usb-2.6.orig/drivers/scsi/hosts.c
+++ usb-2.6/drivers/scsi/hosts.c
@@ -176,7 +176,6 @@ void scsi_remove_host(struct Scsi_Host *
 	transport_unregister_device(&shost->shost_gendev);
 	device_unregister(&shost->shost_dev);
 	device_del(&shost->shost_gendev);
-	scsi_proc_hostdir_rm(shost->hostt);
 }
 EXPORT_SYMBOL(scsi_remove_host);
 
@@ -270,6 +269,8 @@ static void scsi_host_dev_release(struct
 	struct Scsi_Host *shost = dev_to_shost(dev);
 	struct device *parent = dev->parent;
 
+	scsi_proc_hostdir_rm(shost->hostt);
+
 	if (shost->ehandler)
 		kthread_stop(shost->ehandler);
 	if (shost->work_q)


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

end of thread, other threads:[~2009-03-04 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-04 20:06 [patch 12/15] scsi: fix /proc memory leak in the SCSI core akpm
2009-03-04 20:57 ` 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.