ChangeSet 1.985.10.10, 2003/03/25 12:41:14-08:00, [EMAIL PROTECTED]
[PATCH] USB: usb/misc/emi26.c stack reduction
Reduces stack usage in emi26_load_firmware().
drivers/usb/misc/emi26.c | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
diff -Nru a/drivers/usb/misc/emi26.c b/drivers/usb/misc/emi26.c
--- a/drivers/usb/misc/emi26.c Tue Mar 25 16:45:55 2003
+++ b/drivers/usb/misc/emi26.c Tue Mar 25 16:45:55 2003
@@ -78,19 +78,28 @@
return response;
}
+#define FW_LOAD_SIZE 1023
+
static int emi26_load_firmware (struct usb_device *dev)
{
int err;
int i;
int pos = 0; /* Position in hex record */
__u32 addr; /* Address to write */
- __u8 buf[1023];
+ __u8 *buf;
+
+ buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL);
+ if (!buf) {
+ err( "%s - error loading firmware: error = %d", __FUNCTION__, -ENOMEM);
+ err = -ENOMEM;
+ goto wraperr;
+ }
/* Assert reset (stop the CPU in the EMI) */
err = emi26_set_reset(dev,1);
if (err < 0) {
err( "%s - error loading firmware: error = %d", __FUNCTION__, err);
- return err;
+ goto wraperr;
}
/* 1. We need to put the loader for the FPGA into the EZ-USB */
@@ -98,7 +107,7 @@
err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data,
g_Loader[i].length, ANCHOR_LOAD_INTERNAL);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__,
err);
- return err;
+ goto wraperr;
}
}
@@ -113,7 +122,7 @@
addr = g_bitstream[pos].address;
/* intel hex records are terminated with type 0 element */
- while ((g_bitstream[pos].type == 0) && (i + g_bitstream[pos].length <
sizeof(buf))) {
+ while ((g_bitstream[pos].type == 0) && (i + g_bitstream[pos].length <
FW_LOAD_SIZE)) {
memcpy(buf + i, g_bitstream[pos].data,
g_bitstream[pos].length);
i += g_bitstream[pos].length;
pos++;
@@ -121,7 +130,7 @@
err = emi26_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__,
err);
- return err;
+ goto wraperr;
}
} while (i > 0);
@@ -129,7 +138,7 @@
err = emi26_set_reset(dev,1);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__, err);
- return err;
+ goto wraperr;
}
/* 3. We need to put the loader for the firmware into the EZ-USB (again...) */
@@ -137,7 +146,7 @@
err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data,
g_Loader[i].length, ANCHOR_LOAD_INTERNAL);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__,
err);
- return err;
+ goto wraperr;
}
}
@@ -145,7 +154,7 @@
err = emi26_set_reset(dev,0);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__, err);
- return err;
+ goto wraperr;
}
/* 4. We put the part of the firmware that lies in the external RAM into the
EZ-USB */
@@ -154,7 +163,7 @@
err = emi26_writememory(dev, g_Firmware[i].address,
g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_EXTERNAL);
if (err < 0) {
err("%s - error loading firmware: error = %d",
__FUNCTION__, err);
- return err;
+ goto wraperr;
}
}
}
@@ -163,7 +172,7 @@
err = emi26_set_reset(dev,1);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__, err);
- return err;
+ goto wraperr;
}
for (i=0; g_Firmware[i].type == 0; i++) {
@@ -171,7 +180,7 @@
err = emi26_writememory(dev, g_Firmware[i].address,
g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_INTERNAL);
if (err < 0) {
err("%s - error loading firmware: error = %d",
__FUNCTION__, err);
- return err;
+ goto wraperr;
}
}
}
@@ -180,12 +189,16 @@
err = emi26_set_reset(dev,0);
if (err < 0) {
err("%s - error loading firmware: error = %d", __FUNCTION__, err);
- return err;
+ goto wraperr;
}
/* return 1 to fail the driver inialization
* and give real driver change to load */
return 1;
+
+wraperr:
+ kfree(buf);
+ return err;
}
static __devinitdata struct usb_device_id id_table [] = {
-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel