[PATCH] fmc: add error handling for kmemdup
From: Zhouyang Jia
Date: Mon Jun 11 2018 - 23:20:47 EST
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@xxxxxxxxx>
---
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