Skip to contentSkip to conversation

kernel: pid: Update documentation.

PATCH New Varsha Rao 1 participant 3 messages Mar 28, 2017 1 message not in the archive

lore
Share & tools
lore

Varsha Rao

author
#1 lore raw

PATCH v3 1/3 kernel: pid: Update documentation.

In reply to a message not in the archive

This patch adds comments to update documentation.

---
Changes in v3:
- Changed the comment style.

Changes in v2:
- No change.

 kernel/pid.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
kernel/pid.c +21 -0
index 0143ac0..01fb660 100644
@@ -42,6 +42,8 @@
 
 #define pid_hashfn(nr, ns)	\
 	hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
+
+/* Doubly linked hash lists to find PID in given namespace. */
 static struct hlist_head *pid_hash;
 static unsigned int pidhash_shift = 4;
 struct pid init_struct_pid = INIT_STRUCT_PID;
@@ -53,6 +55,7 @@ int pid_max = PID_MAX_DEFAULT;
 int pid_max_min = RESERVED_PIDS + 1;
 int pid_max_max = PID_MAX_LIMIT;
 
+/* mk_pid() - Return distance between map and offset pidmap. */
 static inline int mk_pid(struct pid_namespace *pid_ns,
 		struct pidmap *map, int off)
 {
@@ -101,6 +104,7 @@ EXPORT_SYMBOL_GPL(init_pid_ns);
 
 static  __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock);
 
+/* free_pidmap() - Free process id. */
 static void free_pidmap(struct upid *upid)
 {
 	int nr = upid->nr;
@@ -150,6 +154,10 @@ static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
 	} while ((prev != last_write) && (pid_before(base, last_write, pid)));
 }
 
+/*
+ * alloc_pidmap() - Increment last pid by one and return it if new pid
+ * is valid.
+ */
 static int alloc_pidmap(struct pid_namespace *pid_ns)
 {
 	int i, offset, max_scan, pid, last = pid_ns->last_pid;
@@ -212,6 +220,10 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
 	return -EAGAIN;
 }
 
+/*
+ * next_pidmap() - Find the first pid which is greater than previous
+ * last allocated pid.
+ */
 int next_pidmap(struct pid_namespace *pid_ns, unsigned int last)
 {
 	int offset;
@@ -233,6 +245,7 @@ int next_pidmap(struct pid_namespace *pid_ns, unsigned int last)
 	return -1;
 }
 
+/* put_pid() - Check whether pid can be reallocated. */
 void put_pid(struct pid *pid)
 {
 	struct pid_namespace *ns;
@@ -249,6 +262,10 @@ void put_pid(struct pid *pid)
 }
 EXPORT_SYMBOL_GPL(put_pid);
 
+/*
+ * delayed_put_pid() - Find the real location of struct pid in the
+ * memory and check whether it can be reallocated with put_pid().
+ */
 static void delayed_put_pid(struct rcu_head *rhp)
 {
 	struct pid *pid = container_of(rhp, struct pid, rcu);
@@ -293,6 +310,10 @@ void free_pid(struct pid *pid)
 	call_rcu(&pid->rcu, delayed_put_pid);
 }
 
+/*
+ * alloc_pid() - Allocate local pid for each multiple namespaces
+ * in which new process created is visible.
+ */
 struct pid *alloc_pid(struct pid_namespace *ns)
 {
 	struct pid *pid;
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH v3 2/3 kernel: pid: Change function return value to bool.

In reply to a message not in the archive

Replace unsigned with unsigned int and add bool as return type for pid_before() function. As the function is called only once in condition for do while loop. This patch fixes the checkpatch issue.

---
Changes in v3:
- Modified commit message.
- Replaced unsigned with unsigned int.

Changes in v2:
- Modified commit message.
- Changed return type of pid_before() function.

 kernel/pid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/pid.c +2 -2
index 01fb660..bb0a1c0 100644
@@ -118,7 +118,7 @@ static void free_pidmap(struct upid *upid)
 /*
  * If we started walking pids at 'base', is 'a' seen before 'b'?
  */
-static int pid_before(int base, int a, int b)
+static bool pid_before(int base, int a, int b)
 {
 	/*
 	 * This is the same as saying
@@ -126,7 +126,7 @@ static int pid_before(int base, int a, int b)
 	 * (a - base + MAXUINT) % MAXUINT < (b - base + MAXUINT) % MAXUINT
 	 * and that mapping orders 'a' and 'b' with respect to 'base'.
 	 */
-	return (unsigned)(a - base) < (unsigned)(b - base);
+	return (unsigned int)(a - base) < (unsigned int)(b - base);
 }
 
 /*
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH v3 3/3 kernel: pid: Add blank line after declarations.

In reply to a message not in the archive

Add a blank line after declarations, to fix the checkpatch issue.

---
Changes in v3:
- No changes.

Changes in v2:
- No changes.

 kernel/pid.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/pid.c +7 -0
index bb0a1c0..fe16058 100644
@@ -148,6 +148,7 @@ static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
 {
 	int prev;
 	int last_write = base;
+
 	do {
 		prev = last_write;
 		last_write = cmpxchg(&pid_ns->last_pid, prev, pid);
@@ -269,6 +270,7 @@ EXPORT_SYMBOL_GPL(put_pid);
 static void delayed_put_pid(struct rcu_head *rhp)
 {
 	struct pid *pid = container_of(rhp, struct pid, rcu);
+
 	put_pid(pid);
 }
 
@@ -409,6 +411,7 @@ EXPORT_SYMBOL_GPL(find_vpid);
 void attach_pid(struct task_struct *task, enum pid_type type)
 {
 	struct pid_link *link = &task->pids[type];
+
 	hlist_add_head_rcu(&link->node, &link->pid->tasks[type]);
 }
 
@@ -455,8 +458,10 @@ void transfer_pid(struct task_struct *old, struct task_struct *new,
 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
 {
 	struct task_struct *result = NULL;
+
 	if (pid) {
 		struct hlist_node *first;
+
 		first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
 					      lockdep_tasklist_lock_is_held());
 		if (first)
@@ -484,6 +489,7 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
 {
 	struct pid *pid;
+
 	rcu_read_lock();
 	if (type != PIDTYPE_PID)
 		task = task->group_leader;
@@ -496,6 +502,7 @@ EXPORT_SYMBOL_GPL(get_task_pid);
 struct task_struct *get_pid_task(struct pid *pid, enum pid_type type)
 {
 	struct task_struct *result;
+
 	rcu_read_lock();
 	result = pid_task(pid, type);
 	if (result)
Signature · 1 line
2.9.3