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 |
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
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 --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; }