The CP210x currently does a kcalloc() to create a temporary buffer
that has a maximum size of 16 bytes. This patch uses the stack for the
buffer.
This patch also simplifies the math used to calculate the number of
u32's needed to contain the byte array.
Signed-off-by: Ben Gardner <[EMAIL PROTECTED]>
---
Index: linux-2.6.20/drivers/usb/serial/cp2101.c
===================================================================
--- linux-2.6.20.orig/drivers/usb/serial/cp2101.c 2007-02-06 09:30:59.000000000 -0600
+++ linux-2.6.20/drivers/usb/serial/cp2101.c 2007-02-06 09:36:51.000000000 -0600
@@ -161,7 +161,7 @@
/*
* cp2101_get_config
* Reads from the CP2101 configuration registers
- * 'size' is specified in bytes.
+ * 'size' is specified in bytes, can be 1, 2 or 16
* 'data' is a pointer to a pre-allocated array of integers large
* enough to hold 'size' bytes (with 4 bytes to each integer)
*/
@@ -169,16 +169,16 @@
unsigned int *data, int size)
{
struct usb_serial *serial = port->serial;
- u32 *buf;
+ u32 buf[4];
int result, i, length;
/* Number of integers required to contain the array */
- length = (((size - 1) | 3) + 1)/4;
+ length = (size + 3) / 4;
- buf = kcalloc(length, sizeof(u32), GFP_KERNEL);
- if (!buf) {
- dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
- return -ENOMEM;
+ /* Clear the last u32 if size isn't a multiple of 4 */
+ if (size & 3)
+ {
+ buf[length - 1] = 0;
}
/* For get requests, the request number must be incremented */
@@ -193,8 +193,6 @@
for (i=0; i<length; i++)
data[i] = le32_to_cpu(buf[i]);
- kfree(buf);
-
if (result != size) {
dev_err(&port->dev, "%s - Unable to send config request, "
"request=0x%x size=%d result=%d\n",
@@ -209,24 +207,17 @@
* cp2101_set_config
* Writes to the CP2101 configuration registers
* Values less than 16 bits wide are sent directly
- * 'size' is specified in bytes.
+ * 'size' is specified in bytes, can be 2 or 16
*/
static int cp2101_set_config(struct usb_serial_port* port, u8 request,
unsigned int *data, int size)
{
struct usb_serial *serial = port->serial;
- u32 *buf;
+ u32 buf[4];
int result, i, length;
/* Number of integers required to contain the array */
- length = (((size - 1) | 3) + 1)/4;
-
- buf = kmalloc(length * sizeof(u32), GFP_KERNEL);
- if (!buf) {
- dev_err(&port->dev, "%s - out of memory.\n",
- __FUNCTION__);
- return -ENOMEM;
- }
+ length = (size + 3) / 4;
/* Array of integers into bytes */
for (i = 0; i < length; i++)
@@ -244,8 +235,6 @@
0, NULL, 0, 300);
}
- kfree(buf);
-
if ((size > 2 && result != size) || result < 0) {
dev_err(&port->dev, "%s - Unable to send request, "
"request=0x%x size=%d result=%d\n",
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel