linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 18/30] pcmcia: Use kmemdup rather than duplicating its implementation
@ 2019-07-03 13:16 Fuqian Huang
  0 siblings, 0 replies; only message in thread
From: Fuqian Huang @ 2019-07-03 13:16 UTC (permalink / raw)
  Cc: Dominik Brodowski, linux-kernel, Fuqian Huang

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.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
---
 drivers/pcmcia/cistpl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index abd029945cc8..eff91726f121 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -414,14 +414,13 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
 	}
 	mutex_lock(&s->ops_mutex);
 	kfree(s->fake_cis);
-	s->fake_cis = kmalloc(len, GFP_KERNEL);
+	s->fake_cis = kmemdup(data, len, GFP_KERNEL);
 	if (s->fake_cis == NULL) {
 		dev_warn(&s->dev, "no memory to replace CIS\n");
 		mutex_unlock(&s->ops_mutex);
 		return -ENOMEM;
 	}
 	s->fake_cis_len = len;
-	memcpy(s->fake_cis, data, len);
 	dev_info(&s->dev, "Using replacement CIS\n");
 	mutex_unlock(&s->ops_mutex);
 	return 0;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-03 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 13:16 [PATCH 18/30] pcmcia: Use kmemdup rather than duplicating its implementation Fuqian Huang

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).