projects
/
openwrt
/
staging
/
blogic.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
a451751
)
lib/scatterlist: error handling in __sg_alloc_table()
author
Dan Carpenter
<
[email protected]
>
Mon, 8 Jul 2013 23:01:58 +0000
(16:01 -0700)
committer
Linus Torvalds
<
[email protected]
>
Tue, 9 Jul 2013 17:33:31 +0000
(10:33 -0700)
I was reviewing code which I suspected might allocate a zero size SG
table. That will cause memory corruption. Also we can't return before
doing the memset or we could end up using uninitialized memory in the
cleanup path.
Signed-off-by: Dan Carpenter <
[email protected]
>
Cc: Akinobu Mita <
[email protected]
>
Cc: Imre Deak <
[email protected]
>
Cc: Tejun Heo <
[email protected]
>
Cc: Daniel Vetter <
[email protected]
>
Cc: Maxim Levitsky <
[email protected]
>
Signed-off-by: Andrew Morton <
[email protected]
>
Signed-off-by: Linus Torvalds <
[email protected]
>
lib/scatterlist.c
patch
|
blob
|
history
diff --git
a/lib/scatterlist.c
b/lib/scatterlist.c
index 129a82f707df9b08d7c8e777561fca30c579816c..a685c8a79578b274cb361d442b953507e58d7d63 100644
(file)
--- a/
lib/scatterlist.c
+++ b/
lib/scatterlist.c
@@
-247,13
+247,15
@@
int __sg_alloc_table(struct sg_table *table, unsigned int nents,
struct scatterlist *sg, *prv;
unsigned int left;
+ memset(table, 0, sizeof(*table));
+
+ if (nents == 0)
+ return -EINVAL;
#ifndef ARCH_HAS_SG_CHAIN
if (WARN_ON_ONCE(nents > max_ents))
return -EINVAL;
#endif
- memset(table, 0, sizeof(*table));
-
left = nents;
prv = NULL;
do {