ia64/xen-unstable

changeset 13754:9578ae319874

Clean up arch_get_xen_caps() to not use sprintf().
Based on a patch from Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Tue Jan 30 16:23:43 2007 +0000 (2007-01-30)
parents bd69e83b65ea
children 37fd1cf9019d
files xen/arch/ia64/xen/xensetup.c xen/arch/x86/setup.c
line diff
     1.1 --- a/xen/arch/ia64/xen/xensetup.c	Tue Jan 30 16:14:16 2007 +0000
     1.2 +++ b/xen/arch/ia64/xen/xensetup.c	Tue Jan 30 16:23:43 2007 +0000
     1.3 @@ -547,18 +547,19 @@ printk("num_online_cpus=%d, max_cpus=%d\
     1.4  
     1.5  void arch_get_xen_caps(xen_capabilities_info_t info)
     1.6  {
     1.7 -    char *p=info;
     1.8      int major = xen_major_version();
     1.9      int minor = xen_minor_version();
    1.10 +    char s[32];
    1.11  
    1.12 -    p += snprintf(p,sizeof(info), "xen-%d.%d-ia64 ", major, minor);
    1.13 +    info[0] = '\0';
    1.14 +
    1.15 +    snprintf(s, sizeof(s), "xen-%d.%d-ia54 ", major, minor);
    1.16 +    safe_strcat(info, s);
    1.17  
    1.18      if (vmx_enabled)
    1.19 -        p += snprintf(p,sizeof(info) - (p - info),"hvm-%d.%d-ia64 ", major, minor);
    1.20 -
    1.21 -    *(p-1) = 0;
    1.22 -
    1.23 -    BUG_ON((p-info)>sizeof(xen_capabilities_info_t));
    1.24 -
    1.25 +    {
    1.26 +        snprintf(s, sizeof(s), "hvm-%d.%d-ia64 ", major, minor);
    1.27 +        safe_strcat(info, s);
    1.28 +    }
    1.29  }
    1.30  
     2.1 --- a/xen/arch/x86/setup.c	Tue Jan 30 16:14:16 2007 +0000
     2.2 +++ b/xen/arch/x86/setup.c	Tue Jan 30 16:23:43 2007 +0000
     2.3 @@ -802,69 +802,53 @@ void __init __start_xen(multiboot_info_t
     2.4  
     2.5  void arch_get_xen_caps(xen_capabilities_info_t info)
     2.6  {
     2.7 -    char *p = info;
     2.8 -    int i = 0;
     2.9      int major = xen_major_version();
    2.10      int minor = xen_minor_version();
    2.11 +    char s[32];
    2.12 +
    2.13 +    info[0] = '\0';
    2.14  
    2.15  #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
    2.16  
    2.17 -    i = snprintf(p, sizeof(xen_capabilities_info_t),
    2.18 -                 "xen-%d.%d-x86_32 ", major, minor);
    2.19 -    p += i;
    2.20 -    if ( hvm_enabled ) {
    2.21 -        i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.22 -		"hvm-%d.%d-x86_32 ", major, minor);
    2.23 -	p += i;
    2.24 +    snprintf(s, sizeof(s), "xen-%d.%d-x86_32 ", major, minor);
    2.25 +    safe_strcat(info, s);
    2.26 +    if ( hvm_enabled )
    2.27 +    {
    2.28 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
    2.29 +        safe_strcat(info, s);
    2.30      }
    2.31  
    2.32  #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
    2.33  
    2.34 -    i = snprintf(p, sizeof(xen_capabilities_info_t),
    2.35 -                 "xen-%d.%d-x86_32p ", major, minor);
    2.36 -    p += i;
    2.37 +    snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
    2.38 +    safe_strcat(info, s);
    2.39      if ( hvm_enabled )
    2.40      {
    2.41 -        i = snprintf(p, sizeof(xen_capabilities_info_t),
    2.42 -                     "hvm-%d.%d-x86_32 ", major, minor);
    2.43 -        p += i;
    2.44 -        i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.45 -                     "hvm-%d.%d-x86_32p ", major, minor);
    2.46 -        p += i;
    2.47 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
    2.48 +        safe_strcat(info, s);
    2.49 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
    2.50 +        safe_strcat(info, s);
    2.51      }
    2.52  
    2.53  #elif defined(CONFIG_X86_64)
    2.54  
    2.55 -    i = snprintf(p, sizeof(xen_capabilities_info_t),
    2.56 -                 "xen-%d.%d-x86_64 ", major, minor);
    2.57 -    p += i;
    2.58 +    snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
    2.59 +    safe_strcat(info, s);
    2.60  #ifdef CONFIG_COMPAT
    2.61 -    i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.62 -                "xen-%d.%d-x86_32p ", major, minor);
    2.63 -    p += i;
    2.64 +    snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
    2.65 +    safe_strcat(info, s);
    2.66  #endif
    2.67      if ( hvm_enabled )
    2.68      {
    2.69 -        i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.70 -                     "hvm-%d.%d-x86_32 ", major, minor);
    2.71 -        p += i;
    2.72 -        i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.73 -                     "hvm-%d.%d-x86_32p ", major, minor);
    2.74 -        p += i;
    2.75 -        i = snprintf(p, sizeof(xen_capabilities_info_t) - i,
    2.76 -                     "hvm-%d.%d-x86_64 ", major, minor);
    2.77 -        p += i;
    2.78 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
    2.79 +        safe_strcat(info, s);
    2.80 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
    2.81 +        safe_strcat(info, s);
    2.82 +        snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
    2.83 +        safe_strcat(info, s);
    2.84      }
    2.85  
    2.86 -#else
    2.87 -
    2.88 -    p++;
    2.89 -
    2.90  #endif
    2.91 -
    2.92 -    *(p-1) = 0;
    2.93 -
    2.94 -    BUG_ON((p - info) > sizeof(xen_capabilities_info_t));
    2.95  }
    2.96  
    2.97  /*