diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-11-23 09:09:15 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-11-24 14:16:43 -0500 |
commit | bba14de98753cb6599a2dae0e520714b2153522d (patch) | |
tree | b771ef780aa0808d3eb7827d527920c07215c4fa | |
parent | 456b61bca8ee324ab6c18b065e632c9a8c88aa39 (diff) |
scm: lower SCM_MAX_FD
Lower SCM_MAX_FD from 255 to 253 so that allocations for scm_fp_list are
halved. (commit f8d570a4 added two pointers in this structure)
scm_fp_dup() should not copy whole structure (and trigger kmemcheck
warnings), but only the used part. While we are at it, only allocate
needed size.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/scm.h | 5 | ||||
-rw-r--r-- | net/core/scm.c | 10 |
2 files changed, 9 insertions, 6 deletions
diff --git a/include/net/scm.h b/include/net/scm.h index 31656506d967..745460fa2f02 100644 --- a/include/net/scm.h +++ b/include/net/scm.h | |||
@@ -10,11 +10,12 @@ | |||
10 | /* Well, we should have at least one descriptor open | 10 | /* Well, we should have at least one descriptor open |
11 | * to accept passed FDs 8) | 11 | * to accept passed FDs 8) |
12 | */ | 12 | */ |
13 | #define SCM_MAX_FD 255 | 13 | #define SCM_MAX_FD 253 |
14 | 14 | ||
15 | struct scm_fp_list { | 15 | struct scm_fp_list { |
16 | struct list_head list; | 16 | struct list_head list; |
17 | int count; | 17 | short count; |
18 | short max; | ||
18 | struct file *fp[SCM_MAX_FD]; | 19 | struct file *fp[SCM_MAX_FD]; |
19 | }; | 20 | }; |
20 | 21 | ||
diff --git a/net/core/scm.c b/net/core/scm.c index 413cab89017d..bbe454450801 100644 --- a/net/core/scm.c +++ b/net/core/scm.c | |||
@@ -79,10 +79,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp) | |||
79 | return -ENOMEM; | 79 | return -ENOMEM; |
80 | *fplp = fpl; | 80 | *fplp = fpl; |
81 | fpl->count = 0; | 81 | fpl->count = 0; |
82 | fpl->max = SCM_MAX_FD; | ||
82 | } | 83 | } |
83 | fpp = &fpl->fp[fpl->count]; | 84 | fpp = &fpl->fp[fpl->count]; |
84 | 85 | ||
85 | if (fpl->count + num > SCM_MAX_FD) | 86 | if (fpl->count + num > fpl->max) |
86 | return -EINVAL; | 87 | return -EINVAL; |
87 | 88 | ||
88 | /* | 89 | /* |
@@ -331,11 +332,12 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl) | |||
331 | if (!fpl) | 332 | if (!fpl) |
332 | return NULL; | 333 | return NULL; |
333 | 334 | ||
334 | new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL); | 335 | new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]), |
336 | GFP_KERNEL); | ||
335 | if (new_fpl) { | 337 | if (new_fpl) { |
336 | for (i=fpl->count-1; i>=0; i--) | 338 | for (i = 0; i < fpl->count; i++) |
337 | get_file(fpl->fp[i]); | 339 | get_file(fpl->fp[i]); |
338 | memcpy(new_fpl, fpl, sizeof(*fpl)); | 340 | new_fpl->max = new_fpl->count; |
339 | } | 341 | } |
340 | return new_fpl; | 342 | return new_fpl; |
341 | } | 343 | } |