staging: gasket: sysfs: fix potential null dereference
PATCH 1/1 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)
--- drivers/staging/gasket/gasket_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/staging/gasket/gasket_sysfs.c +6 -0
@@ -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;
Signature · 1 line
2.16.4
Greg KH
maintainerQuoted 16 lines · Ivan Bornyakov
Add handling of possible allocation failure.
Reported by smatch:
drivers/staging/gasket/gasket_sysfs.c:105put_mapping()error: potential null dereference 'files_to_remove'. (kcalloc returns null)Signed-off-by Ivan Bornyakov <[email protected]>--- drivers/staging/gasket/gasket_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/staging/gasket/gasket_sysfs.c +0
-0
drivers/staging/gasket/gasket_sysfs.c static void put_mapping(struct gasket_sysfs_mapping *mapping) · line 105
Quoted 5 lines
drivers/staging/gasket/gasket_sysfs.c +2
-0@@ -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__);
kcalloc failing will print something, no need to do it again here.
thanks,
greg k-h
PATCH v2 1/1 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)
--- drivers/staging/gasket/gasket_sysfs.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/staging/gasket/gasket_sysfs.c +5 -0
@@ -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;
Signature · 1 line
2.16.4