From febda1fad456a7ada1a2af17b73b201f89313f61 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Sun, 5 Aug 2018 13:07:35 -0700 Subject: [PATCH] staging: gasket: sysfs: clean up state if ENOMEM removing mapping If kcalloc() returns NULL in put_mapping(), continue to clean up state, including dropping the reference on the struct device and free attribute memory. Signed-off-by: Todd Poynor Signed-off-by: Greg Kroah-Hartman --- gasket_sysfs.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gasket_sysfs.c b/gasket_sysfs.c index 56d62ae..fc45f0d 100644 --- a/gasket_sysfs.c +++ b/gasket_sysfs.c @@ -101,13 +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) { - mutex_unlock(&mapping->mutex); - return; - } - - for (i = 0; i < num_files_to_remove; i++) - files_to_remove[i] = mapping->attributes[i].attr; + if (files_to_remove) + for (i = 0; i < num_files_to_remove; i++) + files_to_remove[i] = + mapping->attributes[i].attr; + else + num_files_to_remove = 0; kfree(mapping->attributes); mapping->attributes = NULL;