lkml.org 
[lkml]   [2012]   [Apr]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    SubjectRe: [PATCH -V6 10/14] hugetlbfs: Add memcg control files for hugetlbfs
    Date
    Andrew Morton <akpm@linux-foundation.org> writes:

    > On Mon, 16 Apr 2012 16:14:47 +0530
    > "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
    >
    >> +#ifdef CONFIG_MEM_RES_CTLR_HUGETLB
    >> +static char *mem_fmt(char *buf, unsigned long n)
    >> +{
    >> + if (n >= (1UL << 30))
    >> + sprintf(buf, "%luGB", n >> 30);
    >> + else if (n >= (1UL << 20))
    >> + sprintf(buf, "%luMB", n >> 20);
    >> + else
    >> + sprintf(buf, "%luKB", n >> 10);
    >> + return buf;
    >> +}
    >> +
    >> +int __init mem_cgroup_hugetlb_file_init(int idx)
    >> +{
    >> + char buf[32];
    >> + struct cftype *cft;
    >> + struct hstate *h = &hstates[idx];
    >> +
    >> + /* format the size */
    >> + mem_fmt(buf, huge_page_size(h));
    >
    > The sprintf() into a fixed-sized buffer is a bit ugly. I didn't check
    > it for possible overflows because 32 looks like "enough". Actually too
    > much.
    >
    > Oh well, it's hard to avoid. But using scnprintf() would prevent nasty
    > accidents.
    >
    diff --git a/mm/memcontrol.c b/mm/memcontrol.c
    index 519d370..0ccf934 100644
    --- a/mm/memcontrol.c
    +++ b/mm/memcontrol.c
    @@ -5269,14 +5269,14 @@ static void mem_cgroup_destroy(struct cgroup *cont)
    }

    #ifdef CONFIG_MEM_RES_CTLR_HUGETLB
    -static char *mem_fmt(char *buf, unsigned long n)
    +static char *mem_fmt(char *buf, int size, unsigned long hsize)
    {
    - if (n >= (1UL << 30))
    - sprintf(buf, "%luGB", n >> 30);
    - else if (n >= (1UL << 20))
    - sprintf(buf, "%luMB", n >> 20);
    + if (hsize >= (1UL << 30))
    + scnprintf(buf, size, "%luGB", hsize >> 30);
    + else if (hsize >= (1UL << 20))
    + scnprintf(buf, size, "%luMB", hsize >> 20);
    else
    - sprintf(buf, "%luKB", n >> 10);
    + scnprintf(buf, size, "%luKB", hsize >> 10);
    return buf;
    }

    @@ -5287,7 +5287,7 @@ int __init mem_cgroup_hugetlb_file_init(int idx)
    struct hstate *h = &hstates[idx];

    /* format the size */
    - mem_fmt(buf, huge_page_size(h));
    + mem_fmt(buf, 32, huge_page_size(h));

    /* Add the limit file */
    cft = &h->mem_cgroup_files[0];



    \
     
     \ /
      Last update: 2012-04-18 22:37    [W:0.028 / U:119.900 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site