Skip to contentSkip to conversation

acct: eliminate compile warning

PATCH In review Ying Xue 3 participants 3 messages Aug 21, 2014 – Nov 5, 2014

lore
Share & tools
lore

Ying Xue

author
#0 lore raw

PATCH 1/1 acct: eliminate compile warning

If ACCT_VERSION is not defined to 3, below warning appears:
CC kernel/acct.o
kernel/acct.c: In function ‘do_acct_process’:
kernel/acct.c:475:24: warning: unused variable ‘ns’ [-Wunused-variable]

---
 kernel/acct.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/acct.c +3 -3
index b4c667d..bb52701 100644
@@ -472,7 +472,6 @@ static void do_acct_process(struct bsd_acct_struct *acct)
 	acct_t ac;
 	unsigned long flim;
 	const struct cred *orig_cred;
-	struct pid_namespace *ns = acct->ns;
 	struct file *file = acct->file;
 
 	/*
@@ -500,9 +499,10 @@ static void do_acct_process(struct bsd_acct_struct *acct)
 	ac.ac_gid16 = ac.ac_gid;
 #endif
 #if ACCT_VERSION == 3
-	ac.ac_pid = task_tgid_nr_ns(current, ns);
+	ac.ac_pid = task_tgid_nr_ns(current, acct->ns);
 	rcu_read_lock();
-	ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns);
+	ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent),
+				     acct->ns);
 	rcu_read_unlock();
 #endif
 	/*
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 24 lines · On Thu, 21 Aug 2014 09:58:46 +0800 Ying Xue <[email protected]> wrote:

If ACCT_VERSION is not defined to 3, below warning appears:
CC kernel/acct.o
kernel/acct.c: In function ___do_acct_process___:
kernel/acct.c:475:24: warning: unused variable ___ns___ [-Wunused-variable]

---
 kernel/acct.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/acct.c +0 -1
index b4c667d..bb52701 100644
@@ -472,7 +472,6 @@ static void do_acct_process(struct bsd_acct_struct *acct)
 	acct_t ac;
 	unsigned long flim;
 	const struct cred *orig_cred;
-	struct pid_namespace *ns = acct->ns;
 	struct file *file = acct->file;
 
 	/*
@@ -500,9 +499,10 @@ static void do_acct_process(struct bsd_acct_struct *acct)
 	ac.ac_gid16 = ac.ac_gid;

kernel/acct.c static void do_acct_process(struct bsd_acct_struct *acct) · line 507

Quoted 10 lines
kernel/acct.c +3 -2
 #endif
 #if ACCT_VERSION == 3
-	ac.ac_pid = task_tgid_nr_ns(current, ns);
+	ac.ac_pid = task_tgid_nr_ns(current, acct->ns);
 	rcu_read_lock();
-	ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns);
+	ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent),
+				     acct->ns);
 	rcu_read_unlock();
 #endif

With my gcc this change increases .text from 5429 to 5437 bytes. If we do it this way:

kernel/acct.c renamed from kernel/acct.c~acct-eliminate-compile-warning-fix +9 -5
@@ -499,11 +499,15 @@ static void do_acct_process(struct bsd_a
 	ac.ac_gid16 = ac.ac_gid;
 #endif
 #if ACCT_VERSION == 3
-	ac.ac_pid = task_tgid_nr_ns(current, acct->ns);
-	rcu_read_lock();
-	ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent),
-				     acct->ns);
-	rcu_read_unlock();
+	{
+		struct pid_namespace *ns = acct->ns;
+
+		ac.ac_pid = task_tgid_nr_ns(current, ns);
+		rcu_read_lock();
+		ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent),
+					     ns);
+		rcu_read_unlock();
+	}
 #endif
 	/*
 	 * Get freeze protection. If the fs is frozen, just skip the write

it actually shrinks to 5415 bytes. Weird.

We could actually do

	if (ACCT_VERSION == 3)
		...

in lots of places in acct.c. The code would be less ugly and compilation coverage testing would improve.

#2 lore raw
Quoted 7 lines · Andrew Morton

We could actually do

	if (ACCT_VERSION == 3)
		...

in lots of places in acct.c. The code would be less ugly and compilation coverage testing would improve.

... too much. Finally got around to trying that; the problem is that you can't do that in structure declarations. acct_t is either struct acct, or struct acct_v3, and while we could split fill_ac() into v3 and v1/v2 versions, it still doesn't sort everything out. So it looks like that idea is no-go ;-/