From: Ivan Bornyakov Date: Wed, 1 Aug 2018 18:37:44 +0000 (+0300) Subject: staging: gasket: sysfs: fix potential null dereference X-Git-Tag: v4.19-rc1~101^2~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=548b9f03f007ae654055644cff844b2b4fd2b5d2;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c index a4bfca43cd037..56d62aea51118 100644 --- a/drivers/staging/gasket/gasket_sysfs.c +++ b/drivers/staging/gasket/gasket_sysfs.c @@ -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;