Skip to contentSkip to conversation

drivers/staging/gasket: Use refcount_read()

PATCH In review Todd Poynor 2 participants 2 messages Jul 7, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/staging/gasket: Use refcount_read()

From: Todd Poynor <[email protected]>

Use the refcount_read accessor function, avoid reaching into refcount and atomic struct fields.

---
 drivers/staging/gasket/gasket_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_sysfs.c +1 -1
index d45098c90b4b..b5cdc180772a 100644
@@ -122,7 +122,7 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 	}
 
 	mutex_lock(&mapping->mutex);
-	if (mapping->refcount.refcount.refs.counter == 0)
+	if (refcount_read(&mapping->refcount.refcount) == 0)
 		gasket_nodev_error("Refcount is already 0!");
 	if (kref_put(&mapping->refcount, release_entry)) {
 		gasket_nodev_info("Removing Gasket sysfs mapping, device %s",
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
#1 lore raw
Quoted 15 lines · Todd Poynor

From: Todd Poynor <[email protected]>

Use the refcount_read accessor function, avoid reaching into refcount and atomic struct fields.

---
 drivers/staging/gasket/gasket_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_sysfs.c +0 -0
index d45098c90b4b..b5cdc180772a 100644

drivers/staging/gasket/gasket_sysfs.c static void put_mapping(struct gasket_sysfs_mapping *mapping) · line 128

Quoted 8 lines
drivers/staging/gasket/gasket_sysfs.c +1 -1
@@ -122,7 +122,7 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 	}
 
 	mutex_lock(&mapping->mutex);
-	if (mapping->refcount.refcount.refs.counter == 0)
+	if (refcount_read(&mapping->refcount.refcount) == 0)
 		gasket_nodev_error("Refcount is already 0!");
 	if (kref_put(&mapping->refcount, release_entry)) {
 		gasket_nodev_info("Removing Gasket sysfs mapping, device %s",

Thanks for the patch, but ugh, why in the world is this driver even doing this type of thing? Odds are all of these reference counting checks can be removed, something else to add to the "todo" file...

thanks,

greg k-h