staging: gasket: sysfs: fix potential null dereference

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Ivan Bornyakov 2018-08-01 21:37:44 +03:00 committed by Greg Kroah-Hartman
parent c0f460ffeb
commit 548b9f03f0
1 changed files with 5 additions and 0 deletions

View File

@ -101,6 +101,11 @@ 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) {
mutex_unlock(&mapping->mutex);
return;
}
for (i = 0; i < num_files_to_remove; i++)
files_to_remove[i] = mapping->attributes[i].attr;