From 63e828fe881210f30972524fcfc88bac215f36d0 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 23 Jul 2015 00:00:00 -0500 Subject: [PATCH] library: minor tweaks of program logic and/or comments This commit just corrects the oversight wherein 'item' was being employed when 'these' was actually intended. Also, it trades some 'item' use for a more descriptive input parameter which henceforth is known as a 'dest'. And, there was one leftover 'next' pointer eliminated. Finally, some logic was made a tad less dependent upon enumerator names and a few comments were also updated. Signed-off-by: Jim Warner --- proc/meminfo.c | 4 ++-- proc/readstat.c | 44 ++++++++++++++++++++++---------------------- proc/readstat.h | 17 ++++++++--------- proc/slab.c | 4 ++-- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/proc/meminfo.c b/proc/meminfo.c index a7a392df..a3a1060d 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -463,7 +463,7 @@ static int stack_items_valid ( int i; for (i = 0; i < maxitems; i++) { - if (items[i] < PROCPS_MEMHI_FREE) + if (items[i] < 0) return 0; if (items[i] > PROCPS_MEM_stack_end) return 0; @@ -508,7 +508,7 @@ static struct meminfo_stack **procps_meminfo_stacks_alloc ( list_size = sizeof(struct meminfo_result) * maxitems; // a results stack blob_size = sizeof(struct stacks_anchor); // the anchor itself blob_size += vect_size; // all vectors + delims - blob_size += head_size * maxstacks; // all head structs + user stuff + blob_size += head_size * maxstacks; // all head structs blob_size += list_size * maxstacks; // all results stacks /* note: all memory is allocated in a single blob, facilitating a later free(). diff --git a/proc/readstat.c b/proc/readstat.c index 8dfa5047..4d06a6b7 100644 --- a/proc/readstat.c +++ b/proc/readstat.c @@ -441,24 +441,24 @@ reap_em_again: */ PROCPS_EXPORT int procps_stat_jiffs_get ( struct procps_stat *info, - struct procps_jiffs *item, + struct procps_jiffs *dest, int which) { struct procps_jiffs_private *p; int i; - if (info == NULL || item == NULL) + if (info == NULL || dest == NULL) return -EINVAL; if (which < 0) { // note, we're just copying the 'new' portion of our procps_jiffs_private - memcpy(item, &info->cpu_summary, sizeof(struct procps_jiffs)); + memcpy(dest, &info->cpu_summary, sizeof(struct procps_jiffs)); return 0; } p = info->jiff_hists; for (i = 0; i < info->jiff_hists_inuse; i++) { if (p->cpu.id == which) { // note, we're just copying the 'new' portion of our procps_jiffs_private - memcpy(item, p, sizeof(struct procps_jiffs)); + memcpy(dest, p, sizeof(struct procps_jiffs)); return 0; } ++p; @@ -470,30 +470,30 @@ PROCPS_EXPORT int procps_stat_jiffs_get ( * procps_stat_jiffs_fill: * * Refresh available cpu data, then return all cpu data in the caller - * supplied structures, up to the lesser of numitems or total available. + * supplied structures, up to the lesser of maxdests or total available. * - * We tolerate a numitems greater than the total available, and + * We tolerate a maxdests greater than the total available, and * the caller had better tolerate fewer returned than requested. * * This function deals only with the 'current' jiffs counts. */ PROCPS_EXPORT int procps_stat_jiffs_fill ( struct procps_stat *info, - struct procps_jiffs *item, - int numitems) + struct procps_jiffs *dests, + int maxdests) { int i, rc; - if (info == NULL || item == NULL) + if (info == NULL || dests == NULL) return -EINVAL; if ((rc = procps_stat_read_jiffs(info)) < 0) return rc; if (!info->jiff_hists_inuse) return -1; - for (i = 0; i < info->jiff_hists_inuse && i < numitems; i++) { + for (i = 0; i < info->jiff_hists_inuse && i < maxdests; i++) { // note, we're just copying the 'new' portion of our procps_jiffs_private - memcpy(item + i, info->jiff_hists + i, sizeof(struct procps_jiffs)); + memcpy(dests + i, info->jiff_hists + i, sizeof(struct procps_jiffs)); } return i; } @@ -508,22 +508,22 @@ PROCPS_EXPORT int procps_stat_jiffs_fill ( */ PROCPS_EXPORT int procps_stat_jiffs_hist_get ( struct procps_stat *info, - struct procps_jiffs_hist *item, + struct procps_jiffs_hist *dest, int which) { struct procps_jiffs_private *p; int i; - if (info == NULL || item == NULL) + if (info == NULL || dest == NULL) return -EINVAL; if (which < 0) { - memcpy(item, &info->cpu_summary, sizeof(struct procps_jiffs_hist)); + memcpy(dest, &info->cpu_summary, sizeof(struct procps_jiffs_hist)); return 0; } p = info->jiff_hists; for (i = 0; i < info->jiff_hists_inuse; i++) { if (p->cpu.id == which) { - memcpy(item, p, sizeof(struct procps_jiffs_hist)); + memcpy(dest, p, sizeof(struct procps_jiffs_hist)); return 0; } ++p; @@ -535,29 +535,29 @@ PROCPS_EXPORT int procps_stat_jiffs_hist_get ( * procps_stat_jiffs_hist_fill: * * Refresh available cpu data, then return all cpu data in the caller - * supplied structures, up to the lesser of numitems or total available. + * supplied structures, up to the lesser of maxdests or total available. * - * We tolerate a numitems greater than the total available, and + * We tolerate a maxdests greater than the total available, and * the caller had better tolerate fewer returned than requested. * * This function provides both 'new' and 'old' jiffs counts. */ PROCPS_EXPORT int procps_stat_jiffs_hist_fill ( struct procps_stat *info, - struct procps_jiffs_hist *item, - int numitems) + struct procps_jiffs_hist *dests, + int maxdests) { int i, rc; - if (info == NULL || item == NULL) + if (info == NULL || dests == NULL) return -EINVAL; if ((rc = procps_stat_read_jiffs(info)) < 0) return rc; if (!info->jiff_hists_inuse) return -1; - for (i = 0; i < info->jiff_hists_inuse && i < numitems; i++) { - memcpy(item + i, info->jiff_hists + i, sizeof(struct procps_jiffs_hist)); + for (i = 0; i < info->jiff_hists_inuse && i < maxdests; i++) { + memcpy(dests + i, info->jiff_hists + i, sizeof(struct procps_jiffs_hist)); } return i; } diff --git a/proc/readstat.h b/proc/readstat.h index ebebeaf5..95f2412d 100644 --- a/proc/readstat.h +++ b/proc/readstat.h @@ -66,7 +66,6 @@ struct stat_result { unsigned int u_int; jiff jiff; } result; - struct stat_result *next; }; struct procps_stat; @@ -84,27 +83,27 @@ jiff procps_stat_cpu_get ( int procps_stat_cpu_getstack ( struct procps_stat *info, - struct stat_result *item); + struct stat_result *these); int procps_stat_jiffs_get ( struct procps_stat *info, - struct procps_jiffs *item, + struct procps_jiffs *dest, int which); int procps_stat_jiffs_hist_get ( struct procps_stat *info, - struct procps_jiffs_hist *item, + struct procps_jiffs_hist *dest, int which); int procps_stat_jiffs_fill ( struct procps_stat *info, - struct procps_jiffs *item, - int numitems); + struct procps_jiffs *dests, + int maxdests); int procps_stat_jiffs_hist_fill ( struct procps_stat *info, - struct procps_jiffs_hist *item, - int numitems); + struct procps_jiffs_hist *dests, + int maxdests); unsigned int procps_stat_sys_get ( struct procps_stat *info, @@ -112,7 +111,7 @@ unsigned int procps_stat_sys_get ( int procps_stat_sys_getstack ( struct procps_stat *info, - struct stat_result *item); + struct stat_result *these); __END_DECLS #endif diff --git a/proc/slab.c b/proc/slab.c index 359a63f1..2a3c5f7d 100644 --- a/proc/slab.c +++ b/proc/slab.c @@ -689,7 +689,7 @@ static int stack_items_valid ( int i; for (i = 0; i < maxitems; i++) { - if (items[i] < PROCPS_SLABNODE_SIZE) + if (items[i] < 0) return 0; if (items[i] > PROCPS_SLABNODE_stack_end) return 0; @@ -737,7 +737,7 @@ PROCPS_EXPORT struct slabnode_stack **procps_slabnode_stacks_alloc ( list_size = sizeof(struct slab_result) * maxitems; // a results stack blob_size = sizeof(struct stacks_anchor); // the anchor itself blob_size += vect_size; // all vectors + delims - blob_size += head_size * maxstacks; // all head structs + user stuff + blob_size += head_size * maxstacks; // all head structs blob_size += list_size * maxstacks; // all results stacks /* note: all memory is allocated in a single blob, facilitating a later free().