summaryrefslogtreecommitdiff
path: root/drivers/staging/gasket
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2018-07-29 12:36:35 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-30 10:54:50 +0200
commit34cf3ea8dae7f0aa2ab544c1d30a803016af779e (patch)
treeabefe9abd8bae2476c304cfecd83f9ed7f63caf7 /drivers/staging/gasket
parent8dd8a48b9a7dae5493494a8603adddfdf1914716 (diff)
staging: gasket: sysfs: hold reference to device while in use
Hold a reference to the struct device while a gasket sysfs mapping exists for the device and a pointer to the struct is kept in the mapping data structures. Signed-off-by: Todd Poynor <toddpoynor@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/gasket')
-rw-r--r--drivers/staging/gasket/gasket_sysfs.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index da972ce0e0db..fde04658419b 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -126,6 +126,7 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
kfree(mapping->attributes);
mapping->attributes = NULL;
mapping->attribute_count = 0;
+ put_device(mapping->device);
mapping->device = NULL;
mapping->gasket_dev = NULL;
}
@@ -208,22 +209,20 @@ int gasket_sysfs_create_mapping(
device->kobj.name);
mapping = &dev_mappings[map_idx];
- kref_init(&mapping->refcount);
- mapping->device = device;
- mapping->gasket_dev = gasket_dev;
mapping->attributes = kcalloc(GASKET_SYSFS_MAX_NODES,
sizeof(*mapping->attributes),
GFP_KERNEL);
- mapping->attribute_count = 0;
if (!mapping->attributes) {
dev_dbg(device, "Unable to allocate sysfs attribute array\n");
- mapping->device = NULL;
- mapping->gasket_dev = NULL;
mutex_unlock(&mapping->mutex);
mutex_unlock(&function_mutex);
return -ENOMEM;
}
+ kref_init(&mapping->refcount);
+ mapping->device = get_device(device);
+ mapping->gasket_dev = gasket_dev;
+ mapping->attribute_count = 0;
mutex_unlock(&mapping->mutex);
mutex_unlock(&function_mutex);