[PATCH] kmemdup: some users
authorAlexey Dobriyan <adobriyan@gmail.com>
Sun, 1 Oct 2006 06:27:21 +0000 (23:27 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 1 Oct 2006 07:39:19 +0000 (00:39 -0700)
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/i386/kernel/process.c
fs/posix_acl.c
mm/mempolicy.c
net/rxrpc/transport.c
sound/pci/echoaudio/layla24_dsp.c
sound/usb/usbaudio.c
sound/usb/usbmidi.c

index 8c190ca7ae4494b980b01c8a4c88eee291a3fd45..96cd0232e1e03ad24638a6837e024de24ecd0c79 100644 (file)
@@ -425,13 +425,12 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
 
        tsk = current;
        if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) {
-               p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
+               p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr,
+                                               IO_BITMAP_BYTES, GFP_KERNEL);
                if (!p->thread.io_bitmap_ptr) {
                        p->thread.io_bitmap_max = 0;
                        return -ENOMEM;
                }
-               memcpy(p->thread.io_bitmap_ptr, tsk->thread.io_bitmap_ptr,
-                       IO_BITMAP_BYTES);
                set_tsk_thread_flag(p, TIF_IO_BITMAP);
        }
 
index 6c8dcf7613fd89bf903a95b311af8a1eee2bf8ce..aec931e09973716240bf55441622dccf95cf3c74 100644 (file)
@@ -58,11 +58,9 @@ posix_acl_clone(const struct posix_acl *acl, gfp_t flags)
        if (acl) {
                int size = sizeof(struct posix_acl) + acl->a_count *
                           sizeof(struct posix_acl_entry);
-               clone = kmalloc(size, flags);
-               if (clone) {
-                       memcpy(clone, acl, size);
+               clone = kmemdup(acl, size, flags);
+               if (clone)
                        atomic_set(&clone->a_refcount, 1);
-               }
        }
        return clone;
 }
index cf18f0942553554ae4977958dc06109335eb8abd..25788b1b7fcff4b6d116dffab3abe6e1ecc17d08 100644 (file)
@@ -1324,12 +1324,11 @@ struct mempolicy *__mpol_copy(struct mempolicy *old)
        atomic_set(&new->refcnt, 1);
        if (new->policy == MPOL_BIND) {
                int sz = ksize(old->v.zonelist);
-               new->v.zonelist = kmalloc(sz, SLAB_KERNEL);
+               new->v.zonelist = kmemdup(old->v.zonelist, sz, SLAB_KERNEL);
                if (!new->v.zonelist) {
                        kmem_cache_free(policy_cache, new);
                        return ERR_PTR(-ENOMEM);
                }
-               memcpy(new->v.zonelist, old->v.zonelist, sz);
        }
        return new;
 }
index 465efc86fccf1f253cf93a4e5705017e6e1dd83d..94b2e2fe6fdb97ec548956f1d247d5da8ad4c70b 100644 (file)
@@ -381,11 +381,10 @@ static int rxrpc_incoming_msg(struct rxrpc_transport *trans,
 
                /* allocate a new message record */
                ret = -ENOMEM;
-               msg = kmalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
+               msg = kmemdup(jumbomsg, sizeof(struct rxrpc_message), GFP_KERNEL);
                if (!msg)
                        goto error;
 
-               memcpy(msg, jumbomsg, sizeof(*msg));
                list_add_tail(&msg->link, msgq);
 
                /* adjust the jumbo packet */
index 7ec5b63d0dcec008b0a7200ca5d57cef4ae42438..97e42e1151476cdafbb40ac83a6d09b2798bd704 100644 (file)
@@ -302,11 +302,11 @@ static int switch_asic(struct echoaudio *chip, const struct firmware *asic)
 
        /*  Check to see if this is already loaded */
        if (asic != chip->asic_code) {
-               monitors = kmalloc(MONITOR_ARRAY_SIZE, GFP_KERNEL);
+               monitors = kmemdup(chip->comm_page->monitors,
+                                       MONITOR_ARRAY_SIZE, GFP_KERNEL);
                if (! monitors)
                        return -ENOMEM;
 
-               memcpy(monitors, chip->comm_page->monitors, MONITOR_ARRAY_SIZE);
                memset(chip->comm_page->monitors, ECHOGAIN_MUTED,
                       MONITOR_ARRAY_SIZE);
 
index 49248fa7aef47adaa9884aada5ebf593f8838d72..a42acf6d7b68962b22b17061eebf1090abcc88e3 100644 (file)
@@ -2046,10 +2046,9 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
        void *buf = NULL;
 
        if (size > 0) {
-               buf = kmalloc(size, GFP_KERNEL);
+               buf = kmemdup(data, size, GFP_KERNEL);
                if (!buf)
                        return -ENOMEM;
-               memcpy(buf, data, size);
        }
        err = usb_control_msg(dev, pipe, request, requesttype,
                              value, index, buf, size, timeout);
@@ -2846,12 +2845,11 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
        int stream, err;
        int *rate_table = NULL;
 
-       fp = kmalloc(sizeof(*fp), GFP_KERNEL);
+       fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
        if (! fp) {
-               snd_printk(KERN_ERR "cannot malloc\n");
+               snd_printk(KERN_ERR "cannot memdup\n");
                return -ENOMEM;
        }
-       memcpy(fp, quirk->data, sizeof(*fp));
        if (fp->nr_rates > 0) {
                rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
                if (!rate_table) {
@@ -3029,10 +3027,9 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip,
            altsd->bNumEndpoints != 1)
                return -ENXIO;
 
-       fp = kmalloc(sizeof(*fp), GFP_KERNEL);
+       fp = kmemdup(&ua1000_format, sizeof(*fp), GFP_KERNEL);
        if (!fp)
                return -ENOMEM;
-       memcpy(fp, &ua1000_format, sizeof(*fp));
 
        fp->channels = alts->extra[4];
        fp->iface = altsd->bInterfaceNumber;
index abe29dadd979365e01d1458ac00531dd292d1984..0dcf78adb99a879365b5949e9c9092076d120508 100644 (file)
@@ -323,10 +323,9 @@ static int send_bulk_static_data(struct snd_usb_midi_out_endpoint* ep,
                                 const void *data, int len)
 {
        int err;
-       void *buf = kmalloc(len, GFP_KERNEL);
+       void *buf = kmemdup(data, len, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
-       memcpy(buf, data, len);
        dump_urb("sending", buf, len);
        err = usb_bulk_msg(ep->umidi->chip->dev, ep->urb->pipe, buf, len,
                           NULL, 250);