* [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation
@ 2019-07-03 13:13 Fuqian Huang
2019-07-03 13:19 ` Christophe Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Fuqian Huang @ 2019-07-03 13:13 UTC (permalink / raw)
Cc: linux-kernel, Paul Mackerras, Fuqian Huang, linuxppc-dev
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memset, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memset.
Add an allocation failure check.
Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
---
arch/powerpc/platforms/pseries/dlpar.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index 437a74173db2..20fe7b79e09e 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -383,9 +383,10 @@ void queue_hotplug_event(struct pseries_hp_errorlog *hp_errlog)
struct pseries_hp_work *work;
struct pseries_hp_errorlog *hp_errlog_copy;
- hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog),
+ hp_errlog_copy = kmemdup(hp_errlog, sizeof(struct pseries_hp_errorlog),
GFP_KERNEL);
- memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog));
+ if (!hp_errlog_copy)
+ return;
work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL);
if (work) {
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation
2019-07-03 13:13 [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation Fuqian Huang
@ 2019-07-03 13:19 ` Christophe Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Christophe Leroy @ 2019-07-03 13:19 UTC (permalink / raw)
To: Fuqian Huang; +Cc: linuxppc-dev, Paul Mackerras, linux-kernel
Le 03/07/2019 à 15:13, Fuqian Huang a écrit :
> kmemdup is introduced to duplicate a region of memory in a neat way.
> Rather than kmalloc/kzalloc + memset, which the programmer needs to
> write the size twice (sometimes lead to mistakes), kmemdup improves
> readability, leads to smaller code and also reduce the chances of mistakes.
> Suggestion to use kmemdup rather than using kmalloc/kzalloc + memset.
s/memset/memcpy/
>
> Add an allocation failure check.
Shouldn't this be in another patch ?
Christophe
>
> Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
> ---
> arch/powerpc/platforms/pseries/dlpar.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
> index 437a74173db2..20fe7b79e09e 100644
> --- a/arch/powerpc/platforms/pseries/dlpar.c
> +++ b/arch/powerpc/platforms/pseries/dlpar.c
> @@ -383,9 +383,10 @@ void queue_hotplug_event(struct pseries_hp_errorlog *hp_errlog)
> struct pseries_hp_work *work;
> struct pseries_hp_errorlog *hp_errlog_copy;
>
> - hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog),
> + hp_errlog_copy = kmemdup(hp_errlog, sizeof(struct pseries_hp_errorlog),
> GFP_KERNEL);
> - memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog));
> + if (!hp_errlog_copy)
> + return;
>
> work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL);
> if (work) {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-03 13:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03 13:13 [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation Fuqian Huang
2019-07-03 13:19 ` Christophe Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox