lkml.org 
[lkml]   [2018]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] staging: gasket: sysfs: fix potential null dereference
Date
Add handling of possible allocation failure.

Reported by smatch:

drivers/staging/gasket/gasket_sysfs.c:105 put_mapping() error: potential null dereference 'files_to_remove'. (kcalloc returns null)

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
---
drivers/staging/gasket/gasket_sysfs.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index ef4eca02afa6..682e5c21f203 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -101,6 +101,12 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
files_to_remove = kcalloc(num_files_to_remove,
sizeof(*files_to_remove),
GFP_KERNEL);
+ if (!files_to_remove) {
+ pr_err("%s: can't allocate memory\n", __func__);
+ mutex_unlock(&mapping->mutex);
+ return;
+ }
+
for (i = 0; i < num_files_to_remove; i++)
files_to_remove[i] = mapping->attributes[i].attr;

--
2.16.4
\
 
 \ /
  Last update: 2018-07-31 17:24    [W:0.037 / U:0.352 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site