staging: gasket: sysfs: fix potential null dereference
authorIvan Bornyakov <brnkv.i1@gmail.com>
Wed, 1 Aug 2018 18:37:44 +0000 (21:37 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Aug 2018 06:14:35 +0000 (08:14 +0200)
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>
drivers/staging/gasket/gasket_sysfs.c

index a4bfca4..56d62ae 100644 (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;