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
..
2006-09-26 17:40:24 -04:00
2006-09-28 18:02:59 -07:00
2006-09-28 18:03:03 -07:00
2006-09-27 08:26:18 -07:00
2006-09-30 20:52:31 +02:00
2006-09-28 18:01:21 -07:00
2006-09-27 11:58:52 -07:00
2006-09-26 17:43:53 -07:00
2006-09-28 17:53:58 -07:00
2006-09-29 17:13:24 -07:00
2006-09-29 17:05:05 -07:00
2006-09-30 20:29:42 +02:00
2006-09-30 20:52:33 +02:00
2006-09-30 20:29:43 +02:00
2006-09-26 08:48:45 -07:00
2006-09-30 20:52:31 +02:00
2006-09-27 08:26:14 -07:00
2006-09-30 20:52:31 +02:00
2006-09-29 09:18:20 -07:00
2006-09-26 08:49:03 -07:00
2006-09-26 08:48:59 -07:00
2006-09-29 09:18:21 -07:00
2006-09-29 09:18:20 -07:00
2006-09-29 09:18:10 -07:00
2006-09-29 09:18:09 -07:00
2006-09-27 08:26:19 -07:00
2006-09-30 20:52:31 +02:00
2006-09-26 08:48:54 -07:00
2006-09-26 08:48:56 -07:00
2006-09-27 08:26:18 -07:00
2006-09-28 18:02:08 -07:00
2006-09-30 20:52:28 +02:00
2006-09-27 08:26:10 -07:00
2006-09-30 20:52:29 +02:00
2006-09-27 08:26:09 -07:00
2006-09-29 09:18:12 -07:00
2006-09-30 20:52:31 +02:00
2006-09-29 09:18:24 -07:00
2006-09-30 20:52:31 +02:00
2006-09-30 01:47:55 +02:00
2006-09-27 08:26:12 -07:00
2006-09-26 17:40:24 -04:00
2006-09-26 08:48:46 -07:00
2006-09-29 09:18:15 -07:00
2006-09-26 15:38:51 -07:00
2006-09-26 15:38:52 -07:00
2006-09-30 09:36:56 -07:00
2006-09-26 15:38:52 -07:00
2006-09-28 18:02:18 -07:00
2006-09-28 18:02:13 -07:00
2006-09-28 18:02:50 -07:00
2006-09-28 18:02:50 -07:00
2006-09-28 18:02:02 -07:00
2006-09-28 18:02:31 -07:00
2006-09-28 18:01:57 -07:00
2006-09-28 18:02:29 -07:00
2006-09-28 18:01:05 -07:00
2006-09-27 08:26:17 -07:00
2006-09-29 09:18:20 -07:00
2006-09-28 17:54:01 -07:00
2006-09-28 18:02:30 -07:00
2006-09-26 08:48:53 -07:00
2006-09-29 09:18:03 -07:00
2006-09-28 18:02:51 -07:00
2006-09-27 08:26:12 -07:00
2006-10-01 00:39:19 -07:00
2006-09-29 09:18:13 -07:00
2006-09-29 09:18:05 -07:00
2006-09-29 09:18:08 -07:00
2006-09-29 09:18:06 -07:00
2006-10-01 00:39:18 -07:00
2006-10-01 00:39:18 -07:00
2006-09-26 08:48:47 -07:00
2006-09-27 08:26:12 -07:00
2006-10-01 00:39:18 -07:00
2006-09-27 08:26:13 -07:00
2006-09-27 08:26:19 -07:00
2006-09-29 09:18:23 -07:00
2006-09-30 20:52:31 +02:00
2006-09-28 18:02:22 -07:00
2006-09-29 09:18:12 -07:00
2006-09-29 09:18:08 -07:00
2006-09-28 18:02:58 -07:00
2006-09-27 08:26:20 -07:00
2006-09-29 09:18:05 -07:00
2006-09-29 09:18:03 -07:00
2006-09-26 08:48:48 -07:00
2006-09-29 17:06:23 -07:00
2006-09-26 17:43:52 -07:00
2006-10-01 00:39:17 -07:00
2006-09-26 17:43:53 -07:00
2006-09-29 09:18:02 -07:00
2006-09-27 08:26:19 -07:00
2006-09-29 09:18:15 -07:00
2006-09-27 08:26:14 -07:00
2006-09-29 09:18:16 -07:00
2006-09-30 20:52:18 +02:00
2006-09-30 20:26:56 +02:00
2006-09-29 09:18:11 -07:00
2006-09-29 09:18:11 -07:00
2006-09-30 20:52:28 +02:00
2006-09-29 09:18:11 -07:00
2006-09-26 08:49:04 -07:00
2006-09-26 08:48:44 -07:00
2006-09-28 18:02:50 -07:00
2006-09-30 20:31:20 +02:00
2006-09-29 09:18:06 -07:00
2006-09-29 09:18:11 -07:00
2006-09-26 08:48:52 -07:00
2006-09-29 09:18:24 -07:00
2006-09-27 08:26:11 -07:00
2006-09-27 08:26:18 -07:00
2006-09-26 08:48:56 -07:00
2006-09-29 09:18:19 -07:00
2006-09-29 09:18:20 -07:00
2006-10-01 00:39:18 -07:00
2006-10-01 00:39:19 -07:00
2006-09-26 08:49:02 -07:00
2006-09-26 08:48:58 -07:00
2006-09-29 09:18:03 -07:00
2006-09-26 13:07:55 -07:00
2006-09-28 18:02:05 -07:00
2006-09-28 17:53:59 -07:00
2006-09-30 20:52:18 +02:00
2006-10-01 00:39:18 -07:00
2006-09-27 08:26:20 -07:00
2006-09-28 18:02:16 -07:00
2006-09-27 11:58:54 -07:00
2006-09-28 15:36:46 -07:00
2006-09-27 08:26:13 -07:00
2006-09-29 09:18:13 -07:00
2006-09-29 09:18:12 -07:00
2006-09-30 20:52:26 +02:00
2006-09-28 18:02:42 -07:00