Skip to contentSkip to conversation

use kmemdup rather than duplicating its implementation

PATCH Applied Andrzej Hajda 24 participants 79 messages Aug 7, 2015 – Sep 24, 2015 1 message not in the archive

Subsystems (43)
lore
Share & tools
lore
#0 lore raw

cover use kmemdup rather than duplicating its implementation

Hi,

This patchset was created using fixed version of memdup.cocci semantic patch [1]. It was compile tested only.

It is based on latest linux-next.

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Regards
Andrzej

Andrzej Hajda (31):
arch/arm/mach-lpc32xx: use kmemdup rather than duplicating its
implementation
arch/ia64/tioce: use kmemdup rather than duplicating its
implementation
arch/m68k/bootinfo: use kmemdup rather than duplicating its
implementation
arch/mips/bcm47xx: use kmemdup rather than duplicating its
implementation
arch/powerpc/nvram: use kmemdup rather than duplicating its
implementation
arch/powerpc/pseries: use kmemdup rather than duplicating its
implementation
arch/x86/microcode: use kmemdup rather than duplicating its
implementation
arch/x86/intel-mid: use kmemdup rather than duplicating its
implementation
crypto: use kmemdup rather than duplicating its implementation clk/mmp: use kmemdup rather than duplicating its implementation cpufreq/sfi: use kmemdup rather than duplicating its implementation drm/amdgpu: use kmemdup rather than duplicating its implementation
memstick: use kmemdup rather than duplicating its implementation message/fusion: use kmemdup rather than duplicating its implementation misc/vmw_vmci: use kmemdup rather than duplicating its implementation net/cavium/liquidio: use kmemdup rather than duplicating its
implementation
scsi/aacraid: use kmemdup rather than duplicating its implementation scsi/aic7xxx: use kmemdup rather than duplicating its implementation staging/lustre: use kmemdup rather than duplicating its implementation fs/cifs: use kmemdup rather than duplicating its implementation fs/dlm: use kmemdup rather than duplicating its implementation fs/ntfs: use kmemdup rather than duplicating its implementation fs/ocfs2: use kmemdup rather than duplicating its implementation fs/omfs: use kmemdup rather than duplicating its implementation fs/ubifs: use kmemdup rather than duplicating its implementation net/sched: use kmemdup rather than duplicating its implementation net/tipc: use kmemdup rather than duplicating its implementation net/xfrm: use kmemdup rather than duplicating its implementation sound/oxfw: use kmemdup rather than duplicating its implementation sound/atom: use kmemdup rather than duplicating its implementation sound/soc: use kmemdup rather than duplicating its implementation

 arch/arm/mach-lpc32xx/pm.c                           | 7 ++-----
 arch/ia64/sn/pci/tioce_provider.c                    | 4 ++--
 arch/m68k/kernel/bootinfo_proc.c                     | 4 +---
 arch/mips/bcm47xx/buttons.c                          | 3 +--
 arch/powerpc/kernel/nvram_64.c                       | 3 +--
 arch/powerpc/platforms/pseries/hotplug-memory.c      | 3 +--
 arch/x86/kernel/cpu/microcode/amd.c                  | 4 +---
 arch/x86/kernel/cpu/microcode/intel_early.c          | 4 +---
 arch/x86/platform/intel-mid/sfi.c                    | 3 +--
 crypto/echainiv.c                                    | 7 ++-----
 crypto/seqiv.c                                       | 6 ++----
 drivers/clk/mmp/clk-mix.c                            | 7 +++----
 drivers/cpufreq/sfi-cpufreq.c                        | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c           | 4 +---
 drivers/memstick/core/mspro_block.c                  | 3 +--
 drivers/message/fusion/mptbase.c                     | 3 +--
 drivers/misc/vmw_vmci/vmci_datagram.c                | 3 +--
 drivers/net/ethernet/cavium/liquidio/octeon_device.c | 4 +---
 drivers/scsi/aacraid/commctrl.c                      | 7 +++----
 drivers/scsi/aic7xxx/aic79xx_core.c                  | 4 ++--
 drivers/scsi/aic7xxx/aic7xxx_core.c                  | 4 ++--
 drivers/staging/lustre/lustre/obdclass/acl.c         | 6 ++----
 fs/cifs/smb2pdu.c                                    | 5 ++---
 fs/dlm/lowcomms.c                                    | 3 +--
 fs/ntfs/dir.c                                        | 7 +++----
 fs/ocfs2/localalloc.c                                | 6 ++----
 fs/omfs/inode.c                                      | 3 +--
 fs/ubifs/lpt.c                                       | 6 ++----
 fs/ubifs/tnc.c                                       | 3 +--
 net/sched/act_bpf.c                                  | 4 +---
 net/sched/cls_bpf.c                                  | 4 +---
 net/tipc/server.c                                    | 3 +--
 net/xfrm/xfrm_user.c                                 | 6 ++----
 sound/firewire/oxfw/oxfw-stream.c                    | 9 +++------
 sound/soc/intel/atom/sst/sst_ipc.c                   | 3 +--
 sound/soc/soc-topology.c                             | 6 +++---
 36 files changed, 57 insertions(+), 108 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/31 arch/arm/mach-lpc32xx: use kmemdup rather than duplicating its implementation

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/arm/mach-lpc32xx/pm.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-lpc32xx/pm.c +2 -5
index 207e812..dd3a432 100644
@@ -87,7 +87,8 @@ static int lpc32xx_pm_enter(suspend_state_t state)
 	void *iram_swap_area;
 
 	/* Allocate some space for temporary IRAM storage */
-	iram_swap_area = kmalloc(lpc32xx_sys_suspend_sz, GFP_KERNEL);
+	iram_swap_area = kmemdup((void *)TEMP_IRAM_AREA,
+				 lpc32xx_sys_suspend_sz, GFP_KERNEL);
 	if (!iram_swap_area) {
 		printk(KERN_ERR
 		       "PM Suspend: cannot allocate memory to save portion "
@@ -95,10 +96,6 @@ static int lpc32xx_pm_enter(suspend_state_t state)
 		return -ENOMEM;
 	}
 
-	/* Backup a small area of IRAM used for the suspend code */
-	memcpy(iram_swap_area, (void *) TEMP_IRAM_AREA,
-		lpc32xx_sys_suspend_sz);
-
 	/*
 	 * Copy code to suspend system into IRAM. The suspend code
 	 * needs to run from IRAM as DRAM may no longer be available
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 01/31] arch/arm/mach-lpc32xx: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 35 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/arm/mach-lpc32xx/pm.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-lpc32xx/pm.c +2 -5
index 207e812..dd3a432 100644
@@ -87,7 +87,8 @@ static int lpc32xx_pm_enter(suspend_state_t state)
 	void *iram_swap_area;
 
 	/* Allocate some space for temporary IRAM storage */
-	iram_swap_area = kmalloc(lpc32xx_sys_suspend_sz, GFP_KERNEL);
+	iram_swap_area = kmemdup((void *)TEMP_IRAM_AREA,
+				 lpc32xx_sys_suspend_sz, GFP_KERNEL);
 	if (!iram_swap_area) {
 		printk(KERN_ERR
 		       "PM Suspend: cannot allocate memory to save portion "
@@ -95,10 +96,6 @@ static int lpc32xx_pm_enter(suspend_state_t state)
 		return -ENOMEM;
 	}
 
-	/* Backup a small area of IRAM used for the suspend code */
-	memcpy(iram_swap_area, (void *) TEMP_IRAM_AREA,
-		lpc32xx_sys_suspend_sz);
-
 	/*
 	 * Copy code to suspend system into IRAM. The suspend code
 	 * needs to run from IRAM as DRAM may no longer be available
maintainer
#3 lore raw

Re: [PATCH 01/31] arch/arm/mach-lpc32xx: use kmemdup rather than duplicating its implementation

Quoted 14 lines · On Wednesday 16 September 2015 11:52:37 Andrzej Hajda wrote:
Quoted 14 lines
arch/arm/mach-lpc32xx/pm.c +2 -1
@@ -87,7 +87,8 @@ static int lpc32xx_pm_enter(suspend_state_t state)
      void *iram_swap_area;
 
      /* Allocate some space for temporary IRAM storage */
-     iram_swap_area = kmalloc(lpc32xx_sys_suspend_sz, GFP_KERNEL);
+     iram_swap_area = kmemdup((void *)TEMP_IRAM_AREA,
+                              lpc32xx_sys_suspend_sz, GFP_KERNEL);
      if (!iram_swap_area) {
              printk(KERN_ERR
                     "PM Suspend: cannot allocate memory to save portion "
@@ -95,10 +96,6 @@ static int lpc32xx_pm_enter(suspend_state_t state)
              return -ENOMEM;
      }
 
Quoted 4 lines

arch/arm/mach-lpc32xx/pm.c static int lpc32xx_pm_enter(suspend_state_t state) · line 100

Quoted 3 lines
arch/arm/mach-lpc32xx/pm.c +0 -3
-     /* Backup a small area of IRAM used for the suspend code */
-     memcpy(iram_swap_area, (void *) TEMP_IRAM_AREA,
-             lpc32xx_sys_suspend_sz);

Hmm, the patch looks correct in principle, but I think I'd rather leave the original version with the comment in place, because the source is not just random memory but instead some SRAM.

We might want to use memcpy_fromio()/memcpy_toio here and remove the cast for both copies instead.

Arnd

#4 lore raw

PATCH 2/31 arch/ia64/tioce: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/ia64/sn/pci/tioce_provider.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/ia64/sn/pci/tioce_provider.c +2 -2
index 46d3df4..2f13276 100644
@@ -1000,11 +1000,11 @@ tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont
 	 * Allocate kernel bus soft and copy from prom.
 	 */
 
-	tioce_common = kzalloc(sizeof(struct tioce_common), GFP_KERNEL);
+	tioce_common = kmemdup(prom_bussoft, sizeof(struct tioce_common),
+			       GFP_KERNEL);
 	if (!tioce_common)
 		return NULL;
 
-	memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common));
 	tioce_common->ce_pcibus.bs_base = (unsigned long)
 		ioremap(REGION_OFFSET(tioce_common->ce_pcibus.bs_base),
 			sizeof(struct tioce_common));
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH 02/31] arch/ia64/tioce: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 28 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/ia64/sn/pci/tioce_provider.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/ia64/sn/pci/tioce_provider.c +2 -2
index 46d3df4..2f13276 100644
@@ -1000,11 +1000,11 @@ tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont
 	 * Allocate kernel bus soft and copy from prom.
 	 */
 
-	tioce_common = kzalloc(sizeof(struct tioce_common), GFP_KERNEL);
+	tioce_common = kmemdup(prom_bussoft, sizeof(struct tioce_common),
+			       GFP_KERNEL);
 	if (!tioce_common)
 		return NULL;
 
-	memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common));
 	tioce_common->ce_pcibus.bs_base = (unsigned long)
 		ioremap(REGION_OFFSET(tioce_common->ce_pcibus.bs_base),
 			sizeof(struct tioce_common));
#6 lore raw

PATCH 3/31 arch/m68k/bootinfo: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/m68k/kernel/bootinfo_proc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/m68k/kernel/bootinfo_proc.c +1 -3
index 7ee853e..2a33a96 100644
@@ -62,12 +62,10 @@ static int __init init_bootinfo_procfs(void)
 	if (!bootinfo_size)
 		return -EINVAL;
 
-	bootinfo_copy = kmalloc(bootinfo_size, GFP_KERNEL);
+	bootinfo_copy = kmemdup(bootinfo_tmp, bootinfo_size, GFP_KERNEL);
 	if (!bootinfo_copy)
 		return -ENOMEM;
 
-	memcpy(bootinfo_copy, bootinfo_tmp, bootinfo_size);
-
 	pde = proc_create_data("bootinfo", 0400, NULL, &bootinfo_fops, NULL);
 	if (!pde) {
 		kfree(bootinfo_copy);
Signature · 1 line
1.9.1
#7 lore raw

PATCH 3/31 arch/m68k/bootinfo: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/m68k/kernel/bootinfo_proc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/m68k/kernel/bootinfo_proc.c +1 -3
index 7ee853e..2a33a96 100644
@@ -62,12 +62,10 @@ static int __init init_bootinfo_procfs(void)
 	if (!bootinfo_size)
 		return -EINVAL;
 
-	bootinfo_copy = kmalloc(bootinfo_size, GFP_KERNEL);
+	bootinfo_copy = kmemdup(bootinfo_tmp, bootinfo_size, GFP_KERNEL);
 	if (!bootinfo_copy)
 		return -ENOMEM;
 
-	memcpy(bootinfo_copy, bootinfo_tmp, bootinfo_size);
-
 	pde = proc_create_data("bootinfo", 0400, NULL, &bootinfo_fops, NULL);
 	if (!pde) {
 		kfree(bootinfo_copy);
Signature · 1 line
1.9.1
#8 lore raw

Re: [PATCH 03/31] arch/m68k/bootinfo: use kmemdup rather than duplicating its implementation

Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Thanks, will apply and queue for v4.3.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#9 lore raw

PATCH 4/31 arch/mips/bcm47xx: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/mips/bcm47xx/buttons.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/mips/bcm47xx/buttons.c +1 -2
index 08a4abf..52caa75 100644
@@ -396,10 +396,9 @@ static int __init bcm47xx_buttons_copy(const struct gpio_keys_button *buttons,
 {
 	size_t size = nbuttons * sizeof(*buttons);
 
-	bcm47xx_button_pdata.buttons = kmalloc(size, GFP_KERNEL);
+	bcm47xx_button_pdata.buttons = kmemdup(buttons, size, GFP_KERNEL);
 	if (!bcm47xx_button_pdata.buttons)
 		return -ENOMEM;
-	memcpy(bcm47xx_button_pdata.buttons, buttons, size);
 	bcm47xx_button_pdata.nbuttons = nbuttons;
 
 	return 0;
Signature · 1 line
1.9.1
#11 lore raw

PATCH 5/31 arch/powerpc/nvram: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/powerpc/kernel/nvram_64.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kernel/nvram_64.c +1 -2
index 1e703f8..6f6597b 100644
@@ -541,10 +541,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
 			time->tv_sec = be64_to_cpu(oops_hdr->timestamp);
 			time->tv_nsec = 0;
 		}
-		*buf = kmalloc(length, GFP_KERNEL);
+		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
 		if (*buf == NULL)
 			return -ENOMEM;
-		memcpy(*buf, buff + hdr_size, length);
 		kfree(buff);
 
 		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
Signature · 1 line
1.9.1
reviewer Applied
#13 lore raw

Re: [05/31] arch/powerpc/nvram: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda
Quoted 7 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/fc9e9cbf4e48f28525ed

cheers

#14 lore raw

PATCH 6/31 arch/powerpc/pseries: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/platforms/pseries/hotplug-memory.c +1 -2
index 0ced387..e9ff44c 100644
@@ -92,13 +92,12 @@ static struct property *dlpar_clone_drconf_property(struct device_node *dn)
 		return NULL;
 
 	new_prop->name = kstrdup(prop->name, GFP_KERNEL);
-	new_prop->value = kmalloc(prop->length, GFP_KERNEL);
+	new_prop->value = kmemdup(prop->value, prop->length, GFP_KERNEL);
 	if (!new_prop->name || !new_prop->value) {
 		dlpar_free_drconf_property(new_prop);
 		return NULL;
 	}
 
-	memcpy(new_prop->value, prop->value, prop->length);
 	new_prop->length = prop->length;
 
 	/* Convert the property to cpu endian-ness */
Signature · 1 line
1.9.1
reviewer Applied
#16 lore raw

Re: [06/31] arch/powerpc/pseries: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda
Quoted 7 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/2e16acc5ee3626bcd32e

cheers

#17 lore raw

PATCH 7/31 arch/x86/microcode: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/x86/kernel/cpu/microcode/amd.c         | 4 +---
 arch/x86/kernel/cpu/microcode/intel_early.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -3
index c7d2415..be37f10 100644
@@ -366,15 +366,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
 		return -EINVAL;
 	}
 
-	patch->data = kzalloc(patch_size, GFP_KERNEL);
+	patch->data = kmemdup(fw + SECTION_HDR_SIZE, patch_size, GFP_KERNEL);
 	if (!patch->data) {
 		pr_err("Patch data allocation failure.\n");
 		kfree(patch);
 		return -EINVAL;
 	}
 
-	/* All looks ok, copy patch... */
-	memcpy(patch->data, fw + SECTION_HDR_SIZE, patch_size);
 	INIT_LIST_HEAD(&patch->plist);
 	patch->patch_id  = mc_hdr->patch_id;
 	patch->equiv_cpu = proc_id;
arch/x86/kernel/cpu/microcode/intel_early.c +1 -3
index 37ea89c..3f843f1 100644
@@ -207,13 +207,11 @@ save_microcode(struct mc_saved_data *mc_saved_data,
 		mc_hdr = &mc->hdr;
 		size   = get_totalsize(mc_hdr);
 
-		saved_ptr[i] = kmalloc(size, GFP_KERNEL);
+		saved_ptr[i] = kmemdup(mc, size, GFP_KERNEL);
 		if (!saved_ptr[i]) {
 			ret = -ENOMEM;
 			goto err;
 		}
-
-		memcpy(saved_ptr[i], mc, size);
 	}
 
 	/*
Signature · 1 line
1.9.1
maintainer Applied
#18 lore raw

Re: [PATCH 07/31] arch/x86/microcode: use kmemdup rather than duplicating its implementation

Quoted 4 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

I dropped this footnote from the commit message as it seems that your fix is going to be integrated into memdup.cocci.

Quoted 5 lines
---
 arch/x86/kernel/cpu/microcode/amd.c         | 4 +---
 arch/x86/kernel/cpu/microcode/intel_early.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

Applied, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#19 lore raw

PATCH 8/31 arch/x86/intel-mid: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/x86/platform/intel-mid/sfi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/platform/intel-mid/sfi.c +1 -2
index ce992e8..5ee360a 100644
@@ -197,10 +197,9 @@ static int __init sfi_parse_gpio(struct sfi_table_header *table)
 	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
 	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-	gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
+	gpio_table = kmemdup(pentry, num * sizeof(*pentry), GFP_KERNEL);
 	if (!gpio_table)
 		return -1;
-	memcpy(gpio_table, pentry, num * sizeof(*pentry));
 	gpio_num_entry = num;
 
 	pr_debug("GPIO pin info:\n");
Signature · 1 line
1.9.1
#20 lore raw

Re: [PATCH 08/31] arch/x86/intel-mid: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 26 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/x86/platform/intel-mid/sfi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/platform/intel-mid/sfi.c +1 -2
index ce992e8..5ee360a 100644
@@ -197,10 +197,9 @@ static int __init sfi_parse_gpio(struct sfi_table_header *table)
 	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
 	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-	gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
+	gpio_table = kmemdup(pentry, num * sizeof(*pentry), GFP_KERNEL);
 	if (!gpio_table)
 		return -1;
-	memcpy(gpio_table, pentry, num * sizeof(*pentry));
 	gpio_num_entry = num;
 
 	pr_debug("GPIO pin info:\n");
#21 lore raw

[tip:x86/platform] arch/x86/intel-mid: Use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda
arch/x86/intel-mid: Use kmemdup rather than duplicating its implementation
Commit-ID:  c9e69c8c58eb8671e9f6cee728088e4c5abc9115
Gitweb:     http://git.kernel.org/tip/c9e69c8c58eb8671e9f6cee728088e4c5abc9115
Author:     Andrzej Hajda <[email protected]>
AuthorDate: Fri, 7 Aug 2015 09:59:14 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 17 Sep 2015 23:38:59 +0200

arch/x86/intel-mid: Use kmemdup rather than duplicating its implementation

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 arch/x86/platform/intel-mid/sfi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/platform/intel-mid/sfi.c +1 -2
index ce992e8..5ee360a 100644
@@ -197,10 +197,9 @@ static int __init sfi_parse_gpio(struct sfi_table_header *table)
 	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
 	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-	gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
+	gpio_table = kmemdup(pentry, num * sizeof(*pentry), GFP_KERNEL);
 	if (!gpio_table)
 		return -1;
-	memcpy(gpio_table, pentry, num * sizeof(*pentry));
 	gpio_num_entry = num;
 
 	pr_debug("GPIO pin info:\n");
#22 lore raw

PATCH 9/31 crypto: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 crypto/echainiv.c | 7 ++-----
 crypto/seqiv.c    | 6 ++----
 2 files changed, 4 insertions(+), 9 deletions(-)
crypto/echainiv.c +2 -5
index d3896c7..d8968c0 100644
@@ -134,13 +134,10 @@ static int echainiv_encrypt(struct aead_request *req)
 
 	if (unlikely(!IS_ALIGNED((unsigned long)info,
 				 crypto_aead_alignmask(geniv) + 1))) {
-		info = kmalloc(ivsize, req->base.flags &
-				       CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
-								  GFP_ATOMIC);
+		info = kmemdup(req->iv, ivsize,
+			       req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC);
 		if (!info)
 			return -ENOMEM;
-
-		memcpy(info, req->iv, ivsize);
 	}
 
 	aead_request_set_callback(subreq, req->base.flags, compl, data);
crypto/seqiv.c +2 -4
index 45d0563..eb83236 100644
@@ -362,13 +362,11 @@ static int seqiv_aead_encrypt(struct aead_request *req)
 
 	if (unlikely(!IS_ALIGNED((unsigned long)info,
 				 crypto_aead_alignmask(geniv) + 1))) {
-		info = kmalloc(ivsize, req->base.flags &
-				       CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
-								  GFP_ATOMIC);
+		info = kmemdup(req->iv, ivsize,
+			       req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC);
 		if (!info)
 			return -ENOMEM;
 
-		memcpy(info, req->iv, ivsize);
 		compl = seqiv_aead_encrypt_complete;
 		data = req;
 	}
Signature · 1 line
1.9.1
maintainer
#23 lore raw

Re: [PATCH 09/31] crypto: use kmemdup rather than duplicating its implementation

Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Actually I think you've identified a bug in the code.

Quoted 7 lines
crypto/echainiv.c +0 -0
index d3896c7..d8968c0 100644
@@ -134,13 +134,10 @@ static int echainiv_encrypt(struct aead_request *req)
 
 	if (unlikely(!IS_ALIGNED((unsigned long)info,

crypto/echainiv.c static int echainiv_encrypt(struct aead_request *req) · line 143

Quoted 10 lines
crypto/echainiv.c +2 -5
 				 crypto_aead_alignmask(geniv) + 1))) {
-		info = kmalloc(ivsize, req->base.flags &
-				       CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
-								  GFP_ATOMIC);
+		info = kmemdup(req->iv, ivsize,
+			       req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC);
 		if (!info)
 			return -ENOMEM;
-
-		memcpy(info, req->iv, ivsize);

This is meant to reallocate a buffer aligned to geniv but it isn't actually doing that.

So we should be changing it to align the pointer rather than converting it to memcpy.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#24 lore raw

PATCH 10/31 clk/mmp: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/clk/mmp/clk-mix.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/clk/mmp/clk-mix.c +3 -4
index 665cb67..3383410 100644
@@ -469,20 +469,20 @@ struct clk *mmp_clk_register_mix(struct device *dev,
 	memcpy(&mix->reg_info, &config->reg_info, sizeof(config->reg_info));
 	if (config->table) {
 		table_bytes = sizeof(*config->table) * config->table_size;
-		mix->table = kzalloc(table_bytes, GFP_KERNEL);
+		mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL);
 		if (!mix->table) {
 			pr_err("%s:%s: could not allocate mmp mix table\n",
 				__func__, name);
 			kfree(mix);
 			return ERR_PTR(-ENOMEM);
 		}
-		memcpy(mix->table, config->table, table_bytes);
 		mix->table_size = config->table_size;
 	}
 
 	if (config->mux_table) {
 		table_bytes = sizeof(u32) * num_parents;
-		mix->mux_table = kzalloc(table_bytes, GFP_KERNEL);
+		mix->mux_table = kmemdup(config->mux_table, table_bytes,
+					 GFP_KERNEL);
 		if (!mix->mux_table) {
 			pr_err("%s:%s: could not allocate mmp mix mux-table\n",
 				__func__, name);
@@ -490,7 +490,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,
 			kfree(mix);
 			return ERR_PTR(-ENOMEM);
 		}
-		memcpy(mix->mux_table, config->mux_table, table_bytes);
 	}
 
 	mix->div_flags = config->div_flags;
Signature · 1 line
1.9.1
Applied
#25 lore raw

Re: [PATCH 10/31] clk/mmp: use kmemdup rather than duplicating its implementation

Quoted 7 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#26 lore raw

PATCH 11/31 cpufreq/sfi: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/cpufreq/sfi-cpufreq.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/cpufreq/sfi-cpufreq.c +1 -3
index ffa3389..992ce6f 100644
@@ -45,12 +45,10 @@ static int sfi_parse_freq(struct sfi_table_header *table)
 	pentry = (struct sfi_freq_table_entry *)sb->pentry;
 	totallen = num_freq_table_entries * sizeof(*pentry);
 
-	sfi_cpufreq_array = kzalloc(totallen, GFP_KERNEL);
+	sfi_cpufreq_array = kmemdup(pentry, totallen, GFP_KERNEL);
 	if (!sfi_cpufreq_array)
 		return -ENOMEM;
 
-	memcpy(sfi_cpufreq_array, pentry, totallen);
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
maintainer Acked-by on v1 11/31
#27 lore raw

Re: [PATCH 11/31] cpufreq/sfi: use kmemdup rather than duplicating its implementation

Quoted 15 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/cpufreq/sfi-cpufreq.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/cpufreq/sfi-cpufreq.c +0 -0
index ffa3389..992ce6f 100644

drivers/cpufreq/sfi-cpufreq.c static int sfi_parse_freq(struct sfi_table_header *table) · line 53

Quoted 10 lines
drivers/cpufreq/sfi-cpufreq.c +1 -3
@@ -45,12 +45,10 @@ static int sfi_parse_freq(struct sfi_table_header *table)
 	pentry = (struct sfi_freq_table_entry *)sb->pentry;
 	totallen = num_freq_table_entries * sizeof(*pentry);
 
-	sfi_cpufreq_array = kzalloc(totallen, GFP_KERNEL);
+	sfi_cpufreq_array = kmemdup(pentry, totallen, GFP_KERNEL);
 	if (!sfi_cpufreq_array)
 		return -ENOMEM;
 
-	memcpy(sfi_cpufreq_array, pentry, totallen);
-
Signature · 1 line
viresh
#28 lore raw

PATCH 12/31 drm/amdgpu: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -3
index 8da6424..94bd992 100644
@@ -549,12 +549,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
 	if (metadata == NULL)
 		return -EINVAL;
 
-	buffer = kzalloc(metadata_size, GFP_KERNEL);
+	buffer = kmemdup(metadata, metadata_size, GFP_KERNEL);
 	if (buffer == NULL)
 		return -ENOMEM;
 
-	memcpy(buffer, metadata, metadata_size);
-
 	kfree(bo->metadata);
 	bo->metadata_flags = flags;
 	bo->metadata = buffer;
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#29 lore raw

Re: [PATCH 12/31] drm/amdgpu: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 18 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 8da6424..94bd992 100644
@@ -549,12 +549,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
 	if (metadata == NULL)
 		return -EINVAL;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata, · line 558

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -3
-	buffer = kzalloc(metadata_size, GFP_KERNEL);
+	buffer = kmemdup(metadata, metadata_size, GFP_KERNEL);
 	if (buffer == NULL)
 		return -ENOMEM;
 
-	memcpy(buffer, metadata, metadata_size);
-
 	kfree(bo->metadata);
 	bo->metadata_flags = flags;
 	bo->metadata = buffer;

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#30 lore raw

Re: [PATCH 12/31] drm/amdgpu: use kmemdup rather than duplicating its implementation

Quoted 12 lines · Andrzej Hajda

Ping.

Regards
Andrzej

Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Somehow missed that. Patch is Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

Quoted 26 lines
Quoted 12 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 8da6424..94bd992 100644
@@ -549,12 +549,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
  	if (metadata == NULL)
  		return -EINVAL;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata, · line 558

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -3
-	buffer = kzalloc(metadata_size, GFP_KERNEL);
+	buffer = kmemdup(metadata, metadata_size, GFP_KERNEL);
  	if (buffer == NULL)
  		return -ENOMEM;
 
-	memcpy(buffer, metadata, metadata_size);
-
  	kfree(bo->metadata);
  	bo->metadata_flags = flags;
  	bo->metadata = buffer;

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#31 lore raw

Re: [PATCH 12/31] drm/amdgpu: use kmemdup rather than duplicating its implementation

Quoted 12 lines · Christian König
Quoted 11 lines · Andrzej Hajda

Ping.

Regards
Andrzej

Quoted 4 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Somehow missed that. Patch is Reviewed-by: Christian König <[email protected]>.

I hadn't seen it either. Applied now.

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 19 lines
Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index 8da6424..94bd992 100644
@@ -549,12 +549,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo,
 void *metadata,
        if (metadata == NULL)
                return -EINVAL;
  -     buffer = kzalloc(metadata_size, GFP_KERNEL);
+       buffer = kmemdup(metadata, metadata_size, GFP_KERNEL);
        if (buffer == NULL)
                return -ENOMEM;
  -     memcpy(buffer, metadata, metadata_size);
-
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata, · line 558

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
        kfree(bo->metadata);
        bo->metadata_flags = flags;
        bo->metadata = buffer;

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#32 lore raw

PATCH 13/31 memstick: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/memstick/core/mspro_block.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/memstick/core/mspro_block.c +1 -2
index 922a750..1f1dd9b 100644
@@ -1033,12 +1033,11 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
 	}
 	msb->attr_group.name = "media_attributes";
 
-	buffer = kmalloc(attr_len, GFP_KERNEL);
+	buffer = kmemdup((char *)attr, attr_len, GFP_KERNEL);
 	if (!buffer) {
 		rc = -ENOMEM;
 		goto out_free_attr;
 	}
-	memcpy(buffer, (char *)attr, attr_len);
 
 	for (cnt = 0; cnt < attr_count; ++cnt) {
 		s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL);
Signature · 1 line
1.9.1
#33 lore raw

Re: [PATCH 13/31] memstick: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 28 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/memstick/core/mspro_block.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/memstick/core/mspro_block.c +1 -2
index 922a750..1f1dd9b 100644
@@ -1033,12 +1033,11 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
 	}
 	msb->attr_group.name = "media_attributes";
 
-	buffer = kmalloc(attr_len, GFP_KERNEL);
+	buffer = kmemdup((char *)attr, attr_len, GFP_KERNEL);
 	if (!buffer) {
 		rc = -ENOMEM;
 		goto out_free_attr;
 	}
-	memcpy(buffer, (char *)attr, attr_len);
 
 	for (cnt = 0; cnt < attr_count; ++cnt) {
 		s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL);
#34 lore raw

PATCH 14/31 message/fusion: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/message/fusion/mptbase.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +1 -2
index 5dcc031..1551f51 100644
@@ -5971,13 +5971,12 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
 	if (mpt_config(ioc, &cfg) != 0)
 		goto out;
 
-	mem = kmalloc(iocpage2sz, GFP_KERNEL);
+	mem = kmemdup((u8 *)pIoc2, iocpage2sz, GFP_KERNEL);
 	if (!mem) {
 		rc = -ENOMEM;
 		goto out;
 	}
 
-	memcpy(mem, (u8 *)pIoc2, iocpage2sz);
 	ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
 
 	mpt_read_ioc_pg_3(ioc);
Signature · 1 line
1.9.1
#35 lore raw

Re: [PATCH 14/31] message/fusion: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 29 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/message/fusion/mptbase.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/message/fusion/mptbase.c +1 -2
index 5dcc031..1551f51 100644
@@ -5971,13 +5971,12 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
 	if (mpt_config(ioc, &cfg) != 0)
 		goto out;
 
-	mem = kmalloc(iocpage2sz, GFP_KERNEL);
+	mem = kmemdup((u8 *)pIoc2, iocpage2sz, GFP_KERNEL);
 	if (!mem) {
 		rc = -ENOMEM;
 		goto out;
 	}
 
-	memcpy(mem, (u8 *)pIoc2, iocpage2sz);
 	ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
 
 	mpt_read_ioc_pg_3(ioc);
#36 lore raw

PATCH 15/31 misc/vmw_vmci: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/misc/vmw_vmci/vmci_datagram.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/vmw_vmci/vmci_datagram.c +1 -2
index 8226652..8a4b6bb 100644
@@ -276,11 +276,10 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg)
 		}
 
 		/* We make a copy to enqueue. */
-		new_dg = kmalloc(dg_size, GFP_KERNEL);
+		new_dg = kmemdup(dg, dg_size, GFP_KERNEL);
 		if (new_dg == NULL)
 			return VMCI_ERROR_NO_MEM;
 
-		memcpy(new_dg, dg, dg_size);
 		retval = vmci_ctx_enqueue_datagram(dg->dst.context, new_dg);
 		if (retval < VMCI_SUCCESS) {
 			kfree(new_dg);
Signature · 1 line
1.9.1
#37 lore raw

Re: [PATCH 15/31] misc/vmw_vmci: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 27 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/misc/vmw_vmci/vmci_datagram.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/vmw_vmci/vmci_datagram.c +1 -2
index 8226652..8a4b6bb 100644
@@ -276,11 +276,10 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg)
 		}
 
 		/* We make a copy to enqueue. */
-		new_dg = kmalloc(dg_size, GFP_KERNEL);
+		new_dg = kmemdup(dg, dg_size, GFP_KERNEL);
 		if (new_dg == NULL)
 			return VMCI_ERROR_NO_MEM;
 
-		memcpy(new_dg, dg, dg_size);
 		retval = vmci_ctx_enqueue_datagram(dg->dst.context, new_dg);
 		if (retval < VMCI_SUCCESS) {
 			kfree(new_dg);
#38 lore raw

PATCH 16/31 net/cavium/liquidio: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/net/ethernet/cavium/liquidio/octeon_device.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1 -3
index f67641a..8e23e3f 100644
@@ -602,12 +602,10 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data,
 	snprintf(oct->fw_info.liquidio_firmware_version, 32, "LIQUIDIO: %s",
 		 h->version);
 
-	buffer = kmalloc(size, GFP_KERNEL);
+	buffer = kmemdup(data, size, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
-	memcpy(buffer, data, size);
-
 	p = buffer + sizeof(struct octeon_firmware_file_header);
 
 	/* load all images */
Signature · 1 line
1.9.1
#39 lore raw

Re: [PATCH 16/31] net/cavium/liquidio: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 28 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/net/ethernet/cavium/liquidio/octeon_device.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1 -3
index f67641a..8e23e3f 100644
@@ -602,12 +602,10 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data,
 	snprintf(oct->fw_info.liquidio_firmware_version, 32, "LIQUIDIO: %s",
 		 h->version);
 
-	buffer = kmalloc(size, GFP_KERNEL);
+	buffer = kmemdup(data, size, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
-	memcpy(buffer, data, size);
-
 	p = buffer + sizeof(struct octeon_firmware_file_header);
 
 	/* load all images */
#40 lore raw

PATCH 17/31 scsi/aacraid: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/scsi/aacraid/commctrl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -4
index 54195a1..d2ed626 100644
@@ -635,15 +635,14 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 			}
 		} else {
 			struct user_sgmap* usg;
-			usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap), GFP_KERNEL);
+			usg = kmemdup(upsg,
+				      actual_fibsize - sizeof(struct aac_srb) + sizeof(struct sgmap),
+				      GFP_KERNEL);
 			if (!usg) {
 				dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
 				rcode = -ENOMEM;
 				goto cleanup;
 			}
-			memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap));
 			actual_fibsize = actual_fibsize64;
 
 			for (i = 0; i < usg->count; i++) {
Signature · 1 line
1.9.1
#41 lore raw

Re: [PATCH 17/31] scsi/aacraid: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 33 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/scsi/aacraid/commctrl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -4
index 54195a1..d2ed626 100644
@@ -635,15 +635,14 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 			}
 		} else {
 			struct user_sgmap* usg;
-			usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap), GFP_KERNEL);
+			usg = kmemdup(upsg,
+				      actual_fibsize - sizeof(struct aac_srb) + sizeof(struct sgmap),
+				      GFP_KERNEL);
 			if (!usg) {
 				dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
 				rcode = -ENOMEM;
 				goto cleanup;
 			}
-			memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap));
 			actual_fibsize = actual_fibsize64;
 
 			for (i = 0; i < usg->count; i++) {
#42 lore raw

PATCH 18/31 scsi/aic7xxx: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/scsi/aic7xxx/aic79xx_core.c | 4 ++--
 drivers/scsi/aic7xxx/aic7xxx_core.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +2 -2
index 109e2c9..8592448 100644
@@ -9494,10 +9494,10 @@ ahd_loadseq(struct ahd_softc *ahd)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahd->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahd->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahd->critical_sections == NULL)
 			panic("ahd_loadseq: Could not malloc");
-		memcpy(ahd->critical_sections, cs_table, cs_count);
 	}
 	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
 
drivers/scsi/aic7xxx/aic7xxx_core.c +2 -2
index c4829d8..3178730 100644
@@ -6940,10 +6940,10 @@ ahc_loadseq(struct ahc_softc *ahc)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahc->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahc->critical_sections == NULL)
 			panic("ahc_loadseq: Could not malloc");
-		memcpy(ahc->critical_sections, cs_table, cs_count);
 	}
 	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
 
Signature · 1 line
1.9.1
#43 lore raw

Re: [PATCH 18/31] scsi/aic7xxx: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 45 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/scsi/aic7xxx/aic79xx_core.c | 4 ++--
 drivers/scsi/aic7xxx/aic7xxx_core.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +2 -2
