aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-05-15 07:18:58 -0400
committerDavid S. Miller <davem@davemloft.net>2010-05-17 20:44:47 -0400
commit175c04414106c34f0130d8d3bf152825b4829ceb (patch)
treee75156f45768c01199fb270445dcbdf37d005b16 /drivers/net/usb
parent08d18f3b62b4c05731a09eca2b432842a0a18da5 (diff)
drivers/net/usb: Use kmemdup
Use kmemdup when some other buffer is immediately copied into the allocated region. A simplified version of the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression from,to,size,flag; statement S; @@ - to = \(kmalloc\|kzalloc\)(size,flag); + to = kmemdup(from,size,flag); if (to==NULL || ...) S - memcpy(to, from, size); // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/pegasus.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 1cd17d274a12..974d17f0263e 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -203,13 +203,12 @@ static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
203 char *buffer; 203 char *buffer;
204 DECLARE_WAITQUEUE(wait, current); 204 DECLARE_WAITQUEUE(wait, current);
205 205
206 buffer = kmalloc(size, GFP_KERNEL); 206 buffer = kmemdup(data, size, GFP_KERNEL);
207 if (!buffer) { 207 if (!buffer) {
208 netif_warn(pegasus, drv, pegasus->net, 208 netif_warn(pegasus, drv, pegasus->net,
209 "out of memory in %s\n", __func__); 209 "out of memory in %s\n", __func__);
210 return -ENOMEM; 210 return -ENOMEM;
211 } 211 }
212 memcpy(buffer, data, size);
213 212
214 add_wait_queue(&pegasus->ctrl_wait, &wait); 213 add_wait_queue(&pegasus->ctrl_wait, &wait);
215 set_current_state(TASK_UNINTERRUPTIBLE); 214 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -255,13 +254,12 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
255 char *tmp; 254 char *tmp;
256 DECLARE_WAITQUEUE(wait, current); 255 DECLARE_WAITQUEUE(wait, current);
257 256
258 tmp = kmalloc(1, GFP_KERNEL); 257 tmp = kmemdup(&data, 1, GFP_KERNEL);
259 if (!tmp) { 258 if (!tmp) {
260 netif_warn(pegasus, drv, pegasus->net, 259 netif_warn(pegasus, drv, pegasus->net,
261 "out of memory in %s\n", __func__); 260 "out of memory in %s\n", __func__);
262 return -ENOMEM; 261 return -ENOMEM;
263 } 262 }
264 memcpy(tmp, &data, 1);
265 add_wait_queue(&pegasus->ctrl_wait, &wait); 263 add_wait_queue(&pegasus->ctrl_wait, &wait);
266 set_current_state(TASK_UNINTERRUPTIBLE); 264 set_current_state(TASK_UNINTERRUPTIBLE);
267 while (pegasus->flags & ETH_REGS_CHANGED) 265 while (pegasus->flags & ETH_REGS_CHANGED)