[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180729193646.201721-3-toddpoynor@gmail.com>
Date: Sun, 29 Jul 2018 12:36:35 -0700
From: Todd Poynor <toddpoynor@...il.com>
To: Rob Springer <rspringer@...gle.com>,
John Joseph <jnjoseph@...gle.com>,
Ben Chan <benchan@...omium.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org,
Dmitry Torokhov <dtor@...omium.org>,
Todd Poynor <toddpoynor@...gle.com>
Subject: [PATCH 02/13] staging: gasket: sysfs: hold reference to device while in use
From: Todd Poynor <toddpoynor@...gle.com>
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@...gle.com>
---
drivers/staging/gasket/gasket_sysfs.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index da972ce0e0db0..fde04658419bc 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);
--
2.18.0.345.g5c9ce644c3-goog
Powered by blists - more mailing lists