Commit eae04d25 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

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.comSigned-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: default avatarManfred 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dc2c8c84
...@@ -1238,7 +1238,7 @@ COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp, ...@@ -1238,7 +1238,7 @@ COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
} }
#endif #endif
int msg_init_ns(struct ipc_namespace *ns) void msg_init_ns(struct ipc_namespace *ns)
{ {
ns->msg_ctlmax = MSGMAX; ns->msg_ctlmax = MSGMAX;
ns->msg_ctlmnb = MSGMNB; ns->msg_ctlmnb = MSGMNB;
...@@ -1246,7 +1246,7 @@ int msg_init_ns(struct ipc_namespace *ns) ...@@ -1246,7 +1246,7 @@ int msg_init_ns(struct ipc_namespace *ns)
atomic_set(&ns->msg_bytes, 0); atomic_set(&ns->msg_bytes, 0);
atomic_set(&ns->msg_hdrs, 0); atomic_set(&ns->msg_hdrs, 0);
return ipc_init_ids(&ns->ids[IPC_MSG_IDS]); ipc_init_ids(&ns->ids[IPC_MSG_IDS]);
} }
#ifdef CONFIG_IPC_NS #ifdef CONFIG_IPC_NS
...@@ -1287,12 +1287,11 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it) ...@@ -1287,12 +1287,11 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it)
} }
#endif #endif
int __init msg_init(void) void __init msg_init(void)
{ {
const int err = msg_init_ns(&init_ipc_ns); msg_init_ns(&init_ipc_ns);
ipc_init_proc_interface("sysvipc/msg", ipc_init_proc_interface("sysvipc/msg",
" key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n",
IPC_MSG_IDS, sysvipc_msg_proc_show); IPC_MSG_IDS, sysvipc_msg_proc_show);
return err;
} }
...@@ -55,28 +55,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, ...@@ -55,28 +55,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
ns->user_ns = get_user_ns(user_ns); ns->user_ns = get_user_ns(user_ns);
ns->ucounts = ucounts; ns->ucounts = ucounts;
err = sem_init_ns(ns); err = mq_init_ns(ns);
if (err) if (err)
goto fail_put; goto fail_put;
err = msg_init_ns(ns);
if (err)
goto fail_destroy_sem;
err = shm_init_ns(ns);
if (err)
goto fail_destroy_msg;
err = mq_init_ns(ns); sem_init_ns(ns);
if (err) msg_init_ns(ns);
goto fail_destroy_shm; shm_init_ns(ns);
return ns; return ns;
fail_destroy_shm:
shm_exit_ns(ns);
fail_destroy_msg:
msg_exit_ns(ns);
fail_destroy_sem:
sem_exit_ns(ns);
fail_put: fail_put:
put_user_ns(ns->user_ns); put_user_ns(ns->user_ns);
ns_free_inum(&ns->ns); ns_free_inum(&ns->ns);
......
...@@ -221,14 +221,14 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it); ...@@ -221,14 +221,14 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
#define sc_semopm sem_ctls[2] #define sc_semopm sem_ctls[2]
#define sc_semmni sem_ctls[3] #define sc_semmni sem_ctls[3]
int sem_init_ns(struct ipc_namespace *ns) void sem_init_ns(struct ipc_namespace *ns)
{ {
ns->sc_semmsl = SEMMSL; ns->sc_semmsl = SEMMSL;
ns->sc_semmns = SEMMNS; ns->sc_semmns = SEMMNS;
ns->sc_semopm = SEMOPM; ns->sc_semopm = SEMOPM;
ns->sc_semmni = SEMMNI; ns->sc_semmni = SEMMNI;
ns->used_sems = 0; ns->used_sems = 0;
return ipc_init_ids(&ns->ids[IPC_SEM_IDS]); ipc_init_ids(&ns->ids[IPC_SEM_IDS]);
} }
#ifdef CONFIG_IPC_NS #ifdef CONFIG_IPC_NS
...@@ -240,14 +240,12 @@ void sem_exit_ns(struct ipc_namespace *ns) ...@@ -240,14 +240,12 @@ void sem_exit_ns(struct ipc_namespace *ns)
} }
#endif #endif
int __init sem_init(void) void __init sem_init(void)
{ {
const int err = sem_init_ns(&init_ipc_ns); sem_init_ns(&init_ipc_ns);
ipc_init_proc_interface("sysvipc/sem", ipc_init_proc_interface("sysvipc/sem",
" key semid perms nsems uid gid cuid cgid otime ctime\n", " key semid perms nsems uid gid cuid cgid otime ctime\n",
IPC_SEM_IDS, sysvipc_sem_proc_show); IPC_SEM_IDS, sysvipc_sem_proc_show);
return err;
} }
/** /**
......
...@@ -96,14 +96,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp); ...@@ -96,14 +96,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
static int sysvipc_shm_proc_show(struct seq_file *s, void *it); static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif #endif
int shm_init_ns(struct ipc_namespace *ns) void shm_init_ns(struct ipc_namespace *ns)
{ {
ns->shm_ctlmax = SHMMAX; ns->shm_ctlmax = SHMMAX;
ns->shm_ctlall = SHMALL; ns->shm_ctlall = SHMALL;
ns->shm_ctlmni = SHMMNI; ns->shm_ctlmni = SHMMNI;
ns->shm_rmid_forced = 0; ns->shm_rmid_forced = 0;
ns->shm_tot = 0; ns->shm_tot = 0;
return ipc_init_ids(&shm_ids(ns)); ipc_init_ids(&shm_ids(ns));
} }
/* /*
...@@ -136,9 +136,8 @@ void shm_exit_ns(struct ipc_namespace *ns) ...@@ -136,9 +136,8 @@ void shm_exit_ns(struct ipc_namespace *ns)
static int __init ipc_ns_init(void) static int __init ipc_ns_init(void)
{ {
const int err = shm_init_ns(&init_ipc_ns); shm_init_ns(&init_ipc_ns);
WARN(err, "ipc: sysv shm_init_ns failed: %d\n", err); return 0;
return err;
} }
pure_initcall(ipc_ns_init); pure_initcall(ipc_ns_init);
......
...@@ -88,16 +88,12 @@ struct ipc_proc_iface { ...@@ -88,16 +88,12 @@ struct ipc_proc_iface {
*/ */
static int __init ipc_init(void) static int __init ipc_init(void)
{ {
int err_sem, err_msg;
proc_mkdir("sysvipc", NULL); proc_mkdir("sysvipc", NULL);
err_sem = sem_init(); sem_init();
WARN(err_sem, "ipc: sysv sem_init failed: %d\n", err_sem); msg_init();
err_msg = msg_init();
WARN(err_msg, "ipc: sysv msg_init failed: %d\n", err_msg);
shm_init(); shm_init();
return err_msg ? err_msg : err_sem; return 0;
} }
device_initcall(ipc_init); device_initcall(ipc_init);
...@@ -116,21 +112,17 @@ static const struct rhashtable_params ipc_kht_params = { ...@@ -116,21 +112,17 @@ static const struct rhashtable_params ipc_kht_params = {
* Set up the sequence range to use for the ipc identifier range (limited * Set up the sequence range to use for the ipc identifier range (limited
* below IPCMNI) then initialise the keys hashtable and ids idr. * below IPCMNI) then initialise the keys hashtable and ids idr.
*/ */
int ipc_init_ids(struct ipc_ids *ids) void ipc_init_ids(struct ipc_ids *ids)
{ {
int err;
ids->in_use = 0; ids->in_use = 0;
ids->seq = 0; ids->seq = 0;
init_rwsem(&ids->rwsem); init_rwsem(&ids->rwsem);
err = rhashtable_init(&ids->key_ht, &ipc_kht_params); rhashtable_init(&ids->key_ht, &ipc_kht_params);
if (err)
return err;
idr_init(&ids->ipcs_idr); idr_init(&ids->ipcs_idr);
ids->max_id = -1; ids->max_id = -1;
#ifdef CONFIG_CHECKPOINT_RESTORE #ifdef CONFIG_CHECKPOINT_RESTORE
ids->next_id = -1; ids->next_id = -1;
#endif #endif
return 0;
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */ #define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
#define SEQ_MULTIPLIER (IPCMNI) #define SEQ_MULTIPLIER (IPCMNI)
int sem_init(void); void sem_init(void);
int msg_init(void); void msg_init(void);
void shm_init(void); void shm_init(void);
struct ipc_namespace; struct ipc_namespace;
...@@ -34,17 +34,17 @@ static inline void mq_put_mnt(struct ipc_namespace *ns) { } ...@@ -34,17 +34,17 @@ static inline void mq_put_mnt(struct ipc_namespace *ns) { }
#endif #endif
#ifdef CONFIG_SYSVIPC #ifdef CONFIG_SYSVIPC
int sem_init_ns(struct ipc_namespace *ns); void sem_init_ns(struct ipc_namespace *ns);
int msg_init_ns(struct ipc_namespace *ns); void msg_init_ns(struct ipc_namespace *ns);
int shm_init_ns(struct ipc_namespace *ns); void shm_init_ns(struct ipc_namespace *ns);
void sem_exit_ns(struct ipc_namespace *ns); void sem_exit_ns(struct ipc_namespace *ns);
void msg_exit_ns(struct ipc_namespace *ns); void msg_exit_ns(struct ipc_namespace *ns);
void shm_exit_ns(struct ipc_namespace *ns); void shm_exit_ns(struct ipc_namespace *ns);
#else #else
static inline int sem_init_ns(struct ipc_namespace *ns) { return 0; } static inline void sem_init_ns(struct ipc_namespace *ns) { }
static inline int msg_init_ns(struct ipc_namespace *ns) { return 0; } static inline void msg_init_ns(struct ipc_namespace *ns) { }
static inline int shm_init_ns(struct ipc_namespace *ns) { return 0; } static inline void shm_init_ns(struct ipc_namespace *ns) { }
static inline void sem_exit_ns(struct ipc_namespace *ns) { } static inline void sem_exit_ns(struct ipc_namespace *ns) { }
static inline void msg_exit_ns(struct ipc_namespace *ns) { } static inline void msg_exit_ns(struct ipc_namespace *ns) { }
...@@ -83,7 +83,7 @@ struct ipc_ops { ...@@ -83,7 +83,7 @@ struct ipc_ops {
struct seq_file; struct seq_file;
struct ipc_ids; struct ipc_ids;
int ipc_init_ids(struct ipc_ids *); void ipc_init_ids(struct ipc_ids *ids);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
void __init ipc_init_proc_interface(const char *path, const char *header, void __init ipc_init_proc_interface(const char *path, const char *header,
int ids, int (*show)(struct seq_file *, void *)); int ids, int (*show)(struct seq_file *, void *));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment