[PATCH] media: rc: Use bsearch library function
Replace self coded binary search, by existing library version. Signed-off-by: Thomas Meyer <tho...@m3y3r.de> --- drivers/media/rc/rc-main.c | 34 -- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 981cccd6b988..d3d6537867fb 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -460,6 +461,18 @@ static int ir_setkeytable(struct rc_dev *dev, return rc; } +static int rc_map_cmp(const void *key, const void *elt) +{ + unsigned int scancode = *(unsigned int *) key; + struct rc_map_table *e = (struct rc_map_table *) elt; + + if (e->scancode > scancode) + return -1; + else if (e->scancode < scancode) + return 1; + return 0; +} + /** * ir_lookup_by_scancode() - locate mapping by scancode * @rc_map:the struct rc_map to search @@ -472,21 +485,14 @@ static int ir_setkeytable(struct rc_dev *dev, static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map, unsigned int scancode) { - int start = 0; - int end = rc_map->len - 1; - int mid; - - while (start <= end) { - mid = (start + end) / 2; - if (rc_map->scan[mid].scancode < scancode) - start = mid + 1; - else if (rc_map->scan[mid].scancode > scancode) - end = mid - 1; - else - return mid; - } + struct rc_map_table *res; - return -1U; + res = bsearch(, rc_map->scan, rc_map->len, + sizeof(struct rc_map_table), rc_map_cmp); + if (res == NULL) + return -1U; + else + return res - rc_map->scan; } /** -- 2.11.0
[PATCH 10/10] staging/atomisp: Use ARRAY_SIZE macro
Use ARRAY_SIZE macro, rather than explicitly coding some variant of it yourself. Found with: find -type f -name "*.c" -o -name "*.h" | xargs perl -p -i -e 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\ /\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\) /ARRAY_SIZE(\1)/g' and manual check/verification. Signed-off-by: Thomas Meyer <tho...@m3y3r.de> --- diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c index a7c6bba7e094..11d3995ba0db 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c @@ -29,6 +29,7 @@ more details. #endif #include "system_global.h" +#include #ifdef USE_INPUT_SYSTEM_VERSION_2 @@ -487,7 +488,7 @@ static void ifmtr_set_if_blocking_mode( { int i; bool block[] = { false, false, false, false }; - assert(N_INPUT_FORMATTER_ID <= (sizeof(block) / sizeof(block[0]))); + assert(N_INPUT_FORMATTER_ID <= (ARRAY_SIZE(block))); #if !defined(IS_ISP_2400_SYSTEM) #error "ifmtr_set_if_blocking_mode: ISP_SYSTEM must be one of {IS_ISP_2400_SYSTEM}"
[PATCH 5/10] [media] lgdt3306a: Use ARRAY_SIZE macro
Use ARRAY_SIZE macro, rather than explicitly coding some variant of it yourself. Found with: find -type f -name "*.c" -o -name "*.h" | xargs perl -p -i -e 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\ /\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\) /ARRAY_SIZE(\1)/g' and manual check/verification. Signed-off-by: Thomas Meyer <tho...@m3y3r.de> --- diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c index c9b1eb38444e..724e9aac0f11 100644 --- a/drivers/media/dvb-frontends/lgdt3306a.c +++ b/drivers/media/dvb-frontends/lgdt3306a.c @@ -19,6 +19,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include "dvb_math.h" #include "lgdt3306a.h" @@ -2072,7 +2073,7 @@ static const short regtab[] = { 0x30aa, /* MPEGLOCK */ }; -#define numDumpRegs (sizeof(regtab)/sizeof(regtab[0])) +#define numDumpRegs (ARRAY_SIZE(regtab)) static u8 regval1[numDumpRegs] = {0, }; static u8 regval2[numDumpRegs] = {0, };
[PATCH] dma-buf: Cocci spatch ptr_ret.spatch
Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -680,10 +680,7 @@ int dma_buf_debugfs_create_file(const ch d = debugfs_create_file(name, S_IRUGO, dma_buf_debugfs_dir, write, dma_buf_debug_fops); - if (IS_ERR(d)) - return PTR_ERR(d); - - return 0; + return PTR_RET(d); } #else static inline int dma_buf_init_debugfs(void) -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] media: Cocci spatch ptr_ret.spatch
Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c --- a/drivers/media/platform/sh_veu.c +++ b/drivers/media/platform/sh_veu.c @@ -359,10 +359,7 @@ static int sh_veu_context_init(struct sh veu-m2m_ctx = v4l2_m2m_ctx_init(veu-m2m_dev, veu, sh_veu_queue_init); - if (IS_ERR(veu-m2m_ctx)) - return PTR_ERR(veu-m2m_ctx); - - return 0; + return PTR_RET(veu-m2m_ctx); } static int sh_veu_querycap(struct file *file, void *priv, -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] PVRUSB2: Cocci spatch memdup.spatch
Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c --- a/drivers/media/usb/pvrusb2/pvrusb2-io.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c @@ -354,9 +354,9 @@ static int pvr2_stream_buffer_count(stru if (scnt sp-buffer_slot_count) { struct pvr2_buffer **nb = NULL; if (scnt) { - nb = kmalloc(scnt * sizeof(*nb),GFP_KERNEL); + nb = kmemdup(sp-buffers, scnt * sizeof(*nb), +GFP_KERNEL); if (!nb) return -ENOMEM; - memcpy(nb,sp-buffers,scnt * sizeof(*nb)); } kfree(sp-buffers); sp-buffers = nb; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] v4l: s5p-tv: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107 Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/s5p-tv/hdmi_drv.c b/drivers/media/video/s5p-tv/hdmi_drv.c --- a/drivers/media/video/s5p-tv/hdmi_drv.c 2011-11-13 11:07:31.380232715 +0100 +++ b/drivers/media/video/s5p-tv/hdmi_drv.c 2011-11-28 19:58:21.305922829 +0100 @@ -838,8 +838,8 @@ static int hdmi_resources_init(struct hd dev_err(dev, failed to get clock 'hdmiphy'\n); goto fail; } - res-regul_bulk = kzalloc(ARRAY_SIZE(supply) * - sizeof res-regul_bulk[0], GFP_KERNEL); + res-regul_bulk = kcalloc(ARRAY_SIZE(supply), + sizeof(res-regul_bulk[0]), GFP_KERNEL); if (!res-regul_bulk) { dev_err(dev, failed to get memory for regulators\n); goto fail; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] uvcvideo: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107 Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c --- a/drivers/media/video/uvc/uvc_ctrl.c 2011-11-28 19:36:47.613437745 +0100 +++ b/drivers/media/video/uvc/uvc_ctrl.c 2011-11-28 19:58:26.309317018 +0100 @@ -1861,7 +1861,7 @@ int uvc_ctrl_init_device(struct uvc_devi if (ncontrols == 0) continue; - entity-controls = kzalloc(ncontrols * sizeof(*ctrl), + entity-controls = kcalloc(ncontrols, sizeof(*ctrl), GFP_KERNEL); if (entity-controls == NULL) return -ENOMEM; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] xc4000: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107 Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/common/tuners/tuner-xc2028.c b/drivers/media/common/tuners/tuner-xc2028.c --- a/drivers/media/common/tuners/tuner-xc2028.c 2011-11-13 11:07:28.453519914 +0100 +++ b/drivers/media/common/tuners/tuner-xc2028.c 2011-11-28 19:57:19.631625147 +0100 @@ -311,7 +311,7 @@ static int load_all_firmwares(struct dvb n_array, fname, name, priv-firm_version 8, priv-firm_version 0xff); - priv-firm = kzalloc(sizeof(*priv-firm) * n_array, GFP_KERNEL); + priv-firm = kcalloc(n_array, sizeof(*priv-firm), GFP_KERNEL); if (priv-firm == NULL) { tuner_err(Not enough memory to load firmware file.\n); rc = -ENOMEM; diff -u -p a/drivers/media/common/tuners/xc4000.c b/drivers/media/common/tuners/xc4000.c --- a/drivers/media/common/tuners/xc4000.c 2011-11-13 11:07:28.460186686 +0100 +++ b/drivers/media/common/tuners/xc4000.c 2011-11-28 19:57:16.224893821 +0100 @@ -758,7 +758,7 @@ static int xc4000_fwupload(struct dvb_fr n_array, fname, name, priv-firm_version 8, priv-firm_version 0xff); - priv-firm = kzalloc(sizeof(*priv-firm) * n_array, GFP_KERNEL); + priv-firm = kcalloc(n_array, sizeof(*priv-firm), GFP_KERNEL); if (priv-firm == NULL) { printk(KERN_ERR Not enough memory to load firmware file.\n); rc = -ENOMEM; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] v4l2-ctrls: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107 Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c --- a/drivers/media/video/stk-webcam.c 2011-11-13 11:07:31.543568623 +0100 +++ b/drivers/media/video/stk-webcam.c 2011-11-28 19:58:06.822415120 +0100 @@ -377,8 +377,8 @@ static int stk_prepare_iso(struct stk_ca if (dev-isobufs) STK_ERROR(isobufs already allocated. Bad\n); else - dev-isobufs = kzalloc(MAX_ISO_BUFS * sizeof(*dev-isobufs), - GFP_KERNEL); + dev-isobufs = kcalloc(MAX_ISO_BUFS, sizeof(*dev-isobufs), + GFP_KERNEL); if (dev-isobufs == NULL) { STK_ERROR(Unable to allocate iso buffers\n); return -ENOMEM; diff -u -p a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c --- a/drivers/media/video/v4l2-ctrls.c 2011-11-28 19:36:47.613437745 +0100 +++ b/drivers/media/video/v4l2-ctrls.c 2011-11-28 19:58:10.342457254 +0100 @@ -1108,8 +1108,8 @@ int v4l2_ctrl_handler_init(struct v4l2_c INIT_LIST_HEAD(hdl-ctrls); INIT_LIST_HEAD(hdl-ctrl_refs); hdl-nr_of_buckets = 1 + nr_of_controls_hint / 8; - hdl-buckets = kzalloc(sizeof(hdl-buckets[0]) * hdl-nr_of_buckets, - GFP_KERNEL); + hdl-buckets = kcalloc(hdl-nr_of_buckets, sizeof(hdl-buckets[0]), + GFP_KERNEL); hdl-error = hdl-buckets ? 0 : -ENOMEM; return hdl-error; } -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] pvrusb2: Use kcalloc instead of kzalloc to allocate array
The advantage of kcalloc is, that will prevent integer overflows which could result from the multiplication of number of elements and size and it is also a bit nicer to read. The semantic patch that makes this change is available in https://lkml.org/lkml/2011/11/25/107 Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c --- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c 2011-11-13 11:07:30.836890817 +0100 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c 2011-11-28 19:57:31.228511987 +0100 @@ -2546,8 +2546,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct } /* Define and configure additional controls from cx2341x module. */ - hdw-mpeg_ctrl_info = kzalloc( - sizeof(*(hdw-mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL); + hdw-mpeg_ctrl_info = kcalloc(MPEGDEF_COUNT, + sizeof(*(hdw-mpeg_ctrl_info)), + GFP_KERNEL); if (!hdw-mpeg_ctrl_info) goto fail; for (idx = 0; idx MPEGDEF_COUNT; idx++) { cptr = hdw-controls + idx + CTRLDEF_COUNT; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] drxd: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/dvb/frontends/drxd_hard.c b/drivers/media/dvb/frontends/drxd_hard.c --- a/drivers/media/dvb/frontends/drxd_hard.c 2011-11-07 19:37:48.623295422 +0100 +++ b/drivers/media/dvb/frontends/drxd_hard.c 2011-11-08 10:48:49.317800208 +0100 @@ -914,14 +914,13 @@ static int load_firmware(struct drxd_sta return -EIO; } - state-microcode = kmalloc(fw-size, GFP_KERNEL); + state-microcode = kmemdup(fw-data, fw-size, GFP_KERNEL); if (state-microcode == NULL) { release_firmware(fw); printk(KERN_ERR drxd: firmware load failure: no memory\n); return -ENOMEM; } - memcpy(state-microcode, fw-data, fw-size); state-microcode_length = fw-size; release_firmware(fw); return 0; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] dw2102: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c --- a/drivers/media/dvb/dvb-usb/dw2102.c 2011-11-07 19:37:48.086620605 +0100 +++ b/drivers/media/dvb/dvb-usb/dw2102.c 2011-11-08 10:48:56.977902892 +0100 @@ -1859,12 +1859,11 @@ static struct dvb_usb_device_properties static int dw2102_probe(struct usb_interface *intf, const struct usb_device_id *id) { - p1100 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL); + p1100 = kmemdup(s6x0_properties, + sizeof(struct dvb_usb_device_properties), GFP_KERNEL); if (!p1100) return -ENOMEM; /* copy default structure */ - memcpy(p1100, s6x0_properties, - sizeof(struct dvb_usb_device_properties)); /* fill only different fields */ p1100-firmware = dvb-usb-p1100.fw; p1100-devices[0] = d1100; @@ -1872,13 +1871,12 @@ static int dw2102_probe(struct usb_inter p1100-rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table); p1100-adapter-fe[0].frontend_attach = stv0288_frontend_attach; - s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL); + s660 = kmemdup(s6x0_properties, + sizeof(struct dvb_usb_device_properties), GFP_KERNEL); if (!s660) { kfree(p1100); return -ENOMEM; } - memcpy(s660, s6x0_properties, - sizeof(struct dvb_usb_device_properties)); s660-firmware = dvb-usb-s660.fw; s660-num_device_descs = 3; s660-devices[0] = d660; @@ -1886,14 +1884,13 @@ static int dw2102_probe(struct usb_inter s660-devices[2] = d480_2; s660-adapter-fe[0].frontend_attach = ds3000_frontend_attach; - p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL); + p7500 = kmemdup(s6x0_properties, + sizeof(struct dvb_usb_device_properties), GFP_KERNEL); if (!p7500) { kfree(p1100); kfree(s660); return -ENOMEM; } - memcpy(p7500, s6x0_properties, - sizeof(struct dvb_usb_device_properties)); p7500-firmware = dvb-usb-p7500.fw; p7500-devices[0] = d7500; p7500-rc.legacy.rc_map_table = rc_map_tbs_table; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] v4l: Casting (void *) value returned by kmalloc is useless
The semantic patch that makes this change is available in scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci. Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/vino.c b/drivers/media/video/vino.c --- a/drivers/media/video/vino.c 2011-11-07 19:37:51.673341747 +0100 +++ b/drivers/media/video/vino.c 2011-11-08 09:05:04.618617718 +0100 @@ -708,7 +708,7 @@ static int vino_allocate_buffer(struct v size, count); /* allocate memory for table with virtual (page) addresses */ - fb-desc_table.virtual = (unsigned long *) + fb-desc_table.virtual = kmalloc(count * sizeof(unsigned long), GFP_KERNEL); if (!fb-desc_table.virtual) return -ENOMEM; -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] cx25821: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/cx25821/cx25821-audio-upstream.c b/drivers/media/video/cx25821/cx25821-audio-upstream.c --- a/drivers/media/video/cx25821/cx25821-audio-upstream.c 2011-11-07 19:37:49.746645818 +0100 +++ b/drivers/media/video/cx25821/cx25821-audio-upstream.c 2011-11-08 10:47:22.883308220 +0100 @@ -739,25 +739,22 @@ int cx25821_audio_upstream_init(struct c 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, diff -u -p a/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c --- a/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c 2011-11-07 19:37:49.756645970 +0100 +++ b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c 2011-11-08 10:47:21.626624708 +0100 @@ -761,22 +761,18 @@ int cx25821_vidupstream_init_ch2(struct 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 */ diff -u -p a/drivers/media/video/cx25821/cx25821-video-upstream.c b/drivers/media/video/cx25821/cx25821-video-upstream.c --- a/drivers/media/video/cx25821/cx25821-video-upstream.c 2011-11-07 19:37:49.756645970 +0100 +++ b/drivers/media/video/cx25821/cx25821-video-upstream.c 2011-11-08 10:47:22.036630204 +0100 @@ -816,20 +816,18 @@ int cx25821_vidupstream_init_ch1(struct 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 */ -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] pwc: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer tho...@m3y3r.de --- diff -u -p a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c --- a/drivers/media/video/pwc/pwc-ctrl.c 2011-11-07 19:37:51.14699 +0100 +++ b/drivers/media/video/pwc/pwc-ctrl.c 2011-11-08 10:47:00.679677247 +0100 @@ -113,10 +113,9 @@ static int _send_control_msg(struct pwc_ void *kbuf = NULL; if (buflen) { - kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */ + kbuf = kmemdup(buf, buflen, GFP_KERNEL); /* not allowed on stack */ if (kbuf == NULL) return -ENOMEM; - memcpy(kbuf, buf, buflen); } rc = usb_control_msg(pdev-udev, usb_sndctrlpipe(pdev-udev, 0), -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html