[PATCH] reduce stack in cdrom/optcd.c

Randy.Dunlap (randy.dunlap@verizon.net)
Fri, 21 Mar 2003 22:51:52 -0800


This is a multi-part message in MIME format.
--------------1075FE351E48CFE76A68482B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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
--------------1075FE351E48CFE76A68482B
Content-Type: text/plain; charset=us-ascii;
name="optcdrom-stack.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="optcdrom-stack.patch"

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;
}


--------------1075FE351E48CFE76A68482B--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/