diff mbox

Remove duplicated code in mpath_alloc_prin_response()

Message ID 1477383563-10684-1-git-send-email-ding.yemin@zte.com.cn (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show

Commit Message

ding.yemin@zte.com.cn Oct. 25, 2016, 8:19 a.m. UTC
From: "ding.yemin" <ding.yemin@zte.com.cn>

Remove duplicated code in mpath_alloc_prin_response().

Signed-off-by: ding.yemin <ding.yemin@zte.com.cn>
---
 libmpathpersist/mpath_persist.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Bart Van Assche Oct. 28, 2016, 3:16 p.m. UTC | #1
On 10/25/2016 01:19 AM, ding.yemin@zte.com.cn wrote:
>  	}
> +	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.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
ding.yemin@zte.com.cn Oct. 31, 2016, 2:03 a.m. UTC | #2
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 <bart.vanassche@sandisk.com> 
2016-10-28 23:16

收件人
<ding.yemin@zte.com.cn>, Christophe Varoqui 
<christophe.varoqui@opensvc.com>, 
抄送
<tang.junhui@zte.com.cn>, <zhang.kai16@zte.com.cn>, <dm-devel@redhat.com>
主题
Re: [dm-devel] [PATCH] Remove duplicated code in 
mpath_alloc_prin_response()






On 10/25/2016 01:19 AM, ding.yemin@zte.com.cn wrote:
>                }

> +              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.
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c
index 7501651..5962756 100644
--- a/libmpathpersist/mpath_persist.c
+++ b/libmpathpersist/mpath_persist.c
@@ -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;
 }