* [PATCH] reduce stack in cdrom/optcd.c
@ 2003-03-22 6:51 Randy.Dunlap
2003-03-22 20:43 ` Alan Cox
0 siblings, 1 reply; 7+ messages in thread
From: Randy.Dunlap @ 2003-03-22 6:51 UTC (permalink / raw)
To: linux-kernel, torvalds, leo
[-- Attachment #1: Type: text/plain, Size: 149 bytes --]
Hi,
This reduces stack usage in drivers/cdrom/optcd.c by
dynamically allocating a large (> 2 KB) buffer.
Patch is to 2.5.65. Please apply.
~Randy
[-- Attachment #2: optcdrom-stack.patch --]
[-- Type: text/plain, Size: 1462 bytes --]
patch_name: optcdrom-stack.patch
patch_version: 2003-03-21.22:31:24
author: Randy.Dunlap <rddunlap@osdl.org>
description: reduce stack usage in drivers/cdrom/optcd::cdromread()
product: Linux
product_versions: 2.5.65
changelog: kmalloc() the large buffer
maintainer: Leo Spiekman <leo@netlabs.net>
diffstat: =
drivers/cdrom/optcd.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
diff -Naur ./drivers/cdrom/optcd.c%CDROM ./drivers/cdrom/optcd.c
--- ./drivers/cdrom/optcd.c%CDROM Mon Mar 17 13:43:49 2003
+++ ./drivers/cdrom/optcd.c Fri Mar 21 22:30:08 2003
@@ -1600,13 +1600,17 @@
static int cdromread(unsigned long arg, int blocksize, int cmd)
{
- int status;
+ int status, ret = 0;
struct cdrom_msf msf;
- char buf[CD_FRAMESIZE_RAWER];
+ char *buf;
if (copy_from_user(&msf, (void *) arg, sizeof msf))
return -EFAULT;
+ buf = kmalloc(CD_FRAMESIZE_RAWER, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
bin2bcd(&msf);
msf.cdmsf_min1 = 0;
msf.cdmsf_sec1 = 0;
@@ -1615,11 +1619,19 @@
DEBUG((DEBUG_VFS, "read cmd status 0x%x", status));
- if (!sleep_flag_low(FL_DTEN, SLEEP_TIMEOUT))
- return -EIO;
+ if (!sleep_flag_low(FL_DTEN, SLEEP_TIMEOUT)) {
+ ret = -EIO;
+ goto cdr_free;
+ }
+
fetch_data(buf, blocksize);
- return copy_to_user((void *)arg, &buf, blocksize) ? -EFAULT : 0;
+ if (copy_to_user((void *)arg, &buf, blocksize))
+ ret = -EFAULT;
+
+cdr_free:
+ kfree(buf);
+ return ret;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] reduce stack in cdrom/optcd.c
2003-03-22 20:43 ` Alan Cox
@ 2003-03-22 20:19 ` Arjan van de Ven
2003-03-25 18:29 ` Jens Axboe
0 siblings, 1 reply; 7+ messages in thread
From: Arjan van de Ven @ 2003-03-22 20:19 UTC (permalink / raw)
To: Alan Cox; +Cc: Randy.Dunlap, Linux Kernel Mailing List, Linus Torvalds, leo
[-- Attachment #1: Type: text/plain, Size: 500 bytes --]
On Sat, 2003-03-22 at 21:43, Alan Cox wrote:
> On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
> > Hi,
> >
> > This reduces stack usage in drivers/cdrom/optcd.c by
> > dynamically allocating a large (> 2 KB) buffer.
> >
> > Patch is to 2.5.65. Please apply.
>
> This loosk broken. You are using GFP_KERNEL memory allocations on the
> read path of a block device. What happens if the allocation fails
> because we need memory
it's unlikely that you have your swap on the cdrom ;)
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] reduce stack in cdrom/optcd.c
2003-03-22 6:51 [PATCH] reduce stack in cdrom/optcd.c Randy.Dunlap
@ 2003-03-22 20:43 ` Alan Cox
2003-03-22 20:19 ` Arjan van de Ven
0 siblings, 1 reply; 7+ messages in thread
From: Alan Cox @ 2003-03-22 20:43 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: Linux Kernel Mailing List, Linus Torvalds, leo
On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
> Hi,
>
> This reduces stack usage in drivers/cdrom/optcd.c by
> dynamically allocating a large (> 2 KB) buffer.
>
> Patch is to 2.5.65. Please apply.
This loosk broken. You are using GFP_KERNEL memory allocations on the
read path of a block device. What happens if the allocation fails
because we need memory
Surely that buffer needs to be allocated once at open and freed on close
?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] reduce stack in cdrom/optcd.c
2003-03-22 20:19 ` Arjan van de Ven
@ 2003-03-25 18:29 ` Jens Axboe
2003-03-25 18:43 ` Randy.Dunlap
0 siblings, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2003-03-25 18:29 UTC (permalink / raw)
To: Arjan van de Ven
Cc: Alan Cox, Randy.Dunlap, Linux Kernel Mailing List, Linus Torvalds, leo
On Sat, Mar 22 2003, Arjan van de Ven wrote:
> On Sat, 2003-03-22 at 21:43, Alan Cox wrote:
> > On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
> > > Hi,
> > >
> > > This reduces stack usage in drivers/cdrom/optcd.c by
> > > dynamically allocating a large (> 2 KB) buffer.
> > >
> > > Patch is to 2.5.65. Please apply.
> >
> > This loosk broken. You are using GFP_KERNEL memory allocations on the
> > read path of a block device. What happens if the allocation fails
> > because we need memory
>
> it's unlikely that you have your swap on the cdrom ;)
your swap device could still be plugged behind your cdrom.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] reduce stack in cdrom/optcd.c
2003-03-25 18:29 ` Jens Axboe
@ 2003-03-25 18:43 ` Randy.Dunlap
0 siblings, 0 replies; 7+ messages in thread
From: Randy.Dunlap @ 2003-03-25 18:43 UTC (permalink / raw)
To: Jens Axboe; +Cc: arjanv, alan, randy.dunlap, linux-kernel, torvalds, leo
On Tue, 25 Mar 2003 19:29:16 +0100 Jens Axboe <axboe@suse.de> wrote:
| On Sat, Mar 22 2003, Arjan van de Ven wrote:
| > On Sat, 2003-03-22 at 21:43, Alan Cox wrote:
| > > On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
| > > > Hi,
| > > >
| > > > This reduces stack usage in drivers/cdrom/optcd.c by
| > > > dynamically allocating a large (> 2 KB) buffer.
| > > >
| > > > Patch is to 2.5.65. Please apply.
| > >
| > > This loosk broken. You are using GFP_KERNEL memory allocations on the
| > > read path of a block device. What happens if the allocation fails
| > > because we need memory
| >
| > it's unlikely that you have your swap on the cdrom ;)
|
| your swap device could still be plugged behind your cdrom.
I plan to change it as Alan suggested. Will do.
--
~Randy
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] reduce stack in cdrom/optcd.c
2003-03-26 20:12 Randy.Dunlap
@ 2003-03-27 6:54 ` Jens Axboe
0 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2003-03-27 6:54 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: alan, linux-kernel
On Wed, Mar 26 2003, Randy.Dunlap wrote:
>
> (resend; was lost last night)
>
>
> > From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> >
> > On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
> > > Hi,
> > >
> > > This reduces stack usage in drivers/cdrom/optcd.c by
> > > dynamically allocating a large (> 2 KB) buffer.
> > >
> > > Patch is to 2.5.65. Please apply.
> >
> > This loosk broken. You are using GFP_KERNEL memory allocations on the
> > read path of a block device. What happens if the allocation fails
> > because we need memory
> >
> > Surely that buffer needs to be allocated once at open and freed on close
> > ?
> > --
>
>
> Alan, Jens, anybody else-
>
> Does this pass?
Yes, looks much better.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] reduce stack in cdrom/optcd.c
@ 2003-03-26 20:12 Randy.Dunlap
2003-03-27 6:54 ` Jens Axboe
0 siblings, 1 reply; 7+ messages in thread
From: Randy.Dunlap @ 2003-03-26 20:12 UTC (permalink / raw)
To: alan, axboe; +Cc: linux-kernel
(resend; was lost last night)
> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
>
> On Sat, 2003-03-22 at 06:51, Randy.Dunlap wrote:
> > Hi,
> >
> > This reduces stack usage in drivers/cdrom/optcd.c by
> > dynamically allocating a large (> 2 KB) buffer.
> >
> > Patch is to 2.5.65. Please apply.
>
> This loosk broken. You are using GFP_KERNEL memory allocations on the
> read path of a block device. What happens if the allocation fails
> because we need memory
>
> Surely that buffer needs to be allocated once at open and freed on close
> ?
> --
Alan, Jens, anybody else-
Does this pass?
Patch is now to 2.5.66.
Thanks,
~Randy
patch_name: optcd-stackbuf.patch
patch_version: 2003-03-25.19:02:22
author: Randy.Dunlap <rddunlap@osdl.org>
description: pre-allocate readbuf instead of kmalloc() in cdromread();
(previously modified for stack reduction)
product: Linux
product_versions: 2.5.66
maintainer: unknown (email bounces)
diffstat: =
drivers/cdrom/optcd.c | 37 +++++++++++++++++++------------------
1 files changed, 19 insertions(+), 18 deletions(-)
diff -Naur ./drivers/cdrom/optcd.c%OPTCD ./drivers/cdrom/optcd.c
--- ./drivers/cdrom/optcd.c%OPTCD 2003-03-24 14:00:10.000000000 -0800
+++ ./drivers/cdrom/optcd.c 2003-03-25 19:01:06.000000000 -0800
@@ -1598,19 +1598,17 @@
}
+static struct gendisk *optcd_disk;
+
+
static int cdromread(unsigned long arg, int blocksize, int cmd)
{
- int status, ret = 0;
+ int status;
struct cdrom_msf msf;
- char *buf;
if (copy_from_user(&msf, (void *) arg, sizeof msf))
return -EFAULT;
- buf = kmalloc(CD_FRAMESIZE_RAWER, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
bin2bcd(&msf);
msf.cdmsf_min1 = 0;
msf.cdmsf_sec1 = 0;
@@ -1619,19 +1617,15 @@
DEBUG((DEBUG_VFS, "read cmd status 0x%x", status));
- if (!sleep_flag_low(FL_DTEN, SLEEP_TIMEOUT)) {
- ret = -EIO;
- goto cdr_free;
- }
+ if (!sleep_flag_low(FL_DTEN, SLEEP_TIMEOUT))
+ return -EIO;
- fetch_data(buf, blocksize);
+ fetch_data(optcd_disk->private_data, blocksize);
- if (copy_to_user((void *)arg, &buf, blocksize))
- ret = -EFAULT;
+ if (copy_to_user((void *)arg, optcd_disk->private_data, blocksize))
+ return -EFAULT;
-cdr_free:
- kfree(buf);
- return ret;
+ return 0;
}
@@ -1857,6 +1851,14 @@
if (!open_count && state == S_IDLE) {
int status;
+ char *buf;
+
+ buf = kmalloc(CD_FRAMESIZE_RAWER, GFP_KERNEL);
+ if (!buf) {
+ printk(KERN_INFO "optcd: cannot allocate read buffer\n");
+ return -ENOMEM;
+ }
+ optcd_disk->private_data = buf; /* save read buffer */
toc_uptodate = 0;
opt_invalidate_buffers();
@@ -1922,6 +1924,7 @@
status = exec_cmd(COMOPEN);
DEBUG((DEBUG_VFS, "exec_cmd COMOPEN: %02x", -status));
}
+ kfree(optcd_disk->private_data);
del_timer(&delay_timer);
del_timer(&req_timer);
}
@@ -2010,8 +2013,6 @@
#endif /* MODULE */
-static struct gendisk *optcd_disk;
-
/* Test for presence of drive and initialize it. Called at boot time
or during module initialisation. */
static int __init optcd_init(void)
--
~Randy
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-03-27 6:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-22 6:51 [PATCH] reduce stack in cdrom/optcd.c Randy.Dunlap
2003-03-22 20:43 ` Alan Cox
2003-03-22 20:19 ` Arjan van de Ven
2003-03-25 18:29 ` Jens Axboe
2003-03-25 18:43 ` Randy.Dunlap
2003-03-26 20:12 Randy.Dunlap
2003-03-27 6:54 ` Jens Axboe
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.