From 193294c2cc727296b9fb859daf2eacb906fc1735 Mon Sep 17 00:00:00 2001 From: "Tahhan, Maryam" Date: Fri, 14 Apr 2017 12:41:00 +0100 Subject: [PATCH] mcelog: code review updates * Comparing variables with NULL explicilty instead of !var * Removed unnecessary casts Change-Id: I50a1691c42842c81ff71c2e91a8fb292524dc945 Signed-off-by: Tahhan, Maryam --- src/mcelog.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mcelog.c b/src/mcelog.c index 928db1cb..4f3f9b0c 100644 --- a/src/mcelog.c +++ b/src/mcelog.c @@ -141,9 +141,8 @@ static llentry_t *mcelog_dimm(const mcelog_memory_rec_t *rec, llentry_t *dimm_le = mcelog_get_dimm(dimm_name, dimms_list); if (dimm_le == NULL) { - mcelog_memory_rec_t *dimm_mr = - (mcelog_memory_rec_t *)calloc(1, sizeof(mcelog_memory_rec_t)); - if (!dimm_mr) { + mcelog_memory_rec_t *dimm_mr = calloc(1, sizeof(*dimm_mr)); + if (dimm_mr == NULL) { ERROR(MCELOG_PLUGIN ": Error allocating dimm memory item"); return NULL; } @@ -157,6 +156,7 @@ static llentry_t *mcelog_dimm(const mcelog_memory_rec_t *rec, dimm_le = llentry_create(p_name, dimm_mr); if (dimm_le == NULL) { ERROR(MCELOG_PLUGIN ": llentry_create(): error"); + free(dimm_mr); return NULL; } pthread_mutex_lock(&g_mcelog_config.dimms_lock); @@ -302,12 +302,12 @@ static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) { return (-1); llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list); - if (!dimm) { + if (dimm == NULL) { ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache"); return -1; } - mcelog_memory_rec_t *mr_old = (mcelog_memory_rec_t *)dimm->value; + mcelog_memory_rec_t *mr_old = dimm->value; if (mr_old->corrected_err_total != mr->corrected_err_total || mr_old->corrected_err_timed != mr->corrected_err_timed) @@ -394,7 +394,7 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) { } llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list); - if (!dimm) { + if (dimm == NULL) { ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache"); return -1; } -- 2.11.0