mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fmc: correctly handle failed allocation
@ 2015-10-15 15:42 Insu Yun
  0 siblings, 0 replies; only message in thread
From: Insu Yun @ 2015-10-15 15:42 UTC (permalink / raw)
  To: rubini, linux-kernel; +Cc: taesoo, yeongjin.jang, insu, Insu Yun

Since kmemdup can be failed in memory pressure,
return value should be checked and return -ENOMEM.

Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
 drivers/fmc/fmc-fakedev.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/fmc/fmc-fakedev.c b/drivers/fmc/fmc-fakedev.c
index 941d093..0515909 100644
--- a/drivers/fmc/fmc-fakedev.c
+++ b/drivers/fmc/fmc-fakedev.c
@@ -282,6 +282,8 @@ 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)
+      goto no_memory;
 		fmc->hwdev = &ff->dev;
 		fmc->carrier_data = ff;
 		fmc->nr_slots = ff_nr_dev;
@@ -294,6 +296,12 @@ static struct ff_dev *ff_dev_create(void)
 		ff_template_fmc.device_id++;
 	}
 	return ff;
+
+no_memory:
+  for (i--; i >= 0; i--)
+    kfree(ff->fmc[i]);
+  kfree(ff);
+  return ERR_PTR(-ENOMEM);
 }
 
 /* init and exit */
-- 
1.9.1


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

only message in thread, other threads:[~2015-10-15 15:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-15 15:42 [PATCH] fmc: correctly handle failed allocation Insu Yun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®