From: Jan Blunck <j.blunck@tu-harburg.de>
To: Ingo Oeser <ioe-lkml@rameria.de>
Cc: linux-scsi@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
Linux-Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sg.c: fix a memory leak in devices seq_file implementation (2nd)
Date: Tue, 23 Aug 2005 22:25:14 +0200 [thread overview]
Message-ID: <430B862A.4000009@tu-harburg.de> (raw)
In-Reply-To: <200508232057.50334.ioe-lkml@rameria.de>
[-- Attachment #1: Type: text/plain, Size: 250 bytes --]
Ingo Oeser schrieb:
>
> kfree() checks its argument, so instead of
>
> if (pointer)
> kfree(pointer);
>
> just do
>
> kfree(pointer);
>
This is an updated patch. Removed the unnecessary if.
Signed-off-by: Jan Blunck <j.blunck@tu-harburg.de>
[-- Attachment #2: scsi_sg.c-dev_seq_file-fix.diff --]
[-- Type: text/x-patch, Size: 1181 bytes --]
drivers/scsi/sg.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
Index: linux-2.6/drivers/scsi/sg.c
===================================================================
--- linux-2.6.orig/drivers/scsi/sg.c
+++ linux-2.6/drivers/scsi/sg.c
@@ -2971,23 +2971,22 @@ static void * dev_seq_start(struct seq_f
{
struct sg_proc_deviter * it = kmalloc(sizeof(*it), GFP_KERNEL);
+ s->private = it;
if (! it)
return NULL;
+
if (NULL == sg_dev_arr)
- goto err1;
+ return NULL;
it->index = *pos;
it->max = sg_last_dev();
if (it->index >= it->max)
- goto err1;
+ return NULL;
return it;
-err1:
- kfree(it);
- return NULL;
}
static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
- struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
+ struct sg_proc_deviter * it = s->private;
*pos = ++it->index;
return (it->index < it->max) ? it : NULL;
@@ -2995,7 +2994,9 @@ static void * dev_seq_next(struct seq_fi
static void dev_seq_stop(struct seq_file *s, void *v)
{
- kfree (v);
+ struct sg_proc_deviter * it = s->private;
+
+ kfree (it);
}
static int sg_proc_open_dev(struct inode *inode, struct file *file)
prev parent reply other threads:[~2005-08-23 20:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-19 12:27 [PATCH] sg.c: fix a memory leak in devices seq_file implementation Jan Blunck
[not found] ` <200508232057.50334.ioe-lkml@rameria.de>
2005-08-23 20:25 ` Jan Blunck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=430B862A.4000009@tu-harburg.de \
--to=j.blunck@tu-harburg.de \
--cc=akpm@osdl.org \
--cc=ioe-lkml@rameria.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®