Commit 94002c07 authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman
Browse files

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: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 96fe9ee2
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+1 −2
Original line number Diff line number Diff line
@@ -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);
+1 −2
Original line number Diff line number Diff line
@@ -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;
}
+2 −4
Original line number Diff line number Diff line
@@ -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) {
Loading