All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fmc: add error handling for kmemdup
@ 2018-06-12  3:20 Zhouyang Jia
  0 siblings, 0 replies; only message in thread
From: Zhouyang Jia @ 2018-06-12  3:20 UTC (permalink / raw)
  Cc: Zhouyang Jia, Alessandro Rubini, linux-kernel

When kmemdup fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling kmemdup.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/fmc/fmc-fakedev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/fmc/fmc-fakedev.c b/drivers/fmc/fmc-fakedev.c
index 941d093..62d9046 100644
--- a/drivers/fmc/fmc-fakedev.c
+++ b/drivers/fmc/fmc-fakedev.c
@@ -282,6 +282,9 @@ static struct ff_dev *ff_dev_create(void)
 	for (i = 0; i < ff_nr_dev; i++) {
 		fmc = kmemdup(&ff_template_fmc, sizeof(ff_template_fmc),
 			      GFP_KERNEL);
+		if (!fmc)
+			return ERR_PTR(-ENOMEM);
+
 		fmc->hwdev = &ff->dev;
 		fmc->carrier_data = ff;
 		fmc->nr_slots = ff_nr_dev;
-- 
2.7.4


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

only message in thread, other threads:[~2018-06-12  3:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  3:20 [PATCH] fmc: add error handling for kmemdup Zhouyang Jia

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.