index 109e2c9..8592448 100644
@@ -9494,10 +9494,10 @@ ahd_loadseq(struct ahd_softc *ahd)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahd->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahd->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahd->critical_sections == NULL)
 			panic("ahd_loadseq: Could not malloc");
-		memcpy(ahd->critical_sections, cs_table, cs_count);
 	}
 	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
 
drivers/scsi/aic7xxx/aic7xxx_core.c +2 -2
index c4829d8..3178730 100644
@@ -6940,10 +6940,10 @@ ahc_loadseq(struct ahc_softc *ahc)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahc->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahc->critical_sections == NULL)
 			panic("ahc_loadseq: Could not malloc");
-		memcpy(ahc->critical_sections, cs_table, cs_count);
 	}
 	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
 
#44 lore raw

PATCH 19/31 staging/lustre: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 drivers/staging/lustre/lustre/obdclass/acl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/obdclass/acl.c +2 -4
index bc3fc47..933456c 100644
@@ -104,11 +104,10 @@ static int lustre_posix_acl_xattr_reduce_space(posix_acl_xattr_header **header,
 	if (unlikely(old_count <= new_count))
 		return old_size;
 
-	new = kzalloc(new_size, GFP_NOFS);
+	new = kmemdup(*header, new_size, GFP_NOFS);
 	if (unlikely(new == NULL))
 		return -ENOMEM;
 
-	memcpy(new, *header, new_size);
 	kfree(*header);
 	*header = new;
 	return new_size;
@@ -125,11 +124,10 @@ static int lustre_ext_acl_xattr_reduce_space(ext_acl_xattr_header **header,
 	if (unlikely(old_count <= ext_count))
 		return 0;
 
-	new = kzalloc(ext_size, GFP_NOFS);
+	new = kmemdup(*header, ext_size, GFP_NOFS);
 	if (unlikely(new == NULL))
 		return -ENOMEM;
 
-	memcpy(new, *header, ext_size);
 	kfree(*header);
 	*header = new;
 	return 0;
Signature · 1 line
1.9.1
#45 lore raw

PATCH 20/31 fs/cifs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/cifs/smb2pdu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +2 -3
index 070fb2a..2d6b72f 100644
@@ -1394,14 +1394,13 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 		goto ioctl_exit;
 	}
 
-	*out_data = kmalloc(*plen, GFP_KERNEL);
+	*out_data = kmemdup(rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
+			    *plen, GFP_KERNEL);
 	if (*out_data == NULL) {
 		rc = -ENOMEM;
 		goto ioctl_exit;
 	}
 
-	memcpy(*out_data, rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
-	       *plen);
 ioctl_exit:
 	free_rsp_buf(resp_buftype, rsp);
 	return rc;
Signature · 1 line
1.9.1
#46 lore raw

Re: [PATCH 20/31] fs/cifs: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 31 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/cifs/smb2pdu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +2 -3
index 070fb2a..2d6b72f 100644
@@ -1394,14 +1394,13 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 		goto ioctl_exit;
 	}
 
