ia64/xen-unstable
changeset 10548:1da8f53ce65b
[LINUX] Fix a few compile warnings and memory leaks in the sysfs driver.
Also clean up the general allocate-call-free idiom that is used
throughout the file.
Signed-off-by: Keir Fraser <keir@xensource.com>
Also clean up the general allocate-call-free idiom that is used
throughout the file.
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Tue Jun 27 18:24:08 2006 +0100 (2006-06-27) |
parents | 8a89c0ff3f87 |
children | 571507a595cd |
files | linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c |
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c Tue Jun 27 18:08:46 2006 +0100 1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c Tue Jun 27 18:24:08 2006 +0100 1.3 @@ -58,15 +58,17 @@ HYPERVISOR_ATTR_RO(minor); 1.4 1.5 static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer) 1.6 { 1.7 - int ret; 1.8 - char *extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL); 1.9 + int ret = -ENOMEM; 1.10 + char *extra; 1.11 + 1.12 + extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL); 1.13 if (extra) { 1.14 ret = HYPERVISOR_xen_version(XENVER_extraversion, extra); 1.15 if (!ret) 1.16 - return sprintf(buffer, "%s\n", extra); 1.17 + ret = sprintf(buffer, "%s\n", extra); 1.18 kfree(extra); 1.19 - } else 1.20 - ret = -ENOMEM; 1.21 + } 1.22 + 1.23 return ret; 1.24 } 1.25 1.26 @@ -86,7 +88,8 @@ static struct attribute_group version_gr 1.27 1.28 static int __init xen_sysfs_version_init(void) 1.29 { 1.30 - return sysfs_create_group(&hypervisor_subsys.kset.kobj, &version_group); 1.31 + return sysfs_create_group(&hypervisor_subsys.kset.kobj, 1.32 + &version_group); 1.33 } 1.34 1.35 static void xen_sysfs_version_destroy(void) 1.36 @@ -98,16 +101,16 @@ static void xen_sysfs_version_destroy(vo 1.37 1.38 static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer) 1.39 { 1.40 - int ret; 1.41 - struct xen_compile_info *info = 1.42 - kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 1.43 + int ret = -ENOMEM; 1.44 + struct xen_compile_info *info; 1.45 + 1.46 + info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 1.47 if (info) { 1.48 ret = HYPERVISOR_xen_version(XENVER_compile_info, info); 1.49 if (!ret) 1.50 ret = sprintf(buffer, "%s\n", info->compiler); 1.51 kfree(info); 1.52 - } else 1.53 - ret = -ENOMEM; 1.54 + } 1.55 1.56 return ret; 1.57 } 1.58 @@ -116,7 +119,7 @@ HYPERVISOR_ATTR_RO(compiler); 1.59 1.60 static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer) 1.61 { 1.62 - int ret; 1.63 + int ret = -ENOMEM; 1.64 struct xen_compile_info *info; 1.65 1.66 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 1.67 @@ -125,8 +128,8 @@ static ssize_t compiled_by_show(struct h 1.68 if (!ret) 1.69 ret = sprintf(buffer, "%s\n", info->compile_by); 1.70 kfree(info); 1.71 - } else 1.72 - ret = -ENOMEM; 1.73 + } 1.74 + 1.75 return ret; 1.76 } 1.77 1.78 @@ -134,7 +137,7 @@ HYPERVISOR_ATTR_RO(compiled_by); 1.79 1.80 static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer) 1.81 { 1.82 - int ret; 1.83 + int ret = -ENOMEM; 1.84 struct xen_compile_info *info; 1.85 1.86 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 1.87 @@ -143,8 +146,8 @@ static ssize_t compile_date_show(struct 1.88 if (!ret) 1.89 ret = sprintf(buffer, "%s\n", info->compile_date); 1.90 kfree(info); 1.91 - } else 1.92 - ret = -ENOMEM; 1.93 + } 1.94 + 1.95 return ret; 1.96 } 1.97 1.98 @@ -178,15 +181,17 @@ static void xen_compilation_destroy(void 1.99 1.100 static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer) 1.101 { 1.102 - int ret; 1.103 - char *caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL); 1.104 + int ret = -ENOMEM; 1.105 + char *caps; 1.106 + 1.107 + caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL); 1.108 if (caps) { 1.109 ret = HYPERVISOR_xen_version(XENVER_capabilities, caps); 1.110 if (!ret) 1.111 ret = sprintf(buffer, "%s\n", caps); 1.112 kfree(caps); 1.113 - } else 1.114 - ret = -ENOMEM; 1.115 + } 1.116 + 1.117 return ret; 1.118 } 1.119 1.120 @@ -194,15 +199,17 @@ HYPERVISOR_ATTR_RO(capabilities); 1.121 1.122 static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer) 1.123 { 1.124 - int ret; 1.125 - char *cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL); 1.126 + int ret = -ENOMEM; 1.127 + char *cset; 1.128 + 1.129 + cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL); 1.130 if (cset) { 1.131 ret = HYPERVISOR_xen_version(XENVER_changeset, cset); 1.132 if (!ret) 1.133 ret = sprintf(buffer, "%s\n", cset); 1.134 kfree(cset); 1.135 - } else 1.136 - ret = -ENOMEM; 1.137 + } 1.138 + 1.139 return ret; 1.140 } 1.141 1.142 @@ -210,16 +217,18 @@ HYPERVISOR_ATTR_RO(changeset); 1.143 1.144 static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer) 1.145 { 1.146 - int ret; 1.147 - struct xen_platform_parameters *parms = 1.148 - kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL); 1.149 + int ret = -ENOMEM; 1.150 + struct xen_platform_parameters *parms; 1.151 + 1.152 + parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL); 1.153 if (parms) { 1.154 - ret = HYPERVISOR_xen_version(XENVER_platform_parameters, parms); 1.155 + ret = HYPERVISOR_xen_version(XENVER_platform_parameters, 1.156 + parms); 1.157 if (!ret) 1.158 ret = sprintf(buffer, "%lx\n", parms->virt_start); 1.159 kfree(parms); 1.160 - } else 1.161 - ret = -ENOMEM; 1.162 + } 1.163 + 1.164 return ret; 1.165 } 1.166 1.167 @@ -231,7 +240,8 @@ static ssize_t pagesize_show(struct hyp_ 1.168 1.169 ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL); 1.170 if (ret > 0) 1.171 - ret = sprintf(buffer, "%lx\n", ret); 1.172 + ret = sprintf(buffer, "%x\n", ret); 1.173 + 1.174 return ret; 1.175 } 1.176 1.177 @@ -240,18 +250,18 @@ HYPERVISOR_ATTR_RO(pagesize); 1.178 /* eventually there will be several more features to export */ 1.179 static ssize_t xen_feature_show(int index, char *buffer) 1.180 { 1.181 - int ret; 1.182 + int ret = -ENOMEM; 1.183 + struct xen_feature_info *info; 1.184 1.185 - struct xen_feature_info *info = 1.186 - kmalloc(sizeof(struct xen_feature_info), GFP_KERNEL); 1.187 + info = kmalloc(sizeof(struct xen_feature_info), GFP_KERNEL); 1.188 if (info) { 1.189 info->submap_idx = index; 1.190 ret = HYPERVISOR_xen_version(XENVER_get_features, info); 1.191 if (!ret) 1.192 ret = sprintf(buffer, "%d\n", info->submap); 1.193 kfree(info); 1.194 - } else 1.195 - ret = -ENOMEM; 1.196 + } 1.197 + 1.198 return ret; 1.199 } 1.200 1.201 @@ -284,7 +294,8 @@ static int __init xen_properties_init(vo 1.202 1.203 static void xen_properties_destroy(void) 1.204 { 1.205 - sysfs_remove_group(&hypervisor_subsys.kset.kobj, &xen_properties_group); 1.206 + sysfs_remove_group(&hypervisor_subsys.kset.kobj, 1.207 + &xen_properties_group); 1.208 } 1.209 1.210 static int __init hyper_sysfs_init(void)