Skip to contentSkip to conversation

ptrace: annotate siglock acquisition

PATCH In review Namhyung Kim 2 participants 2 messages Sep 25, 2010 – Sep 26, 2010 ptrace support

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ptrace: annotate siglock acquisition

lock_task_sighand() conditionally acquires sighand->siglock in case of returning non-NULL but unlock_task_sighand() releases it unconditionally. This leads sparse to complain about the lock context imbalance. Annotate it to make sparse happier.

---

Roland, I sent the same patch a month ago and got your Acked-by but this time I update it using __cond_lock() suggested by Al Viro. Please take a look again, Thanks.

 kernel/ptrace.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/ptrace.c +4 -2
index f34d798..8d9b7b2 100644
@@ -435,7 +435,8 @@ static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)
 	unsigned long flags;
 	int error = -ESRCH;
 
-	if (lock_task_sighand(child, &flags)) {
+	if (__cond_lock(&child->sighand->siglock,
+			lock_task_sighand(child, &flags))) {
 		error = -EINVAL;
 		if (likely(child->last_siginfo != NULL)) {
 			*info = *child->last_siginfo;
@@ -451,7 +452,8 @@ static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
 	unsigned long flags;
 	int error = -ESRCH;
 
-	if (lock_task_sighand(child, &flags)) {
+	if (__cond_lock(&child->sighand->siglock,
+			lock_task_sighand(child, &flags))) {
 		error = -EINVAL;
 		if (likely(child->last_siginfo != NULL)) {
 			*child->last_siginfo = *info;
Signature · 1 line
1.7.2.2
maintainer
#1 lore raw

kernel/ptrace.c static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info) · line 439

Quoted 10 lines · Namhyung Kim
kernel/ptrace.c +2 -1
@@ -435,7 +435,8 @@ static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)
 	unsigned long flags;
 	int error = -ESRCH;
 
-	if (lock_task_sighand(child, &flags)) {
+	if (__cond_lock(&child->sighand->siglock,
+			lock_task_sighand(child, &flags))) {

Well, this looks fine, but if we are going to make sparse happy then we have more callers to fix.

Perhaps we should just renam lock_task_sighand to __lock_task_sighand and add

	#define lock_task_sighand(tsk, flagsp)	\
		__cond_lock((tsk)->sighand->siglock, __lock_task_sighand((tsk), (flagsp)))

?

Oleg.