summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2018-08-22 01:01:56 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:52 -0400
commiteae04d25a713304c978d7c45dcab01b0e0811c74 (patch)
tree7b2dfd99330a00a7586a8b8368161df9457bcd96
parentdc2c8c84def6ce450c63529e08c1db100020994e (diff)
ipc: simplify ipc initialization
Now that we know that rhashtable_init() will not fail, we can get rid of a lot of the unnecessary cleanup paths when the call errored out. [manfred@colorfullife.com: variable name added to util.h to resolve checkpatch warning] Link: http://lkml.kernel.org/r/20180712185241.4017-11-manfred@colorfullife.com Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Kees Cook <keescook@chromium.org> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Michal Hocko <mhocko@suse.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--ipc/msg.c9
-rw-r--r--ipc/namespace.c20
-rw-r--r--ipc/sem.c10
-rw-r--r--ipc/shm.c9
-rw-r--r--ipc/util.c18
-rw-r--r--ipc/util.h18
6 files changed, 30 insertions, 54 deletions
diff --git a/ipc/msg.c b/ipc/msg.c
index b9b47d6cd7ee..ee78dad90460 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -1238,7 +1238,7 @@ COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
1238} 1238}
1239#endif 1239#endif
1240 1240
1241int msg_init_ns(struct ipc_namespace *ns) 1241void msg_init_ns(struct ipc_namespace *ns)
1242{ 1242{
1243 ns->msg_ctlmax = MSGMAX; 1243 ns->msg_ctlmax = MSGMAX;
1244 ns->msg_ctlmnb = MSGMNB; 1244 ns->msg_ctlmnb = MSGMNB;
@@ -1246,7 +1246,7 @@ int msg_init_ns(struct ipc_namespace *ns)
1246 1246
1247 atomic_set(&ns->msg_bytes, 0); 1247 atomic_set(&ns->msg_bytes, 0);
1248 atomic_set(&ns->msg_hdrs, 0); 1248 atomic_set(&ns->msg_hdrs, 0);
1249 return ipc_init_ids(&ns->ids[IPC_MSG_IDS]); 1249 ipc_init_ids(&ns->ids[IPC_MSG_IDS]);
1250} 1250}
1251 1251
1252#ifdef CONFIG_IPC_NS 1252#ifdef CONFIG_IPC_NS
@@ -1287,12 +1287,11 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it)
1287} 1287}
1288#endif 1288#endif
1289 1289
1290int __init msg_init(void) 1290void __init msg_init(void)
1291{ 1291{
1292 const int err = msg_init_ns(&init_ipc_ns); 1292 msg_init_ns(&init_ipc_ns);
1293 1293
1294 ipc_init_proc_interface("sysvipc/msg", 1294 ipc_init_proc_interface("sysvipc/msg",
1295 " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", 1295 " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n",
1296 IPC_MSG_IDS, sysvipc_msg_proc_show); 1296 IPC_MSG_IDS, sysvipc_msg_proc_show);
1297 return err;
1298} 1297}
diff --git a/ipc/namespace.c b/ipc/namespace.c
index f59a89966f92..21607791d62c 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -55,28 +55,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
55 ns->user_ns = get_user_ns(user_ns); 55 ns->user_ns = get_user_ns(user_ns);
56 ns->ucounts = ucounts; 56 ns->ucounts = ucounts;
57 57
58 err = sem_init_ns(ns); 58 err = mq_init_ns(ns);
59 if (err) 59 if (err)
60 goto fail_put; 60 goto fail_put;
61 err = msg_init_ns(ns);
62 if (err)
63 goto fail_destroy_sem;
64 err = shm_init_ns(ns);
65 if (err)
66 goto fail_destroy_msg;
67 61
68 err = mq_init_ns(ns); 62 sem_init_ns(ns);
69 if (err) 63 msg_init_ns(ns);
70 goto fail_destroy_shm; 64 shm_init_ns(ns);
71 65
72 return ns; 66 return ns;
73 67
74fail_destroy_shm:
75 shm_exit_ns(ns);
76fail_destroy_msg:
77 msg_exit_ns(ns);
78fail_destroy_sem:
79 sem_exit_ns(ns);
80fail_put: 68fail_put:
81 put_user_ns(ns->user_ns); 69 put_user_ns(ns->user_ns);
82 ns_free_inum(&ns->ns); 70 ns_free_inum(&ns->ns);
diff --git a/ipc/sem.c b/ipc/sem.c
index cf2ba4509f0d..e4df102f3404 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -221,14 +221,14 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
221#define sc_semopm sem_ctls[2] 221#define sc_semopm sem_ctls[2]
222#define sc_semmni sem_ctls[3] 222#define sc_semmni sem_ctls[3]
223 223
224int sem_init_ns(struct ipc_namespace *ns) 224void sem_init_ns(struct ipc_namespace *ns)
225{ 225{
226 ns->sc_semmsl = SEMMSL; 226 ns->sc_semmsl = SEMMSL;
227 ns->sc_semmns = SEMMNS; 227 ns->sc_semmns = SEMMNS;
228 ns->sc_semopm = SEMOPM; 228 ns->sc_semopm = SEMOPM;
229 ns->sc_semmni = SEMMNI; 229 ns->sc_semmni = SEMMNI;
230 ns->used_sems = 0; 230 ns->used_sems = 0;
231 return ipc_init_ids(&ns->ids[IPC_SEM_IDS]); 231 ipc_init_ids(&ns->ids[IPC_SEM_IDS]);
232} 232}
233 233
234#ifdef CONFIG_IPC_NS 234#ifdef CONFIG_IPC_NS
@@ -240,14 +240,12 @@ void sem_exit_ns(struct ipc_namespace *ns)
240} 240}
241#endif 241#endif
242 242
243int __init sem_init(void) 243void __init sem_init(void)
244{ 244{
245 const int err = sem_init_ns(&init_ipc_ns); 245 sem_init_ns(&init_ipc_ns);
246
247 ipc_init_proc_interface("sysvipc/sem", 246 ipc_init_proc_interface("sysvipc/sem",
248 " key semid perms nsems uid gid cuid cgid otime ctime\n", 247 " key semid perms nsems uid gid cuid cgid otime ctime\n",
249 IPC_SEM_IDS, sysvipc_sem_proc_show); 248 IPC_SEM_IDS, sysvipc_sem_proc_show);
250 return err;
251} 249}
252 250
253/** 251/**
diff --git a/ipc/shm.c b/ipc/shm.c
index 4c7ae625d996..c4fb359f1e53 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -96,14 +96,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
96static int sysvipc_shm_proc_show(struct seq_file *s, void *it); 96static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
97#endif 97#endif
98 98
99int shm_init_ns(struct ipc_namespace *ns) 99void shm_init_ns(struct ipc_namespace *ns)
100{ 100{
101 ns->shm_ctlmax = SHMMAX; 101 ns->shm_ctlmax = SHMMAX;
102 ns->shm_ctlall = SHMALL; 102 ns->shm_ctlall = SHMALL;
103 ns->shm_ctlmni = SHMMNI; 103 ns->shm_ctlmni = SHMMNI;
104 ns->shm_rmid_forced = 0; 104 ns->shm_rmid_forced = 0;
105 ns->shm_tot = 0; 105 ns->shm_tot = 0;
106 return ipc_init_ids(&shm_ids(ns)); 106 ipc_init_ids(&shm_ids(ns));
107} 107}
108 108
109/* 109/*
@@ -136,9 +136,8 @@ void shm_exit_ns(struct ipc_namespace *ns)
136 136
137static int __init ipc_ns_init(void) 137static int __init ipc_ns_init(void)
138{ 138{
139 const int err = shm_init_ns(&init_ipc_ns); 139 shm_init_ns(&init_ipc_ns);
140 WARN(err, "ipc: sysv shm_init_ns failed: %d\n", err); 140 return 0;
141 return err;
142} 141}
143 142
144pure_initcall(ipc_ns_init); 143pure_initcall(ipc_ns_init);
diff --git a/ipc/util.c b/ipc/util.c
index 7c1387c9510d..a2aae8c1410d 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -88,16 +88,12 @@ struct ipc_proc_iface {
88 */ 88 */
89static int __init ipc_init(void) 89static int __init ipc_init(void)
90{ 90{
91 int err_sem, err_msg;
92
93 proc_mkdir("sysvipc", NULL); 91 proc_mkdir("sysvipc", NULL);
94 err_sem = sem_init(); 92 sem_init();
95 WARN(err_sem, "ipc: sysv sem_init failed: %d\n", err_sem); 93 msg_init();
96 err_msg = msg_init();
97 WARN(err_msg, "ipc: sysv msg_init failed: %d\n", err_msg);
98 shm_init(); 94 shm_init();
99 95
100 return err_msg ? err_msg : err_sem; 96 return 0;
101} 97}
102device_initcall(ipc_init); 98device_initcall(ipc_init);
103 99
@@ -116,21 +112,17 @@ static const struct rhashtable_params ipc_kht_params = {
116 * Set up the sequence range to use for the ipc identifier range (limited 112 * Set up the sequence range to use for the ipc identifier range (limited
117 * below IPCMNI) then initialise the keys hashtable and ids idr. 113 * below IPCMNI) then initialise the keys hashtable and ids idr.
118 */ 114 */
119int ipc_init_ids(struct ipc_ids *ids) 115void ipc_init_ids(struct ipc_ids *ids)
120{ 116{
121 int err;
122 ids->in_use = 0; 117 ids->in_use = 0;
123 ids->seq = 0; 118 ids->seq = 0;
124 init_rwsem(&ids->rwsem); 119 init_rwsem(&ids->rwsem);
125 err = rhashtable_init(&ids->key_ht, &ipc_kht_params); 120 rhashtable_init(&ids->key_ht, &ipc_kht_params);
126 if (err)
127 return err;
128 idr_init(&ids->ipcs_idr); 121 idr_init(&ids->ipcs_idr);
129 ids->max_id = -1; 122 ids->max_id = -1;
130#ifdef CONFIG_CHECKPOINT_RESTORE 123#ifdef CONFIG_CHECKPOINT_RESTORE
131 ids->next_id = -1; 124 ids->next_id = -1;
132#endif 125#endif
133 return 0;
134} 126}
135 127
136#ifdef CONFIG_PROC_FS 128#ifdef CONFIG_PROC_FS
diff --git a/ipc/util.h b/ipc/util.h
index e3c47b21db93..6c5c77c61f85 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -18,8 +18,8 @@
18#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */ 18#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
19#define SEQ_MULTIPLIER (IPCMNI) 19#define SEQ_MULTIPLIER (IPCMNI)
20 20
21int sem_init(void); 21void sem_init(void);
22int msg_init(void); 22void msg_init(void);
23void shm_init(void); 23void shm_init(void);
24 24
25struct ipc_namespace; 25struct ipc_namespace;
@@ -34,17 +34,17 @@ static inline void mq_put_mnt(struct ipc_namespace *ns) { }
34#endif 34#endif
35 35
36#ifdef CONFIG_SYSVIPC 36#ifdef CONFIG_SYSVIPC
37int sem_init_ns(struct ipc_namespace *ns); 37void sem_init_ns(struct ipc_namespace *ns);
38int msg_init_ns(struct ipc_namespace *ns); 38void msg_init_ns(struct ipc_namespace *ns);
39int shm_init_ns(struct ipc_namespace *ns); 39void shm_init_ns(struct ipc_namespace *ns);
40 40
41void sem_exit_ns(struct ipc_namespace *ns); 41void sem_exit_ns(struct ipc_namespace *ns);
42void msg_exit_ns(struct ipc_namespace *ns); 42void msg_exit_ns(struct ipc_namespace *ns);
43void shm_exit_ns(struct ipc_namespace *ns); 43void shm_exit_ns(struct ipc_namespace *ns);
44#else 44#else
45static inline int sem_init_ns(struct ipc_namespace *ns) { return 0; } 45static inline void sem_init_ns(struct ipc_namespace *ns) { }
46static inline int msg_init_ns(struct ipc_namespace *ns) { return 0; } 46static inline void msg_init_ns(struct ipc_namespace *ns) { }
47static inline int shm_init_ns(struct ipc_namespace *ns) { return 0; } 47static inline void shm_init_ns(struct ipc_namespace *ns) { }
48 48
49static inline void sem_exit_ns(struct ipc_namespace *ns) { } 49static inline void sem_exit_ns(struct ipc_namespace *ns) { }
50static inline void msg_exit_ns(struct ipc_namespace *ns) { } 50static inline void msg_exit_ns(struct ipc_namespace *ns) { }
@@ -83,7 +83,7 @@ struct ipc_ops {
83struct seq_file; 83struct seq_file;
84struct ipc_ids; 84struct ipc_ids;
85 85
86int ipc_init_ids(struct ipc_ids *); 86void ipc_init_ids(struct ipc_ids *ids);
87#ifdef CONFIG_PROC_FS 87#ifdef CONFIG_PROC_FS
88void __init ipc_init_proc_interface(const char *path, const char *header, 88void __init ipc_init_proc_interface(const char *path, const char *header,
89 int ids, int (*show)(struct seq_file *, void *)); 89 int ids, int (*show)(struct seq_file *, void *));