diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-04-08 20:25:59 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-04-08 20:25:59 +0200 |
commit | 699a49933d2b2690888f719a447682d85c9942b0 (patch) | |
tree | abaf80cecec848db033318cfe84bac08b884dbdc /src/hardware/LMI_ProcessorCacheMemoryProvider.c | |
parent | 9b77270eebd073ab4060ac84e4b40fc0652dff07 (diff) | |
download | openlmi-providers-699a49933d2b2690888f719a447682d85c9942b0.tar.gz openlmi-providers-699a49933d2b2690888f719a447682d85c9942b0.tar.xz openlmi-providers-699a49933d2b2690888f719a447682d85c9942b0.zip |
Hardware: Code clean up
* Got rid of asprintf() where suitable (used static memory instead)
* Removed if conditional before free()
* Replaced more hard coded numbers with LMI constants
Diffstat (limited to 'src/hardware/LMI_ProcessorCacheMemoryProvider.c')
-rw-r--r-- | src/hardware/LMI_ProcessorCacheMemoryProvider.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/hardware/LMI_ProcessorCacheMemoryProvider.c b/src/hardware/LMI_ProcessorCacheMemoryProvider.c index d4c73f6..ca45b67 100644 --- a/src/hardware/LMI_ProcessorCacheMemoryProvider.c +++ b/src/hardware/LMI_ProcessorCacheMemoryProvider.c @@ -60,7 +60,7 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances( { LMI_ProcessorCacheMemory lmi_cpu_cache; const char *ns = KNameSpace(cop); - char *error_msg = NULL, *instance_id = NULL; + char *error_msg = NULL, instance_id[INSTANCE_ID_LEN] = ""; unsigned i, caches = 0; DmiCpuCache *dmi_cpu_caches = NULL; unsigned dmi_cpu_caches_nb = 0; @@ -118,12 +118,9 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances( /* do we have dmidecode output? */ if (dmi_cpu_caches_nb > 0) { - if (asprintf(&instance_id, ORGID ":" CPU_CACHE_CLASS_NAME ":%s", - dmi_cpu_caches[i].id) < 0) { - instance_id = NULL; - error_msg = "Not enough available memory."; - goto done; - } + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" CPU_CACHE_CLASS_NAME ":%s", + dmi_cpu_caches[i].id); LMI_ProcessorCacheMemory_Set_DeviceID(&lmi_cpu_cache, dmi_cpu_caches[i].id); @@ -137,12 +134,9 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances( LMI_ProcessorCacheMemory_Set_EnabledState(&lmi_cpu_cache, get_cachestatus(dmi_cpu_caches[i].status)); } else { - if (asprintf(&instance_id, ORGID ":" CPU_CACHE_CLASS_NAME ":%s", - sysfs_cpu_caches[i].id) < 0) { - instance_id = NULL; - error_msg = "Not enough available memory."; - goto done; - } + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" CPU_CACHE_CLASS_NAME ":%s", + sysfs_cpu_caches[i].id); LMI_ProcessorCacheMemory_Set_DeviceID(&lmi_cpu_cache, sysfs_cpu_caches[i].id); |