scm: lower SCM_MAX_FD
authorEric Dumazet <eric.dumazet@gmail.com>
Tue, 23 Nov 2010 14:09:15 +0000 (14:09 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Nov 2010 19:16:43 +0000 (11:16 -0800)
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>
include/net/scm.h
net/core/scm.c

index 31656506d967a4a2349a74a158cdb3fa3ecb6986..745460fa2f02cdd96e6b6befd79b8791d95965fd 100644 (file)
 /* Well, we should have at least one descriptor open
  * to accept passed FDs 8)
  */
-#define SCM_MAX_FD     255
+#define SCM_MAX_FD     253
 
 struct scm_fp_list {
        struct list_head        list;
-       int                     count;
+       short                   count;
+       short                   max;
        struct file             *fp[SCM_MAX_FD];
 };
 
index 413cab89017d0818c997b8d6a807997fa47c92d0..bbe4544508016925726522f275e95aefadeb1664 100644 (file)
@@ -79,10 +79,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
                        return -ENOMEM;
                *fplp = fpl;
                fpl->count = 0;
+               fpl->max = SCM_MAX_FD;
        }
        fpp = &fpl->fp[fpl->count];
 
-       if (fpl->count + num > SCM_MAX_FD)
+       if (fpl->count + num > fpl->max)
                return -EINVAL;
 
        /*
@@ -331,11 +332,12 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl)
        if (!fpl)
                return NULL;
 
-       new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL);
+       new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
+                         GFP_KERNEL);
        if (new_fpl) {
-               for (i=fpl->count-1; i>=0; i--)
+               for (i = 0; i < fpl->count; i++)
                        get_file(fpl->fp[i]);
-               memcpy(new_fpl, fpl, sizeof(*fpl));
+               new_fpl->max = new_fpl->count;
        }
        return new_fpl;
 }