Skip to contentSkip to conversation

proc: constify status array

PATCH In review Mike Frysinger 2 participants 3 messages Mar 30, 2011 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: constify status array

No need for this local array to be writable, so mark it const.

---
 fs/proc/array.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/proc/array.c +2 -2
index 5e4f776..9b45ee8 100644
@@ -131,7 +131,7 @@ static inline void task_name(struct seq_file *m, struct task_struct *p)
  * you can test for combinations of others with
  * simple bit tests.
  */
-static const char *task_state_array[] = {
+static const char * const task_state_array[] = {
 	"R (running)",		/*   0 */
 	"S (sleeping)",		/*   1 */
 	"D (disk sleep)",	/*   2 */
@@ -147,7 +147,7 @@ static const char *task_state_array[] = {
 static inline const char *get_task_state(struct task_struct *tsk)
 {
 	unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state;
-	const char **p = &task_state_array[0];
+	const char * const *p = &task_state_array[0];
 
 	BUILD_BUG_ON(1 + ilog2(TASK_STATE_MAX) != ARRAY_SIZE(task_state_array));
 
Signature · 1 line
1.7.4.1
#1 lore raw

fs/proc/array.c static inline void task_name(struct seq_file *m, struct task_struct *p) · line 134

Quoted 2 lines · Mike Frysinger
fs/proc/array.c +1 -1
-static const char *task_state_array[] = {
+static const char * const task_state_array[] = {

Why this is needed for task_state_array, but not for, say, tgid_base_stuff?

00000000000000e0 d task_state_array
0000000000000a50 r tgid_base_stuff

This double const is ugly.

#2 lore raw
Quoted 5 lines · Alexey Dobriyan

fs/proc/array.c static inline void task_name(struct seq_file *m, struct task_struct *p) · line 134

Quoted 2 lines · Mike Frysinger
fs/proc/array.c +1 -1
-static const char *task_state_array[] = {
+static const char * const task_state_array[] = {

Why this is needed for task_state_array, but not for, say, tgid_base_stuff?

tgid_base_stuff is already declared const. which your nm output clearly shows.

Quoted 1 line

This double const is ugly.

quite the opposite. not declaring const arrays const is ugly. -mike