* [PATCH] fmc: fix to avoid NULL pointer dereference
@ 2019-03-19 19:28 Aditya Pakki
0 siblings, 0 replies; only message in thread
From: Aditya Pakki @ 2019-03-19 19:28 UTC (permalink / raw)
To: pakki001; +Cc: kjlu, Alessandro Rubini, linux-kernel
kmemdup can fail to allocate memory and result in a NULL pointer
dereference. The patches avoids such a scenario.
Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
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 941d0930969a..d634c901b4f3 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 rollback;
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;
+
+rollback:
+ for (i--; i >= 0; i--)
+ kfree(ff->fmc[i]);
+ kfree(ff);
+ return ERR_PTR(-ENOMEM);
}
/* init and exit */
--
2.17.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-03-19 19:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 19:28 [PATCH] fmc: fix to avoid NULL pointer dereference Aditya Pakki
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).