[media] cx25821: Use kmemdup rather than duplicating its implementation
authorThomas Meyer <thomas@m3y3r.de>
Thu, 17 Nov 2011 22:12:18 +0000 (19:12 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Thu, 24 Nov 2011 23:08:01 +0000 (21:08 -0200)
The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/cx25821/cx25821-audio-upstream.c
drivers/media/video/cx25821/cx25821-video-upstream-ch2.c
drivers/media/video/cx25821/cx25821-video-upstream.c

index 4dc2a241335c7e34bcda30e7a8bff16be3d22b59..20c7ca3351a8df7399d05af0a850867e32140662 100644 (file)
@@ -733,25 +733,22 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
 
        if (dev->input_audiofilename) {
                str_length = strlen(dev->input_audiofilename);
-               dev->_audiofilename = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_audiofilename = kmemdup(dev->input_audiofilename,
+                                             str_length + 1, GFP_KERNEL);
 
                if (!dev->_audiofilename)
                        goto error;
 
-               memcpy(dev->_audiofilename, dev->input_audiofilename,
-                      str_length + 1);
-
                /* Default if filename is empty string */
                if (strcmp(dev->input_audiofilename, "") == 0)
                        dev->_audiofilename = "/root/audioGOOD.wav";
        } else {
                str_length = strlen(_defaultAudioName);
-               dev->_audiofilename = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_audiofilename = kmemdup(_defaultAudioName,
+                                             str_length + 1, GFP_KERNEL);
 
                if (!dev->_audiofilename)
                        goto error;
-
-               memcpy(dev->_audiofilename, _defaultAudioName, str_length + 1);
        }
 
        retval = cx25821_sram_channel_setup_upstream_audio(dev, sram_ch,
index 6401ce8be0f5434bde5fbe27cd1b078e63ff8f24..5a157cf4a95e38ca8b8f7800f01267ad85d14569 100644 (file)
@@ -747,22 +747,18 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
 
        if (dev->input_filename_ch2) {
                str_length = strlen(dev->input_filename_ch2);
-               dev->_filename_ch2 = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_filename_ch2 = kmemdup(dev->input_filename_ch2,
+                                            str_length + 1, GFP_KERNEL);
 
                if (!dev->_filename_ch2)
                        goto error;
-
-               memcpy(dev->_filename_ch2, dev->input_filename_ch2,
-                      str_length + 1);
        } else {
                str_length = strlen(dev->_defaultname_ch2);
-               dev->_filename_ch2 = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_filename_ch2 = kmemdup(dev->_defaultname_ch2,
+                                            str_length + 1, GFP_KERNEL);
 
                if (!dev->_filename_ch2)
                        goto error;
-
-               memcpy(dev->_filename_ch2, dev->_defaultname_ch2,
-                      str_length + 1);
        }
 
        /* Default if filename is empty string */
index 103226320518f4f5973bb1f165be98acb05675df..21e7d657f049b21daa20d7ab6ef620304946dd4b 100644 (file)
@@ -794,20 +794,18 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
 
        if (dev->input_filename) {
                str_length = strlen(dev->input_filename);
-               dev->_filename = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_filename = kmemdup(dev->input_filename, str_length + 1,
+                                        GFP_KERNEL);
 
                if (!dev->_filename)
                        goto error;
-
-               memcpy(dev->_filename, dev->input_filename, str_length + 1);
        } else {
                str_length = strlen(dev->_defaultname);
-               dev->_filename = kmalloc(str_length + 1, GFP_KERNEL);
+               dev->_filename = kmemdup(dev->_defaultname, str_length + 1,
+                                        GFP_KERNEL);
 
                if (!dev->_filename)
                        goto error;
-
-               memcpy(dev->_filename, dev->_defaultname, str_length + 1);
        }
 
        /* Default if filename is empty string */