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>
/* Well, we should have at least one descriptor open
* to accept passed FDs 8)
*/
/* Well, we should have at least one descriptor open
* to accept passed FDs 8)
*/
struct scm_fp_list {
struct list_head list;
struct scm_fp_list {
struct list_head list;
+ short count;
+ short max;
struct file *fp[SCM_MAX_FD];
};
struct file *fp[SCM_MAX_FD];
};
return -ENOMEM;
*fplp = fpl;
fpl->count = 0;
return -ENOMEM;
*fplp = fpl;
fpl->count = 0;
}
fpp = &fpl->fp[fpl->count];
}
fpp = &fpl->fp[fpl->count];
- if (fpl->count + num > SCM_MAX_FD)
+ if (fpl->count + num > fpl->max)
- new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL);
+ new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
+ GFP_KERNEL);
- for (i=fpl->count-1; i>=0; i--)
+ for (i = 0; i < fpl->count; i++)
- memcpy(new_fpl, fpl, sizeof(*fpl));
+ new_fpl->max = new_fpl->count;