mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-14 15:54:15 +08:00
Staging: 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: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
96fe9ee2c2
commit
94002c07ff
@ -840,13 +840,12 @@ static int firmwareUpload(struct usbduxsub *usbduxsub,
|
||||
}
|
||||
|
||||
/* we generate a local buffer for the firmware */
|
||||
fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
|
||||
fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
|
||||
if (!fwBuf) {
|
||||
dev_err(&usbduxsub->interface->dev,
|
||||
"comedi_: mem alloc for firmware failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(fwBuf, firmwareBinary, sizeFirmware);
|
||||
|
||||
ret = usbduxsub_stop(usbduxsub);
|
||||
if (ret < 0) {
|
||||
|
@ -1368,13 +1368,12 @@ static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub,
|
||||
}
|
||||
|
||||
/* we generate a local buffer for the firmware */
|
||||
fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
|
||||
fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
|
||||
if (!fwBuf) {
|
||||
dev_err(&usbduxfastsub->interface->dev,
|
||||
"comedi_: mem alloc for firmware failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(fwBuf, firmwareBinary, sizeFirmware);
|
||||
|
||||
ret = usbduxfastsub_stop(usbduxfastsub);
|
||||
if (ret < 0) {
|
||||
|
@ -185,11 +185,10 @@ static void VmbusOnMsgDPC(struct hv_driver *drv)
|
||||
/* no msg */
|
||||
break;
|
||||
} else {
|
||||
copied = kmalloc(sizeof(*copied), GFP_ATOMIC);
|
||||
copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
|
||||
if (copied == NULL)
|
||||
continue;
|
||||
|
||||
memcpy(copied, msg, sizeof(*copied));
|
||||
osd_schedule_callback(gVmbusConnection.WorkQueue,
|
||||
VmbusOnChannelMessage,
|
||||
(void *)copied);
|
||||
|
@ -105,10 +105,9 @@ int line6_wait_dump(struct line6_dump_request *l6dr, int nonblock)
|
||||
int line6_dumpreq_initbuf(struct line6_dump_request *l6dr, const void *buf,
|
||||
size_t len, int num)
|
||||
{
|
||||
l6dr->reqbufs[num].buffer = kmalloc(len, GFP_KERNEL);
|
||||
l6dr->reqbufs[num].buffer = kmemdup(buf, len, GFP_KERNEL);
|
||||
if (l6dr->reqbufs[num].buffer == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(l6dr->reqbufs[num].buffer, buf, len);
|
||||
l6dr->reqbufs[num].length = len;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1074,7 +1074,8 @@ int pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pod->buffer_versionreq = kmalloc(sizeof(pod_request_version),
|
||||
pod->buffer_versionreq = kmemdup(pod_request_version,
|
||||
sizeof(pod_request_version),
|
||||
GFP_KERNEL);
|
||||
|
||||
if (pod->buffer_versionreq == NULL) {
|
||||
@ -1083,9 +1084,6 @@ int pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(pod->buffer_versionreq, pod_request_version,
|
||||
sizeof(pod_request_version));
|
||||
|
||||
/* create sysfs entries: */
|
||||
err = pod_create_files2(&interface->dev);
|
||||
if (err < 0) {
|
||||
|
@ -486,7 +486,8 @@ int variax_init(struct usb_interface *interface,
|
||||
return err;
|
||||
}
|
||||
|
||||
variax->buffer_activate = kmalloc(sizeof(variax_activate), GFP_KERNEL);
|
||||
variax->buffer_activate = kmemdup(variax_activate,
|
||||
sizeof(variax_activate), GFP_KERNEL);
|
||||
|
||||
if (variax->buffer_activate == NULL) {
|
||||
dev_err(&interface->dev, "Out of memory\n");
|
||||
@ -494,8 +495,6 @@ int variax_init(struct usb_interface *interface,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(variax->buffer_activate, variax_activate,
|
||||
sizeof(variax_activate));
|
||||
init_timer(&variax->activate_timer);
|
||||
|
||||
/* create sysfs entries: */
|
||||
|
@ -204,18 +204,18 @@ int pohmelfs_copy_crypto(struct pohmelfs_sb *psb)
|
||||
}
|
||||
|
||||
if (g->hash_keysize) {
|
||||
psb->hash_key = kmalloc(g->hash_keysize, GFP_KERNEL);
|
||||
psb->hash_key = kmemdup(g->hash_key, g->hash_keysize,
|
||||
GFP_KERNEL);
|
||||
if (!psb->hash_key)
|
||||
goto err_out_free_cipher_string;
|
||||
memcpy(psb->hash_key, g->hash_key, g->hash_keysize);
|
||||
psb->hash_keysize = g->hash_keysize;
|
||||
}
|
||||
|
||||
if (g->cipher_keysize) {
|
||||
psb->cipher_key = kmalloc(g->cipher_keysize, GFP_KERNEL);
|
||||
psb->cipher_key = kmemdup(g->cipher_key, g->cipher_keysize,
|
||||
GFP_KERNEL);
|
||||
if (!psb->cipher_key)
|
||||
goto err_out_free_hash;
|
||||
memcpy(psb->cipher_key, g->cipher_key, g->cipher_keysize);
|
||||
psb->cipher_keysize = g->cipher_keysize;
|
||||
}
|
||||
|
||||
@ -454,14 +454,12 @@ static int pohmelfs_crypto_hash_init(struct pohmelfs_config_group *g, struct poh
|
||||
g->hash_strlen = c->strlen;
|
||||
g->hash_keysize = c->keysize;
|
||||
|
||||
g->hash_key = kmalloc(c->keysize, GFP_KERNEL);
|
||||
g->hash_key = kmemdup(key, c->keysize, GFP_KERNEL);
|
||||
if (!g->hash_key) {
|
||||
kfree(g->hash_string);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(g->hash_key, key, c->keysize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -479,14 +477,12 @@ static int pohmelfs_crypto_cipher_init(struct pohmelfs_config_group *g, struct p
|
||||
g->cipher_strlen = c->strlen;
|
||||
g->cipher_keysize = c->keysize;
|
||||
|
||||
g->cipher_key = kmalloc(c->keysize, GFP_KERNEL);
|
||||
g->cipher_key = kmemdup(key, c->keysize, GFP_KERNEL);
|
||||
if (!g->cipher_key) {
|
||||
kfree(g->cipher_string);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(g->cipher_key, key, c->keysize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2667,11 +2667,11 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
|
||||
return -EINVAL;
|
||||
|
||||
if (param->u.wpa_ie.len) {
|
||||
buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
|
||||
buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
|
||||
GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = param->u.wpa_ie.len;
|
||||
|
@ -727,10 +727,9 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
|
||||
printk("len:%zu, ie:%d\n", len, ie[1]);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = kmalloc(len, GFP_KERNEL);
|
||||
buf = kmemdup(ie, len, GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(buf, ie, len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = len;
|
||||
|
@ -3255,11 +3255,11 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
|
||||
return -EINVAL;
|
||||
|
||||
if (param->u.wpa_ie.len) {
|
||||
buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
|
||||
buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
|
||||
GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = param->u.wpa_ie.len;
|
||||
|
@ -979,10 +979,9 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
|
||||
printk("len:%zu, ie:%d\n", len, ie[1]);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = kmalloc(len, GFP_KERNEL);
|
||||
buf = kmemdup(ie, len, GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(buf, ie, len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = len;
|
||||
|
@ -2844,11 +2844,11 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
|
||||
return -EINVAL;
|
||||
|
||||
if (param->u.wpa_ie.len) {
|
||||
buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
|
||||
buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
|
||||
GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = param->u.wpa_ie.len;
|
||||
|
@ -767,10 +767,9 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
|
||||
printk("len: %Zd, ie:%d\n", len, ie[1]);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = kmalloc(len, GFP_KERNEL);
|
||||
buf = kmemdup(ie, len, GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(buf, ie, len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = len;
|
||||
|
@ -1579,10 +1579,9 @@ static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
|
||||
|
||||
if(*(t++) == MFIE_TYPE_CHALLENGE){
|
||||
*chlen = *(t++);
|
||||
*challenge = kmalloc(*chlen, GFP_ATOMIC);
|
||||
*challenge = kmemdup(t, *chlen, GFP_ATOMIC);
|
||||
if (!*challenge)
|
||||
return -ENOMEM;
|
||||
memcpy(*challenge, t, *chlen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2870,11 +2869,11 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
|
||||
return -EINVAL;
|
||||
|
||||
if (param->u.wpa_ie.len) {
|
||||
buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
|
||||
buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
|
||||
GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = param->u.wpa_ie.len;
|
||||
|
@ -847,10 +847,9 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
|
||||
printk("len:%zu, ie:%d\n", len, ie[1]);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = kmalloc(len, GFP_KERNEL);
|
||||
buf = kmemdup(ie, len, GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(buf, ie, len);
|
||||
kfree(ieee->wpa_ie);
|
||||
ieee->wpa_ie = buf;
|
||||
ieee->wpa_ie_len = len;
|
||||
|
@ -502,13 +502,13 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
|
||||
}
|
||||
|
||||
/* set priv->urb->setup_packet */
|
||||
priv->urb->setup_packet = kzalloc(8, GFP_KERNEL);
|
||||
priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8,
|
||||
GFP_KERNEL);
|
||||
if (!priv->urb->setup_packet) {
|
||||
dev_err(&sdev->interface->dev, "allocate setup_packet\n");
|
||||
usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
|
||||
return;
|
||||
}
|
||||
memcpy(priv->urb->setup_packet, &pdu->u.cmd_submit.setup, 8);
|
||||
|
||||
/* set other members from the base header of pdu */
|
||||
priv->urb->context = (void *) priv;
|
||||
|
Loading…
Reference in New Issue
Block a user