Skip to contentSkip to conversation

umh: Optimize 'proc_cap_handler()'

PATCH Applied Christophe JAILLET 2 participants 3 messages Oct 20, 2017 – Nov 10, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 umh: Optimize 'proc_cap_handler()'

If 'write' is 0, we can avoid a call to spin_lock/spin_unlock.

---
 kernel/umh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/umh.c +2 -2
index 6ff9905250ff..18e5fa4b0e71 100644
@@ -537,14 +537,14 @@ static int proc_cap_handler(struct ctl_table *table, int write,
 	/*
 	 * Drop everything not in the new_cap (but don't add things)
 	 */
-	spin_lock(&umh_sysctl_lock);
 	if (write) {
+		spin_lock(&umh_sysctl_lock);
 		if (table->data = CAP_BSET)
 			usermodehelper_bset = cap_intersect(usermodehelper_bset, new_cap);
 		if (table->data = CAP_PI)
 			usermodehelper_inheritable = cap_intersect(usermodehelper_inheritable, new_cap);
+		spin_unlock(&umh_sysctl_lock);
 	}
-	spin_unlock(&umh_sysctl_lock);
 
 	return 0;
 }
Signature · 1 line
2.14.1
#1 lore raw
Quoted 3 lines · Christophe JAILLET

If 'write' is 0, we can avoid a call to spin_lock/spin_unlock.

Sorry for the delay, I was travelling and will start nose diving now. I hope to have a concrete review and answer by tomorrow. Sorry for the two week delay on the review and thanks for the patch!

Luis

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Christophe JAILLET
Quoted 3 lines · Christophe JAILLET

If 'write' is 0, we can avoid a call to spin_lock/spin_unlock.

Thanks for the patch!

I'll bounce a copy to Andrew for integration next.

Luis

Quoted 29 lines
---
 kernel/umh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/umh.c +2 -2
index 6ff9905250ff..18e5fa4b0e71 100644
@@ -537,14 +537,14 @@ static int proc_cap_handler(struct ctl_table *table, int write,
 	/*
 	 * Drop everything not in the new_cap (but don't add things)
 	 */
-	spin_lock(&umh_sysctl_lock);
 	if (write) {
+		spin_lock(&umh_sysctl_lock);
 		if (table->data = CAP_BSET)
 			usermodehelper_bset = cap_intersect(usermodehelper_bset, new_cap);
 		if (table->data = CAP_PI)
 			usermodehelper_inheritable = cap_intersect(usermodehelper_inheritable, new_cap);
+		spin_unlock(&umh_sysctl_lock);
 	}
-	spin_unlock(&umh_sysctl_lock);
 
 	return 0;
 }
Signature · 1 line
2.14.1
Signature · 2 lines
Luis Rodriguez, SUSE LINUX GmbH
Maxfeldstrasse 5; D-90409 Nuernberg