android_kernel_samsung_msm8976/include
Alexey Dobriyan 1a2f67b459 [PATCH] kmemdup: introduce
One of idiomatic ways to duplicate a region of memory is

	dst = kmalloc(len, GFP_KERNEL);
	if (!dst)
		return -ENOMEM;
	memcpy(dst, src, len);

which is neat code except a programmer needs to write size twice.  Which
sometimes leads to mistakes.  If len passed to kmalloc is smaller that len
passed to memcpy, it's straight overwrite-beyond-end.  If len passed to
memcpy is smaller than len passed to kmalloc, it's either a) legit
behaviour ;-), or b) cloned buffer will contain garbage in second half.

Slight trolling of commit lists shows several duplications bugs
done exactly because of diverged lenghts:

	Linux:
		[CRYPTO]: Fix memcpy/memset args.
		[PATCH] memcpy/memset fixes
	OpenBSD:
		kerberosV/src/lib/asn1: der_copy.c:1.4

If programmer is given only one place to play with lengths, I believe, such
mistakes could be avoided.

With kmemdup, the snippet above will be rewritten as:

	dst = kmemdup(src, len, GFP_KERNEL);
	if (!dst)
		return -ENOMEM;

This also leads to smaller code (kzalloc effect). Quick grep shows
200+ places where kmemdup() can be used.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-10-01 00:39:19 -07:00
..
acpi
asm-alpha
asm-arm [PATCH] simplify update_times (avoid jiffies/jiffies_64 aliasing problem) 2006-09-29 09:18:15 -07:00
asm-arm26 [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-avr32
asm-cris
asm-frv [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-generic [PATCH] Let WARN_ON/WARN_ON_ONCE return the condition 2006-09-29 09:18:06 -07:00
asm-h8300 [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-i386 [PATCH] x86: Clean up x86 NMI sysctls 2006-09-30 01:47:55 +02:00
asm-ia64 Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6 2006-09-27 10:53:30 -07:00
asm-m32r [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-m68k [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-m68knommu [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-mips [MIPS] s/__ASSEMBLER__/__ASSEMBLY__/ for clarity sake. 2006-09-27 13:37:57 +01:00
asm-parisc
asm-powerpc [PATCH] Let WARN_ON/WARN_ON_ONCE return the condition 2006-09-29 09:18:06 -07:00
asm-ppc
asm-s390 [PATCH] Make touch_nmi_watchdog imply touch_softlockup_watchdog on all archs 2006-09-29 09:18:05 -07:00
asm-sh Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh-2.6 2006-09-27 08:49:07 -07:00
asm-sh64 [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-sparc
asm-sparc64
asm-um [PATCH] uml: remove pte_mkexec 2006-09-29 09:18:04 -07:00
asm-v850 [PATCH] consistently use MAX_ERRNO in __syscall_return 2006-09-27 08:26:18 -07:00
asm-x86_64 [PATCH] Use early clobber in semaphores 2006-09-30 01:47:55 +02:00
asm-xtensa
crypto
keys
linux [PATCH] kmemdup: introduce 2006-10-01 00:39:19 -07:00
math-emu
media Merge master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb 2006-09-30 09:39:15 -07:00
mtd
net [NetLabel]: audit fixups due to delayed feedback 2006-09-29 17:05:05 -07:00
pcmcia
rdma
rxrpc
scsi [PATCH] scsi: device_reprobe() can fail 2006-09-30 19:33:43 -07:00
sound [PATCH] maximum latency tracking: ALSA support 2006-10-01 00:39:19 -07:00
video
Kbuild