Commit 34cf3ea8 authored by Todd Poynor's avatar Todd Poynor Committed by Greg Kroah-Hartman

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: default avatarTodd Poynor <toddpoynor@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8dd8a48b
...@@ -126,6 +126,7 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping) ...@@ -126,6 +126,7 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
kfree(mapping->attributes); kfree(mapping->attributes);
mapping->attributes = NULL; mapping->attributes = NULL;
mapping->attribute_count = 0; mapping->attribute_count = 0;
put_device(mapping->device);
mapping->device = NULL; mapping->device = NULL;
mapping->gasket_dev = NULL; mapping->gasket_dev = NULL;
} }
...@@ -208,22 +209,20 @@ int gasket_sysfs_create_mapping( ...@@ -208,22 +209,20 @@ int gasket_sysfs_create_mapping(
device->kobj.name); device->kobj.name);
mapping = &dev_mappings[map_idx]; mapping = &dev_mappings[map_idx];
kref_init(&mapping->refcount);
mapping->device = device;
mapping->gasket_dev = gasket_dev;
mapping->attributes = kcalloc(GASKET_SYSFS_MAX_NODES, mapping->attributes = kcalloc(GASKET_SYSFS_MAX_NODES,
sizeof(*mapping->attributes), sizeof(*mapping->attributes),
GFP_KERNEL); GFP_KERNEL);
mapping->attribute_count = 0;
if (!mapping->attributes) { if (!mapping->attributes) {
dev_dbg(device, "Unable to allocate sysfs attribute array\n"); dev_dbg(device, "Unable to allocate sysfs attribute array\n");
mapping->device = NULL;
mapping->gasket_dev = NULL;
mutex_unlock(&mapping->mutex); mutex_unlock(&mapping->mutex);
mutex_unlock(&function_mutex); mutex_unlock(&function_mutex);
return -ENOMEM; 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(&mapping->mutex);
mutex_unlock(&function_mutex); mutex_unlock(&function_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment