Skip to contentSkip to conversation

powerpc/opal_elog: Handle multiple writes to ack attribute

PATCH Applied Aneesh Kumar K.V 3 participants 3 messages Oct 14, 2020 – Oct 16, 2020 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/opal_elog: Handle multiple writes to ack attribute

Even though we use self removing sysfs helper, we still need to make sure we do the final kobject delete conditionally. sysfs_remove_file_self() will handle parallel calls to remove the sysfs attribute file and returns true only in the caller that removed the attribute file. The other parallel callers are returned false. Do the final kobject delete checking the return value of sysfs_remove_file_self().

Cc Mahesh Salgaonkar <[email protected]>
Cc Oliver O'Halloran <[email protected]>
---
 arch/powerpc/platforms/powernv/opal-elog.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/opal-elog.c +8 -3
index 5e33b1fc67c2..37b380eef41a 100644
@@ -72,9 +72,14 @@ static ssize_t elog_ack_store(struct elog_obj *elog_obj,
 			      const char *buf,
 			      size_t count)
 {
-	opal_send_ack_elog(elog_obj->id);
-	sysfs_remove_file_self(&elog_obj->kobj, &attr->attr);
-	kobject_put(&elog_obj->kobj);
+	/*
+	 * Try to self remove this attribute. If we are successful,
+	 * delete the kobject itself.
+	 */
+	if (sysfs_remove_file_self(&elog_obj->kobj, &attr->attr)) {
+		opal_send_ack_elog(elog_obj->id);
+		kobject_put(&elog_obj->kobj);
+	}
 	return count;
 }
 
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Aneesh Kumar K.V

Even though we use self removing sysfs helper, we still need to make sure we do the final kobject delete conditionally. sysfs_remove_file_self() will handle parallel calls to remove the sysfs attribute file and returns true only in the caller that removed the attribute file. The other parallel callers are returned false. Do the final kobject delete checking the return value of sysfs_remove_file_self().

Cc Mahesh Salgaonkar <[email protected]>
Cc Oliver O'Halloran <[email protected]>
---
 arch/powerpc/platforms/powernv/opal-elog.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/opal-elog.c +0 -3
index 5e33b1fc67c2..37b380eef41a 100644
@@ -72,9 +72,14 @@ static ssize_t elog_ack_store(struct elog_obj *elog_obj,
 			      const char *buf,
 			      size_t count)
 {
-	opal_send_ack_elog(elog_obj->id);
-	sysfs_remove_file_self(&elog_obj->kobj, &attr->attr);
-	kobject_put(&elog_obj->kobj);

arch/powerpc/platforms/powernv/opal-elog.c static ssize_t elog_ack_store(struct elog_obj *elog_obj, · line 84

Quoted 10 lines
arch/powerpc/platforms/powernv/opal-elog.c +8 -0
+	/*
+	 * Try to self remove this attribute. If we are successful,
+	 * delete the kobject itself.
+	 */
+	if (sysfs_remove_file_self(&elog_obj->kobj, &attr->attr)) {
+		opal_send_ack_elog(elog_obj->id);
+		kobject_put(&elog_obj->kobj);
+	}
 	return count;
 }

Looks good.

Thanks,
-Mahesh.

#2 lore raw
In reply to Aneesh Kumar K.V
Quoted 7 lines · Aneesh Kumar K.V

Even though we use self removing sysfs helper, we still need to make sure we do the final kobject delete conditionally. sysfs_remove_file_self() will handle parallel calls to remove the sysfs attribute file and returns true only in the caller that removed the attribute file. The other parallel callers are returned false. Do the final kobject delete checking the return value of sysfs_remove_file_self().

Applied to powerpc/fixes.

[1/1] powerpc/opal_elog: Handle multiple writes to ack attribute

      https://git.kernel.org/powerpc/c/d4263b12a1a0e8816e021450be0765a1ad8bb53c

cheers