-	*out_data = kmalloc(*plen, GFP_KERNEL);
+	*out_data = kmemdup(rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
+			    *plen, GFP_KERNEL);
 	if (*out_data == NULL) {
 		rc = -ENOMEM;
 		goto ioctl_exit;
 	}
 
-	memcpy(*out_data, rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
-	       *plen);
 ioctl_exit:
 	free_rsp_buf(resp_buftype, rsp);
 	return rc;
#47 lore raw

Re: [PATCH 20/31] fs/cifs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

loooks reasonable to me - isn't this part of a larger patch series though? Did you want it merged distinctly into cifs-2.6.git?

Quoted 38 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/cifs/smb2pdu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +2 -4
index 070fb2a..2d6b72f 100644
@@ -1394,14 +1394,13 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
                goto ioctl_exit;
        }
 
-       *out_data = kmalloc(*plen, GFP_KERNEL);
+       *out_data = kmemdup(rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
+                           *plen, GFP_KERNEL);
        if (*out_data == NULL) {
                rc = -ENOMEM;
                goto ioctl_exit;
        }
 
-       memcpy(*out_data, rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
-              *plen);
 ioctl_exit:
        free_rsp_buf(resp_buftype, rsp);
        return rc;
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Thanks,

Steve
#48 lore raw

PATCH 21/31 fs/dlm: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/dlm/lowcomms.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/dlm/lowcomms.c +1 -2
index 754fd6c..b31b32a 100644
@@ -1317,10 +1317,9 @@ static void init_local(void)
 		if (dlm_our_addr(&sas, i))
 			break;
 
-		addr = kmalloc(sizeof(*addr), GFP_NOFS);
+		addr = kmemdup(&sas, sizeof(*addr), GFP_NOFS);
 		if (!addr)
 			break;
-		memcpy(addr, &sas, sizeof(*addr));
 		dlm_local_addr[dlm_local_count++] = addr;
 	}
 }
Signature · 1 line
1.9.1
#49 lore raw

Re: [PATCH 21/31] fs/dlm: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 26 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/dlm/lowcomms.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/dlm/lowcomms.c +1 -2
index 754fd6c..b31b32a 100644
@@ -1317,10 +1317,9 @@ static void init_local(void)
 		if (dlm_our_addr(&sas, i))
 			break;
 
-		addr = kmalloc(sizeof(*addr), GFP_NOFS);
+		addr = kmemdup(&sas, sizeof(*addr), GFP_NOFS);
 		if (!addr)
 			break;
-		memcpy(addr, &sas, sizeof(*addr));
 		dlm_local_addr[dlm_local_count++] = addr;
 	}
 }
#50 lore raw

PATCH 22/31 fs/ntfs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ntfs/dir.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -4
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
Signature · 1 line
1.9.1
#51 lore raw

Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 32 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ntfs/dir.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -4
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
#52 lore raw

Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

Hi Andrzej,

Thanks for your patch. It looks fine though I don't quite see the point of it to be honest.

It actually adds an additional function call (kmemdup() is not inline) just to save 1 line of source code in the driver and I don't think it improves readability or anything so why bother? What does it gain?

Best regards,

Anton

Quoted 36 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
fs/ntfs/dir.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -4
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
Signature · 1 line
1.9.1
Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer
#53 lore raw

Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation

Quoted 5 lines · Anton Altaparmakov

Hi Andrzej,

Thanks for your patch. It looks fine though I don't quite see the point of it to be honest.

It actually adds an additional function call (kmemdup() is not inline) just to save 1 line of source code in the driver and I don't think it improves readability or anything so why bother? What does it gain?

kmemdup replaces combo (kmalloc + memdup) with one call.
The patch follows quite common practice of abstracting out common patterns.

Regards
Andrzej

Quoted 41 lines

Best regards,

Anton

Quoted 36 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
fs/ntfs/dir.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -4
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#55 lore raw

Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation

Hi Andrzej,

Quoted 11 lines · Andrzej Hajda
Quoted 5 lines · Anton Altaparmakov

Hi Andrzej,

Thanks for your patch. It looks fine though I don't quite see the point of it to be honest.

It actually adds an additional function call (kmemdup() is not inline) just to save 1 line of source code in the driver and I don't think it improves readability or anything so why bother? What does it gain?

kmemdup replaces combo (kmalloc + memdup) with one call.
The patch follows quite common practice of abstracting out common patterns.

Sure it does I am just questioning the sanity of the practice... (-;

Such changes reduce the size of the kernel binary by a few bytes at the cost of adding CPU cycles to the execution time. How is that good thing? Unless you are on an embedded system desperate for RAM throwing away CPU cycles on pointless abstractions makes no sense to me...

But as I said patch is fine. Feel free to send it onto Andrew to get it into mainline. You can add my Acked-by: Anton Altaparmakoc <[email protected]> line to it when sending it. I am just saying that I think patches like that don't make much sense to me...

Best regards,

Anton

Quoted 44 lines

Regards
Andrzej

Quoted 41 lines

Best regards,

Anton

Quoted 36 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
fs/ntfs/dir.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -4
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
Signature · 1 line
1.9.1
Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer
#56 lore raw

Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation

Quoted 14 lines · Anton Altaparmakov

Hi Andrzej,

Quoted 9 lines · Andrzej Hajda
Quoted 5 lines · Anton Altaparmakov

Hi Andrzej,

Thanks for your patch. It looks fine though I don't quite see the point of it to be honest.

It actually adds an additional function call (kmemdup() is not inline) just to save 1 line of source code in the driver and I don't think it improves readability or anything so why bother? What does it gain?

Quoted 8 lines
Quoted 2 lines

kmemdup replaces combo (kmalloc + memdup) with one call.
The patch follows quite common practice of abstracting out common patterns.

Sure it does I am just questioning the sanity of the practice... (-;

Such changes reduce the size of the kernel binary by a few bytes at the cost of adding CPU cycles to the execution time. How is that good thing? Unless you are on an embedded system desperate for RAM throwing away CPU cycles on pointless abstractions makes no sense to me...

But as I said patch is fine. Feel free to send it onto Andrew to get it into mainline. You can add my Acked-by: Anton Altaparmakoc <[email protected]>

Altaparmakov even. Can't even spell my own surname... )-;

Quoted 42 lines

line to it when sending it. I am just saying that I think patches like that don't make much sense to me...

Best regards,

Anton

Quoted 36 lines

Regards
Andrzej

Quoted 33 lines

Best regards,

Anton

Quoted 28 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
fs/ntfs/dir.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +3 -1
index 9e38daf..2b7fef0 100644
@@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
 	 * map the mft record without deadlocking.
 	 */
 	rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-	ir = kmalloc(rc, GFP_NOFS);
+	/* Copy the index root value (it has been verified in read_inode). */
+	ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset),
+		     rc, GFP_NOFS);
 	if (unlikely(!ir)) {
 		err = -ENOMEM;
 		goto err_out;
 	}
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
fs/ntfs/dir.c +0 -3
-	/* Copy the index root value (it has been verified in read_inode). */
-	memcpy(ir, (u8*)ctx->attr +
-			le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
 	ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ndir);
 	ctx = NULL;
Signature · 1 line
1.9.1
Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer

Best regards,

Anton

Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer
#57 lore raw

PATCH 23/31 fs/ocfs2: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ocfs2/localalloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ocfs2/localalloc.c +2 -4
index 0a4457f..194d6d6 100644
@@ -434,12 +434,11 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
 	bh = osb->local_alloc_bh;
 	alloc = (struct ocfs2_dinode *) bh->b_data;
 
-	alloc_copy = kmalloc(bh->b_size, GFP_NOFS);
+	alloc_copy = kmemdup(alloc, bh->b_size, GFP_NOFS);
 	if (!alloc_copy) {
 		status = -ENOMEM;
 		goto out_commit;
 	}
-	memcpy(alloc_copy, alloc, bh->b_size);
 
 	status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode),
 					 bh, OCFS2_JOURNAL_ACCESS_WRITE);
@@ -1285,13 +1284,12 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
 	 * local alloc shutdown won't try to double free main bitmap
 	 * bits. Make a copy so the sync function knows which bits to
 	 * free. */
-	alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS);
+	alloc_copy = kmemdup(alloc, osb->local_alloc_bh->b_size, GFP_NOFS);
 	if (!alloc_copy) {
 		status = -ENOMEM;
 		mlog_errno(status);
 		goto bail;
 	}
-	memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size);
 
 	status = ocfs2_journal_access_di(handle,
 					 INODE_CACHE(local_alloc_inode),
Signature · 1 line
1.9.1
#58 lore raw

Re: [PATCH 23/31] fs/ocfs2: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 43 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ocfs2/localalloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ocfs2/localalloc.c +2 -4
index 0a4457f..194d6d6 100644
@@ -434,12 +434,11 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
 	bh = osb->local_alloc_bh;
 	alloc = (struct ocfs2_dinode *) bh->b_data;
 
-	alloc_copy = kmalloc(bh->b_size, GFP_NOFS);
+	alloc_copy = kmemdup(alloc, bh->b_size, GFP_NOFS);
 	if (!alloc_copy) {
 		status = -ENOMEM;
 		goto out_commit;
 	}
-	memcpy(alloc_copy, alloc, bh->b_size);
 
 	status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode),
 					 bh, OCFS2_JOURNAL_ACCESS_WRITE);
@@ -1285,13 +1284,12 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
 	 * local alloc shutdown won't try to double free main bitmap
 	 * bits. Make a copy so the sync function knows which bits to
 	 * free. */
-	alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS);
+	alloc_copy = kmemdup(alloc, osb->local_alloc_bh->b_size, GFP_NOFS);
 	if (!alloc_copy) {
 		status = -ENOMEM;
 		mlog_errno(status);
 		goto bail;
 	}
