[ofa-general] [PATCH 2/2] opensm/osm_qos_policy.c: Use calloc rather than malloc/memset

Hal Rosenstock hnrose at comcast.net
Wed Jul 15 04:59:50 PDT 2009


Signed-off-by: Hal Rosenstock <hal.rosenstock at gmail.com>
---
 opensm/opensm/osm_qos_policy.c |   26 ++++++++------------------
 1 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/opensm/opensm/osm_qos_policy.c b/opensm/opensm/osm_qos_policy.c
index 2002fd1..7826578 100644
--- a/opensm/opensm/osm_qos_policy.c
+++ b/opensm/opensm/osm_qos_policy.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  * Copyright (c) 2008 Xsigo Systems Inc.  All rights reserved.
+ * Copyright (c) 2009 HNR Consulting.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -133,10 +134,9 @@ static void __free_single_element(void *p_element, void *context)
 osm_qos_port_t *osm_qos_policy_port_create(osm_physp_t *p_physp)
 {
 	osm_qos_port_t *p =
-	    (osm_qos_port_t *) malloc(sizeof(osm_qos_port_t));
+	    (osm_qos_port_t *) calloc(1, sizeof(osm_qos_port_t));
 	if (!p)
 		return NULL;
-	memset(p, 0, sizeof(osm_qos_port_t));
 
 	p->p_physp = p_physp;
 	return p;
@@ -148,11 +148,10 @@ osm_qos_port_t *osm_qos_policy_port_create(osm_physp_t *p_physp)
 osm_qos_port_group_t *osm_qos_policy_port_group_create()
 {
 	osm_qos_port_group_t *p =
-	    (osm_qos_port_group_t *) malloc(sizeof(osm_qos_port_group_t));
+	    (osm_qos_port_group_t *) calloc(1, sizeof(osm_qos_port_group_t));
 	if (!p)
 		return NULL;
 
-	memset(p, 0, sizeof(osm_qos_port_group_t));
 	cl_qmap_init(&p->port_map);
 
 	return p;
@@ -192,12 +191,10 @@ void osm_qos_policy_port_group_destroy(osm_qos_port_group_t * p)
 osm_qos_vlarb_scope_t *osm_qos_policy_vlarb_scope_create()
 {
 	osm_qos_vlarb_scope_t *p =
-	    (osm_qos_vlarb_scope_t *) malloc(sizeof(osm_qos_vlarb_scope_t));
+	    (osm_qos_vlarb_scope_t *) calloc(1, sizeof(osm_qos_vlarb_scope_t));
 	if (!p)
 		return NULL;
 
-	memset(p, 0, sizeof(osm_qos_vlarb_scope_t));
-
 	cl_list_init(&p->group_list, 10);
 	cl_list_init(&p->across_list, 10);
 	cl_list_init(&p->vlarb_high_list, 10);
@@ -238,12 +235,10 @@ void osm_qos_policy_vlarb_scope_destroy(osm_qos_vlarb_scope_t * p)
 osm_qos_sl2vl_scope_t *osm_qos_policy_sl2vl_scope_create()
 {
 	osm_qos_sl2vl_scope_t *p =
-	    (osm_qos_sl2vl_scope_t *) malloc(sizeof(osm_qos_sl2vl_scope_t));
+	    (osm_qos_sl2vl_scope_t *) calloc(1, sizeof(osm_qos_sl2vl_scope_t));
 	if (!p)
 		return NULL;
 
-	memset(p, 0, sizeof(osm_qos_sl2vl_scope_t));
-
 	cl_list_init(&p->group_list, 10);
 	cl_list_init(&p->across_from_list, 10);
 	cl_list_init(&p->across_to_list, 10);
@@ -280,10 +275,9 @@ void osm_qos_policy_sl2vl_scope_destroy(osm_qos_sl2vl_scope_t * p)
 osm_qos_level_t *osm_qos_policy_qos_level_create()
 {
 	osm_qos_level_t *p =
-	    (osm_qos_level_t *) malloc(sizeof(osm_qos_level_t));
+	    (osm_qos_level_t *) calloc(1, sizeof(osm_qos_level_t));
 	if (!p)
 		return NULL;
-	memset(p, 0, sizeof(osm_qos_level_t));
 	return p;
 }
 
@@ -360,12 +354,10 @@ ib_net16_t osm_qos_level_get_shared_pkey(IN const osm_qos_level_t * p_qos_level,
 osm_qos_match_rule_t *osm_qos_policy_match_rule_create()
 {
 	osm_qos_match_rule_t *p =
-	    (osm_qos_match_rule_t *) malloc(sizeof(osm_qos_match_rule_t));
+	    (osm_qos_match_rule_t *) calloc(1, sizeof(osm_qos_match_rule_t));
 	if (!p)
 		return NULL;
 
-	memset(p, 0, sizeof(osm_qos_match_rule_t));
-
 	cl_list_init(&p->source_list, 10);
 	cl_list_init(&p->source_group_list, 10);
 	cl_list_init(&p->destination_list, 10);
@@ -426,12 +418,10 @@ void osm_qos_policy_match_rule_destroy(osm_qos_match_rule_t * p)
 
 osm_qos_policy_t * osm_qos_policy_create(osm_subn_t * p_subn)
 {
-	osm_qos_policy_t * p_qos_policy = (osm_qos_policy_t *)malloc(sizeof(osm_qos_policy_t));
+	osm_qos_policy_t * p_qos_policy = (osm_qos_policy_t *)calloc(1, sizeof(osm_qos_policy_t));
 	if (!p_qos_policy)
 		return NULL;
 
-	memset(p_qos_policy, 0, sizeof(osm_qos_policy_t));
-
 	cl_list_construct(&p_qos_policy->port_groups);
 	cl_list_init(&p_qos_policy->port_groups, 10);
 
-- 
1.5.6.4




More information about the general mailing list