Skip to contentSkip to conversation

Remove duplicated code in mpath_alloc_prin_response()

PATCH In review [email protected] 2 participants 3 messages Oct 25, 2016 – Oct 31, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove duplicated code in mpath_alloc_prin_response()

From: "ding.yemin" <[email protected]>

Remove duplicated code in mpath_alloc_prin_response().

---
 libmpathpersist/mpath_persist.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
libmpathpersist/mpath_persist.c +8 -8
index 7501651..5962756 100644
@@ -833,26 +833,26 @@ void * mpath_alloc_prin_response(int prin_sa)
 	{
 		case MPATH_PRIN_RKEY_SA:
 			size = sizeof(struct prin_readdescr);
-			ptr = malloc(size);
-			memset(ptr, 0, size);
 			break;
 		case MPATH_PRIN_RRES_SA:
 			size = sizeof(struct prin_resvdescr);
-			ptr = malloc(size);
-			memset(ptr, 0, size);
 			break;
 		case MPATH_PRIN_RCAP_SA:
 			size=sizeof(struct prin_capdescr);
-			ptr = malloc(size);
-			memset(ptr, 0, size);
 			break;
 		case MPATH_PRIN_RFSTAT_SA:
 			size = sizeof(struct print_fulldescr_list) +
 				sizeof(struct prin_fulldescr *)*MPATH_MX_TIDS;
-			ptr = malloc(size);
-			memset(ptr, 0, size);
 			break;
 	}
+	if (size > 0)
+	{
+		ptr = malloc(size);
+		if (ptr)
+		{
+			memset(ptr, 0, size);
+		}
+	}
 	return ptr;
 }
 
Signature · 1 line
2.8.1.windows.1
#1 lore raw

libmpathpersist/mpath_persist.c void * mpath_alloc_prin_response(int prin_sa) · line 857

Quoted 11 lines · On 10/25/2016 01:19 AM, [email protected] wrote:
libmpathpersist/mpath_persist.c +8 -0
 	}
+	if (size > 0)
+	{
+		ptr = malloc(size);
+		if (ptr)
+		{
+			memset(ptr, 0, size);
+		}
+	}
 	return ptr;
 }

Hello Ding Yemin,

Please use calloc() instead of open coding it.

Thanks,

Bart.

#2 lore raw

Hello Bart,

Thanks for your review. Using calloc() is really better than malloc(). I will modify and commit it later.

Thanks,

Ding Yemin.

Bart Van Assche <[email protected]>
2016-10-28 23:16

收件人
<[email protected]>, Christophe Varoqui <[email protected]>,
抄送
<[email protected]>, <[email protected]>, <[email protected]> 主题
Re: [dm-devel] [PATCH] Remove duplicated code in mpath_alloc_prin_response()

libmpathpersist/mpath_persist.c void * mpath_alloc_prin_response(int prin_sa) · line 857

Quoted 11 lines · On 10/25/2016 01:19 AM, [email protected] wrote:
               }
libmpathpersist/mpath_persist.c +8 -0
+              if (size > 0)
+              {
+                              ptr = malloc(size);
+                              if (ptr)
+                              {
+                                              memset(ptr, 0, size);
+                              }
+              }
               return ptr;
 }

Hello Ding Yemin,

Please use calloc() instead of open coding it.

Thanks,

Bart.