* [PATCH] Remove duplicated code in mpath_alloc_prin_response()
@ 2016-10-25 8:19 ding.yemin
2016-10-28 15:16 ` Bart Van Assche
0 siblings, 1 reply; 4+ messages in thread
From: ding.yemin @ 2016-10-25 8:19 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: tang.junhui, zhang.kai16, ding.yemin, dm-devel
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(-)
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;
}
--
2.8.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Remove duplicated code in mpath_alloc_prin_response()
2016-10-25 8:19 ding.yemin
@ 2016-10-28 15:16 ` Bart Van Assche
2016-10-31 2:03 ` ding.yemin
0 siblings, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2016-10-28 15:16 UTC (permalink / raw)
To: ding.yemin, Christophe Varoqui; +Cc: zhang.kai16, dm-devel, tang.junhui
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Remove duplicated code in mpath_alloc_prin_response()
2016-10-28 15:16 ` Bart Van Assche
@ 2016-10-31 2:03 ` ding.yemin
0 siblings, 0 replies; 4+ messages in thread
From: ding.yemin @ 2016-10-31 2:03 UTC (permalink / raw)
To: Bart Van Assche; +Cc: dm-devel, tang.junhui, zhang.kai16
[-- Attachment #1.1: Type: text/plain, Size: 1015 bytes --]
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.
[-- Attachment #1.2: Type: text/html, Size: 2772 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Remove duplicated code in mpath_alloc_prin_response()
@ 2016-10-31 2:55 ding.yemin
0 siblings, 0 replies; 4+ messages in thread
From: ding.yemin @ 2016-10-31 2:55 UTC (permalink / raw)
To: Christophe Varoqui
Cc: tang.junhui, zhang.kai16, ding.yemin, dm-devel, bart.vanassche
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 | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c
index 7501651..633e462 100644
--- a/libmpathpersist/mpath_persist.c
+++ b/libmpathpersist/mpath_persist.c
@@ -833,26 +833,22 @@ 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 = calloc(size, 1);
+ }
return ptr;
}
--
2.8.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-10-31 2:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-31 2:55 [PATCH] Remove duplicated code in mpath_alloc_prin_response() ding.yemin
-- strict thread matches above, loose matches on Subject: below --
2016-10-25 8:19 ding.yemin
2016-10-28 15:16 ` Bart Van Assche
2016-10-31 2:03 ` ding.yemin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).