ia64/xen-unstable

changeset 18673:687601e21055

Update cpufreq statistic protection

For struct pm_px, there are 3 pointer: pxpt, pt, trans_pt.
Partly free pointer 'pt' and 'trans_pt' will result in little memory
leak, and what is more, will result in protection issue when user
access px statistic info through libxc.

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Oct 21 09:48:56 2008 +0100 (2008-10-21)
parents 27eec3c54d08
children 353f2359230a
files xen/drivers/cpufreq/utility.c
line diff
     1.1 --- a/xen/drivers/cpufreq/utility.c	Tue Oct 21 09:48:08 2008 +0100
     1.2 +++ b/xen/drivers/cpufreq/utility.c	Tue Oct 21 09:48:56 2008 +0100
     1.3 @@ -73,27 +73,30 @@ int cpufreq_statistic_init(unsigned int 
     1.4      struct pm_px *pxpt = cpufreq_statistic_data[cpuid];
     1.5      const struct processor_pminfo *pmpt = processor_pminfo[cpuid];
     1.6  
     1.7 -    count = pmpt->perf.state_count;
     1.8 -
     1.9      if ( !pmpt )
    1.10          return -EINVAL;
    1.11  
    1.12 +    if ( pxpt )
    1.13 +        return 0;
    1.14 +
    1.15 +    count = pmpt->perf.state_count;
    1.16 +
    1.17 +    pxpt = xmalloc(struct pm_px);
    1.18      if ( !pxpt )
    1.19 -    {
    1.20 -        pxpt = xmalloc(struct pm_px);
    1.21 -        if ( !pxpt )
    1.22 -            return -ENOMEM;
    1.23 -        memset(pxpt, 0, sizeof(*pxpt));
    1.24 -        cpufreq_statistic_data[cpuid] = pxpt;
    1.25 -    }
    1.26 +        return -ENOMEM;
    1.27 +    memset(pxpt, 0, sizeof(*pxpt));
    1.28 +    cpufreq_statistic_data[cpuid] = pxpt;
    1.29  
    1.30      pxpt->u.trans_pt = xmalloc_array(uint64_t, count * count);
    1.31 -    if (!pxpt->u.trans_pt)
    1.32 +    if (!pxpt->u.trans_pt) {
    1.33 +        xfree(pxpt);
    1.34          return -ENOMEM;
    1.35 +    }
    1.36  
    1.37      pxpt->u.pt = xmalloc_array(struct pm_px_val, count);
    1.38      if (!pxpt->u.pt) {
    1.39          xfree(pxpt->u.trans_pt);
    1.40 +        xfree(pxpt);
    1.41          return -ENOMEM;
    1.42      }
    1.43  
    1.44 @@ -120,7 +123,8 @@ void cpufreq_statistic_exit(unsigned int
    1.45          return;
    1.46      xfree(pxpt->u.trans_pt);
    1.47      xfree(pxpt->u.pt);
    1.48 -    memset(pxpt, 0, sizeof(struct pm_px));
    1.49 +    xfree(pxpt);
    1.50 +    cpufreq_statistic_data[cpuid] = NULL;
    1.51  }
    1.52  
    1.53  void cpufreq_statistic_reset(unsigned int cpuid)