-	memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size);
 
 	status = ocfs2_journal_access_di(handle,
 					 INODE_CACHE(local_alloc_inode),
#59 lore raw

PATCH 24/31 fs/omfs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/omfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/omfs/inode.c +1 -2
index 3d935c8..02af1a3 100644
@@ -333,12 +333,11 @@ static int omfs_get_imap(struct super_block *sb)
 		bh = sb_bread(sb, block++);
 		if (!bh)
 			goto nomem_free;
-		*ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
+		*ptr = kmemdup(bh->b_data, sb->s_blocksize, GFP_KERNEL);
 		if (!*ptr) {
 			brelse(bh);
 			goto nomem_free;
 		}
-		memcpy(*ptr, bh->b_data, sb->s_blocksize);
 		if (count < sb->s_blocksize)
 			memset((void *)*ptr + count, 0xff,
 				sb->s_blocksize - count);
Signature · 1 line
1.9.1
maintainer Acked-by on v1 24/31
#60 lore raw

Re: [PATCH 24/31] fs/omfs: use kmemdup rather than duplicating its implementation

Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Thanks -

Signature · 1 line
Bob Copeland %% http://bobcopeland.com/
#61 lore raw

Re: [PATCH 24/31] fs/omfs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

Ping.

Regards
Andrzej

Quoted 28 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/omfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/omfs/inode.c +1 -2
index 3d935c8..02af1a3 100644
@@ -333,12 +333,11 @@ static int omfs_get_imap(struct super_block *sb)
 		bh = sb_bread(sb, block++);
 		if (!bh)
 			goto nomem_free;
-		*ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
+		*ptr = kmemdup(bh->b_data, sb->s_blocksize, GFP_KERNEL);
 		if (!*ptr) {
 			brelse(bh);
 			goto nomem_free;
 		}
-		memcpy(*ptr, bh->b_data, sb->s_blocksize);
 		if (count < sb->s_blocksize)
 			memset((void *)*ptr + count, 0xff,
 				sb->s_blocksize - count);
#62 lore raw

PATCH 25/31 fs/ubifs: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ubifs/lpt.c | 6 ++----
 fs/ubifs/tnc.c | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
fs/ubifs/lpt.c +2 -4
index dc9f27e..9a51710 100644
@@ -1498,11 +1498,10 @@ static struct ubifs_nnode *dirty_cow_nnode(struct ubifs_info *c,
 	}
 
 	/* nnode is being committed, so copy it */
-	n = kmalloc(sizeof(struct ubifs_nnode), GFP_NOFS);
+	n = kmemdup(nnode, sizeof(struct ubifs_nnode), GFP_NOFS);
 	if (unlikely(!n))
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(n, nnode, sizeof(struct ubifs_nnode));
 	n->cnext = NULL;
 	__set_bit(DIRTY_CNODE, &n->flags);
 	__clear_bit(COW_CNODE, &n->flags);
@@ -1549,11 +1548,10 @@ static struct ubifs_pnode *dirty_cow_pnode(struct ubifs_info *c,
 	}
 
 	/* pnode is being committed, so copy it */
-	p = kmalloc(sizeof(struct ubifs_pnode), GFP_NOFS);
+	p = kmemdup(pnode, sizeof(struct ubifs_pnode), GFP_NOFS);
 	if (unlikely(!p))
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(p, pnode, sizeof(struct ubifs_pnode));
 	p->cnext = NULL;
 	__set_bit(DIRTY_CNODE, &p->flags);
 	__clear_bit(COW_CNODE, &p->flags);
fs/ubifs/tnc.c +1 -2
index 957f575..fa9a20c 100644
@@ -198,11 +198,10 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c,
 {
 	struct ubifs_znode *zn;
 
-	zn = kmalloc(c->max_znode_sz, GFP_NOFS);
+	zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS);
 	if (unlikely(!zn))
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(zn, znode, c->max_znode_sz);
 	zn->cnext = NULL;
 	__set_bit(DIRTY_ZNODE, &zn->flags);
 	__clear_bit(COW_ZNODE, &zn->flags);
Signature · 1 line
1.9.1
Reviewed-by on v1 25/31
#63 lore raw

Re: [PATCH 25/31] fs/ubifs: use kmemdup rather than duplicating its implementation

Quoted 48 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 fs/ubifs/lpt.c | 6 ++----
 fs/ubifs/tnc.c | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
fs/ubifs/lpt.c +2 -4
index dc9f27e..9a51710 100644
@@ -1498,11 +1498,10 @@ static struct ubifs_nnode *dirty_cow_nnode(struct ubifs_info *c,
        }
 
        /* nnode is being committed, so copy it */
-       n = kmalloc(sizeof(struct ubifs_nnode), GFP_NOFS);
+       n = kmemdup(nnode, sizeof(struct ubifs_nnode), GFP_NOFS);
        if (unlikely(!n))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(n, nnode, sizeof(struct ubifs_nnode));
        n->cnext = NULL;
        __set_bit(DIRTY_CNODE, &n->flags);
        __clear_bit(COW_CNODE, &n->flags);
@@ -1549,11 +1548,10 @@ static struct ubifs_pnode *dirty_cow_pnode(struct ubifs_info *c,
        }
 
        /* pnode is being committed, so copy it */
-       p = kmalloc(sizeof(struct ubifs_pnode), GFP_NOFS);
+       p = kmemdup(pnode, sizeof(struct ubifs_pnode), GFP_NOFS);
        if (unlikely(!p))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(p, pnode, sizeof(struct ubifs_pnode));
        p->cnext = NULL;
        __set_bit(DIRTY_CNODE, &p->flags);
        __clear_bit(COW_CNODE, &p->flags);
fs/ubifs/tnc.c +0 -0
index 957f575..fa9a20c 100644
@@ -198,11 +198,10 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c,
 {
        struct ubifs_znode *zn;

fs/ubifs/tnc.c static struct ubifs_znode *copy_znode(struct ubifs_info *c, · line 207

Quoted 10 lines
fs/ubifs/tnc.c +1 -2
 
-       zn = kmalloc(c->max_znode_sz, GFP_NOFS);
+       zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS);
        if (unlikely(!zn))
                return ERR_PTR(-ENOMEM);
 
-       memcpy(zn, znode, c->max_znode_sz);
        zn->cnext = NULL;
        __set_bit(DIRTY_ZNODE, &zn->flags);
        __clear_bit(COW_ZNODE, &zn->flags);
Signature · 2 lines
Thanks,
//richard
#65 lore raw

PATCH 26/31 net/sched: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 net/sched/act_bpf.c | 4 +---
 net/sched/cls_bpf.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
net/sched/act_bpf.c +1 -3
index 1b97dab..5c0fa03 100644
@@ -190,12 +190,10 @@ static int tcf_bpf_init_from_ops(struct nlattr **tb, struct tcf_bpf_cfg *cfg)
 	if (bpf_size != nla_len(tb[TCA_ACT_BPF_OPS]))
 		return -EINVAL;
 
-	bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
+	bpf_ops = kmemdup(nla_data(tb[TCA_ACT_BPF_OPS]), bpf_size, GFP_KERNEL);
 	if (bpf_ops == NULL)
 		return -ENOMEM;
 
-	memcpy(bpf_ops, nla_data(tb[TCA_ACT_BPF_OPS]), bpf_size);
-
 	fprog_tmp.len = bpf_num_ops;
 	fprog_tmp.filter = bpf_ops;
 
net/sched/cls_bpf.c +1 -3
index e5168f8..423f774 100644
@@ -212,12 +212,10 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb,
 	if (bpf_size != nla_len(tb[TCA_BPF_OPS]))
 		return -EINVAL;
 
-	bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
+	bpf_ops = kmemdup(nla_data(tb[TCA_BPF_OPS]), bpf_size, GFP_KERNEL);
 	if (bpf_ops == NULL)
 		return -ENOMEM;
 
-	memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
-
 	fprog_tmp.len = bpf_num_ops;
 	fprog_tmp.filter = bpf_ops;
 
Signature · 1 line
1.9.1
maintainer Acked-by on v1 26/31
#66 lore raw

Re: [PATCH 26/31] net/sched: use kmemdup rather than duplicating its implementation

Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Not sure where the rest of this series went, but if you want this patch to be routed via net-next tree (which I recommend, to avoid cross tree conflicts), then you would need to send these patches separately, rebased to that tree, and also mention [PATCH net-next XX/YY] in the subject.

                                      ^^^^^^^^

Thanks,
Daniel

#67 lore raw

PATCH 27/31 net/tipc: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 net/tipc/server.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/tipc/server.c +1 -2
index 922e04a..c187cad 100644
@@ -411,13 +411,12 @@ static struct outqueue_entry *tipc_alloc_entry(void *data, int len)
 	if (!entry)
 		return NULL;
 
-	buf = kmalloc(len, GFP_ATOMIC);
+	buf = kmemdup(data, len, GFP_ATOMIC);
 	if (!buf) {
 		kfree(entry);
 		return NULL;
 	}
 
-	memcpy(buf, data, len);
 	entry->iov.iov_base = buf;
 	entry->iov.iov_len = len;
 
Signature · 1 line
1.9.1
#68 lore raw

Re: [PATCH 27/31] net/tipc: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

Quoted 29 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 net/tipc/server.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/tipc/server.c +1 -2
index 922e04a..c187cad 100644
@@ -411,13 +411,12 @@ static struct outqueue_entry *tipc_alloc_entry(void *data, int len)
 	if (!entry)
 		return NULL;
 
-	buf = kmalloc(len, GFP_ATOMIC);
+	buf = kmemdup(data, len, GFP_ATOMIC);
 	if (!buf) {
 		kfree(entry);
 		return NULL;
 	}
 
-	memcpy(buf, data, len);
 	entry->iov.iov_base = buf;
 	entry->iov.iov_len = len;
 
Acked-by
#69 lore raw

RE: [PATCH 27/31] net/tipc: use kmemdup rather than duplicating its implementation

///jon

Quoted 45 lines

-----Original Message-----
From: Andrzej Hajda [mailto:[email protected]]
Sent: Wednesday, 16 September, 2015 06:07
To: Jon Maloy; Ying Xue
Cc: Bartlomiej Zolnierkiewicz; Marek Szyprowski; linux- [email protected]; David S. Miller; [email protected]
Subject: Re: [PATCH 27/31] net/tipc: use kmemdup rather than duplicating its implementation

Ping.

Regards
Andrzej

net/tipc/server.c static struct outqueue_entry

Quoted 15 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 net/tipc/server.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/tipc/server.c index renamed from net/tipc/server.c +0 -0

922e04a..c187cad 100644

net/tipc/server.c +0 -0
@@ -411,13 +411,12 @@ static struct outqueue_entry

*tipc_alloc_entry(void *data, int len)

Quoted 14 lines
net/tipc/server.c +1 -2
 	if (!entry)
 		return NULL;
 
-	buf = kmalloc(len, GFP_ATOMIC);
+	buf = kmemdup(data, len, GFP_ATOMIC);
 	if (!buf) {
 		kfree(entry);
 		return NULL;
 	}
 
-	memcpy(buf, data, len);
 	entry->iov.iov_base = buf;
 	entry->iov.iov_len = len;
 
Reviewed-by on v1 27/31
#70 lore raw

Re: [PATCH 27/31] net/tipc: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda
Quoted 6 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Quoted 24 lines
---
 net/tipc/server.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/tipc/server.c +1 -2
index 922e04a..c187cad 100644
@@ -411,13 +411,12 @@ static struct outqueue_entry *tipc_alloc_entry(void *data, int len)
 	if (!entry)
 		return NULL;
 
-	buf = kmalloc(len, GFP_ATOMIC);
+	buf = kmemdup(data, len, GFP_ATOMIC);
 	if (!buf) {
 		kfree(entry);
 		return NULL;
 	}
 
-	memcpy(buf, data, len);
 	entry->iov.iov_base = buf;
 	entry->iov.iov_len = len;
 
#71 lore raw

PATCH 28/31 net/xfrm: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 net/xfrm/xfrm_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/xfrm/xfrm_user.c +2 -4
index 0cebf1f..a8de9e3 100644
@@ -925,12 +925,10 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
 			return err;
 
 		if (attrs[XFRMA_ADDRESS_FILTER]) {
-			filter = kmalloc(sizeof(*filter), GFP_KERNEL);
+			filter = kmemdup(nla_data(attrs[XFRMA_ADDRESS_FILTER]),
+					 sizeof(*filter), GFP_KERNEL);
 			if (filter == NULL)
 				return -ENOMEM;
-
-			memcpy(filter, nla_data(attrs[XFRMA_ADDRESS_FILTER]),
-			       sizeof(*filter));
 		}
 
 		if (attrs[XFRMA_PROTO])
Signature · 1 line
1.9.1
#73 lore raw

PATCH 29/31 sound/oxfw: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 sound/firewire/oxfw/oxfw-stream.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/firewire/oxfw/oxfw-stream.c +3 -6
index 873d40f..77ad5b9 100644
@@ -512,12 +512,11 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
 	if (err < 0)
 		goto end;
 
-	formats[eid] = kmalloc(*len, GFP_KERNEL);
+	formats[eid] = kmemdup(buf, *len, GFP_KERNEL);
 	if (formats[eid] == NULL) {
 		err = -ENOMEM;
 		goto end;
 	}
-	memcpy(formats[eid], buf, *len);
 
 	/* apply the format for each available sampling rate */
 	for (i = 0; i < ARRAY_SIZE(oxfw_rate_table); i++) {
@@ -531,12 +530,11 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
 			continue;
 
 		eid++;
-		formats[eid] = kmalloc(*len, GFP_KERNEL);
+		formats[eid] = kmemdup(buf, *len, GFP_KERNEL);
 		if (formats[eid] == NULL) {
 			err = -ENOMEM;
 			goto end;
 		}
-		memcpy(formats[eid], buf, *len);
 		formats[eid][2] = avc_stream_rate_table[i];
 	}
 
@@ -594,12 +592,11 @@ static int fill_stream_formats(struct snd_oxfw *oxfw,
 		if (err < 0)
 			break;
 
-		formats[eid] = kmalloc(len, GFP_KERNEL);
+		formats[eid] = kmemdup(buf, len, GFP_KERNEL);
 		if (formats[eid] == NULL) {
 			err = -ENOMEM;
 			break;
 		}
-		memcpy(formats[eid], buf, len);
 
 		/* get next entry */
 		len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
Signature · 1 line
1.9.1
Applied
#74 lore raw

Re: [alsa-devel] [PATCH 29/31] sound/oxfw: use kmemdup rather than duplicating its implementation

Quoted 7 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Applied, thanks.

Takashi

Quoted 58 lines
---
 sound/firewire/oxfw/oxfw-stream.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/firewire/oxfw/oxfw-stream.c +3 -6
index 873d40f..77ad5b9 100644
@@ -512,12 +512,11 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
 	if (err < 0)
 		goto end;
 
-	formats[eid] = kmalloc(*len, GFP_KERNEL);
+	formats[eid] = kmemdup(buf, *len, GFP_KERNEL);
 	if (formats[eid] == NULL) {
 		err = -ENOMEM;
 		goto end;
 	}
-	memcpy(formats[eid], buf, *len);
 
 	/* apply the format for each available sampling rate */
 	for (i = 0; i < ARRAY_SIZE(oxfw_rate_table); i++) {
@@ -531,12 +530,11 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
 			continue;
 
 		eid++;
-		formats[eid] = kmalloc(*len, GFP_KERNEL);
+		formats[eid] = kmemdup(buf, *len, GFP_KERNEL);
 		if (formats[eid] == NULL) {
 			err = -ENOMEM;
 			goto end;
 		}
-		memcpy(formats[eid], buf, *len);
 		formats[eid][2] = avc_stream_rate_table[i];
 	}
 
@@ -594,12 +592,11 @@ static int fill_stream_formats(struct snd_oxfw *oxfw,
 		if (err < 0)
 			break;
 
-		formats[eid] = kmalloc(len, GFP_KERNEL);
+		formats[eid] = kmemdup(buf, len, GFP_KERNEL);
 		if (formats[eid] == NULL) {
 			err = -ENOMEM;
 			break;
 		}
-		memcpy(formats[eid], buf, len);
 
 		/* get next entry */
 		len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
Signature · 6 lines
1.9.1

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#75 lore raw

PATCH 30/31 sound/atom: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 sound/soc/intel/atom/sst/sst_ipc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/atom/sst/sst_ipc.c +1 -2
index 5a27861..3dc7358 100644
@@ -352,10 +352,9 @@ void sst_process_reply_mrfld(struct intel_sst_drv *sst_drv_ctx,
 	 * copy from mailbox
 	 **/
 	if (msg_high.part.large) {
-		data = kzalloc(msg_low, GFP_KERNEL);
+		data = kmemdup((void *)msg->mailbox_data, msg_low, GFP_KERNEL);
 		if (!data)
 			return;
-		memcpy(data, (void *) msg->mailbox_data, msg_low);
 		/* Copy command id so that we can use to put sst to reset */
 		dsp_hdr = (struct ipc_dsp_hdr *)data;
 		cmd_id = dsp_hdr->cmd_id;
Signature · 1 line
1.9.1
maintainer
#76 lore raw

Re: [PATCH 30/31] sound/atom: use kmemdup rather than duplicating its implementation

Quoted 5 lines · Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Applied, but please make an effort to use subject lines reflecting the style for the subsysetem and if you're sending a patch series make sure that at least the cover letter goes to everyone or (if there are no interdependencies as is the case here) just send them individually. That way people can tell what's going on in terms of dependencies.

maintainer
#77 lore raw

Applied "ASoC: intel: use kmemdup rather than duplicating its implementation" to the asoc tree

In reply to Andrzej Hajda

The patch

ASoC: intel: use kmemdup rather than duplicating its implementation

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From b42e093e59c320e91b9c2de73bf3f0429fc45307 Mon Sep 17 00:00:00 2001

From: Andrzej Hajda <[email protected]>
Date: Fri, 7 Aug 2015 09:59:36 +0200
Subject: [PATCH] ASoC: intel: use kmemdup rather than duplicating its
implementation

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 sound/soc/intel/atom/sst/sst_ipc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/atom/sst/sst_ipc.c +1 -2
index 5a27861..3dc7358 100644
@@ -352,10 +352,9 @@ void sst_process_reply_mrfld(struct intel_sst_drv *sst_drv_ctx,
 	 * copy from mailbox
 	 **/
 	if (msg_high.part.large) {
-		data = kzalloc(msg_low, GFP_KERNEL);
+		data = kmemdup((void *)msg->mailbox_data, msg_low, GFP_KERNEL);
 		if (!data)
 			return;
-		memcpy(data, (void *) msg->mailbox_data, msg_low);
 		/* Copy command id so that we can use to put sst to reset */
 		dsp_hdr = (struct ipc_dsp_hdr *)data;
 		cmd_id = dsp_hdr->cmd_id;
Signature · 1 line
2.5.0
#78 lore raw

PATCH 31/31 sound/soc: use kmemdup rather than duplicating its implementation

In reply to Andrzej Hajda

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 sound/soc/soc-topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/soc-topology.c +3 -3
index 4dadb5e..a5da91b 100644
@@ -831,12 +831,12 @@ static int soc_tplg_denum_create_values(struct soc_enum *se,
 	if (ec->items > sizeof(*ec->values))
 		return -EINVAL;
 
-	se->dobj.control.dvalues =
-		kmalloc(ec->items * sizeof(u32), GFP_KERNEL);
+	se->dobj.control.dvalues = kmemdup(ec->values,
+					   ec->items * sizeof(u32),
+					   GFP_KERNEL);
 	if (!se->dobj.control.dvalues)
 		return -ENOMEM;
 
-	memcpy(se->dobj.control.dvalues, ec->values, ec->items * sizeof(u32));
 	return 0;
 }
 
Signature · 1 line
1.9.1
maintainer
#79 lore raw

Applied "ASoC: topology: use kmemdup rather than duplicating its implementation" to the asoc tree

The patch

ASoC: topology: use kmemdup rather than duplicating its implementation

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 376c0afe2f0047d091956a95e382e1edd104ea72 Mon Sep 17 00:00:00 2001

From: Andrzej Hajda <[email protected]>
Date: Fri, 7 Aug 2015 09:59:37 +0200
Subject: [PATCH] ASoC: topology: use kmemdup rather than duplicating its
implementation

The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

---
 sound/soc/soc-topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/soc-topology.c +3 -3
index f038c6e..8620dbf 100644
@@ -832,12 +832,12 @@ static int soc_tplg_denum_create_values(struct soc_enum *se,
 	if (ec->items > sizeof(*ec->values))
 		return -EINVAL;
 
-	se->dobj.control.dvalues =
-		kmalloc(ec->items * sizeof(u32), GFP_KERNEL);
+	se->dobj.control.dvalues = kmemdup(ec->values,
+					   ec->items * sizeof(u32),
+					   GFP_KERNEL);
 	if (!se->dobj.control.dvalues)
 		return -ENOMEM;
 
-	memcpy(se->dobj.control.dvalues, ec->values, ec->items * sizeof(u32));
 	return 0;
 }
 
Signature · 1 line
2.5.0