aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManfred Spraul <manfred@colorfullife.com>2018-08-22 01:02:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:52 -0400
commit27c331a174614208d0b539019583990967ad9479 (patch)
treec4ddfa96ed2a654783ed485c86afdb4c83a91e17
parenteae04d25a713304c978d7c45dcab01b0e0811c74 (diff)
ipc/util.c: further variable name cleanups
The varable names got a mess, thus standardize them again: id: user space id. Called semid, shmid, msgid if the type is known. Most functions use "id" already. idx: "index" for the idr lookup Right now, some functions use lid, ipc_addid() already uses idx as the variable name. seq: sequence number, to avoid quick collisions of the user space id key: user space key, used for the rhash tree Link: http://lkml.kernel.org/r/20180712185241.4017-12-manfred@colorfullife.com Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Davidlohr Bueso <dbueso@suse.de> 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--include/linux/ipc_namespace.h2
-rw-r--r--ipc/msg.c6
-rw-r--r--ipc/sem.c6
-rw-r--r--ipc/shm.c4
-rw-r--r--ipc/util.c26
-rw-r--r--ipc/util.h10
6 files changed, 27 insertions, 27 deletions
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index e9ccdfdb1928..6ab8c1bada3f 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -18,7 +18,7 @@ struct ipc_ids {
18 unsigned short seq; 18 unsigned short seq;
19 struct rw_semaphore rwsem; 19 struct rw_semaphore rwsem;
20 struct idr ipcs_idr; 20 struct idr ipcs_idr;
21 int max_id; 21 int max_idx;
22#ifdef CONFIG_CHECKPOINT_RESTORE 22#ifdef CONFIG_CHECKPOINT_RESTORE
23 int next_id; 23 int next_id;
24#endif 24#endif
diff --git a/ipc/msg.c b/ipc/msg.c
index ee78dad90460..883642cf2b27 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -456,7 +456,7 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid,
456 int cmd, struct msginfo *msginfo) 456 int cmd, struct msginfo *msginfo)
457{ 457{
458 int err; 458 int err;
459 int max_id; 459 int max_idx;
460 460
461 /* 461 /*
462 * We must not return kernel stack data. 462 * We must not return kernel stack data.
@@ -483,9 +483,9 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid,
483 msginfo->msgpool = MSGPOOL; 483 msginfo->msgpool = MSGPOOL;
484 msginfo->msgtql = MSGTQL; 484 msginfo->msgtql = MSGTQL;
485 } 485 }
486 max_id = ipc_get_maxid(&msg_ids(ns)); 486 max_idx = ipc_get_maxidx(&msg_ids(ns));
487 up_read(&msg_ids(ns).rwsem); 487 up_read(&msg_ids(ns).rwsem);
488 return (max_id < 0) ? 0 : max_id; 488 return (max_idx < 0) ? 0 : max_idx;
489} 489}
490 490
491static int msgctl_stat(struct ipc_namespace *ns, int msqid, 491static int msgctl_stat(struct ipc_namespace *ns, int msqid,
diff --git a/ipc/sem.c b/ipc/sem.c
index e4df102f3404..26f8e37fcdcb 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1294,7 +1294,7 @@ static int semctl_info(struct ipc_namespace *ns, int semid,
1294 int cmd, void __user *p) 1294 int cmd, void __user *p)
1295{ 1295{
1296 struct seminfo seminfo; 1296 struct seminfo seminfo;
1297 int max_id; 1297 int max_idx;
1298 int err; 1298 int err;
1299 1299
1300 err = security_sem_semctl(NULL, cmd); 1300 err = security_sem_semctl(NULL, cmd);
@@ -1318,11 +1318,11 @@ static int semctl_info(struct ipc_namespace *ns, int semid,
1318 seminfo.semusz = SEMUSZ; 1318 seminfo.semusz = SEMUSZ;
1319 seminfo.semaem = SEMAEM; 1319 seminfo.semaem = SEMAEM;
1320 } 1320 }
1321 max_id = ipc_get_maxid(&sem_ids(ns)); 1321 max_idx = ipc_get_maxidx(&sem_ids(ns));
1322 up_read(&sem_ids(ns).rwsem); 1322 up_read(&sem_ids(ns).rwsem);
1323 if (copy_to_user(p, &seminfo, sizeof(struct seminfo))) 1323 if (copy_to_user(p, &seminfo, sizeof(struct seminfo)))
1324 return -EFAULT; 1324 return -EFAULT;
1325 return (max_id < 0) ? 0 : max_id; 1325 return (max_idx < 0) ? 0 : max_idx;
1326} 1326}
1327 1327
1328static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum, 1328static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum,
diff --git a/ipc/shm.c b/ipc/shm.c
index c4fb359f1e53..b0eb3757ab89 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -948,7 +948,7 @@ static int shmctl_ipc_info(struct ipc_namespace *ns,
948 shminfo->shmall = ns->shm_ctlall; 948 shminfo->shmall = ns->shm_ctlall;
949 shminfo->shmmin = SHMMIN; 949 shminfo->shmmin = SHMMIN;
950 down_read(&shm_ids(ns).rwsem); 950 down_read(&shm_ids(ns).rwsem);
951 err = ipc_get_maxid(&shm_ids(ns)); 951 err = ipc_get_maxidx(&shm_ids(ns));
952 up_read(&shm_ids(ns).rwsem); 952 up_read(&shm_ids(ns).rwsem);
953 if (err < 0) 953 if (err < 0)
954 err = 0; 954 err = 0;
@@ -968,7 +968,7 @@ static int shmctl_shm_info(struct ipc_namespace *ns,
968 shm_info->shm_tot = ns->shm_tot; 968 shm_info->shm_tot = ns->shm_tot;
969 shm_info->swap_attempts = 0; 969 shm_info->swap_attempts = 0;
970 shm_info->swap_successes = 0; 970 shm_info->swap_successes = 0;
971 err = ipc_get_maxid(&shm_ids(ns)); 971 err = ipc_get_maxidx(&shm_ids(ns));
972 up_read(&shm_ids(ns).rwsem); 972 up_read(&shm_ids(ns).rwsem);
973 if (err < 0) 973 if (err < 0)
974 err = 0; 974 err = 0;
diff --git a/ipc/util.c b/ipc/util.c
index a2aae8c1410d..6f30ba80ca15 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -119,7 +119,7 @@ void ipc_init_ids(struct ipc_ids *ids)
119 init_rwsem(&ids->rwsem); 119 init_rwsem(&ids->rwsem);
120 rhashtable_init(&ids->key_ht, &ipc_kht_params); 120 rhashtable_init(&ids->key_ht, &ipc_kht_params);
121 idr_init(&ids->ipcs_idr); 121 idr_init(&ids->ipcs_idr);
122 ids->max_id = -1; 122 ids->max_idx = -1;
123#ifdef CONFIG_CHECKPOINT_RESTORE 123#ifdef CONFIG_CHECKPOINT_RESTORE
124 ids->next_id = -1; 124 ids->next_id = -1;
125#endif 125#endif
@@ -237,7 +237,7 @@ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new)
237 * @limit: limit for the number of used ids 237 * @limit: limit for the number of used ids
238 * 238 *
239 * Add an entry 'new' to the ipc ids idr. The permissions object is 239 * Add an entry 'new' to the ipc ids idr. The permissions object is
240 * initialised and the first free entry is set up and the id assigned 240 * initialised and the first free entry is set up and the index assigned
241 * is returned. The 'new' entry is returned in a locked state on success. 241 * is returned. The 'new' entry is returned in a locked state on success.
242 * 242 *
243 * On failure the entry is not locked and a negative err-code is returned. 243 * On failure the entry is not locked and a negative err-code is returned.
@@ -291,8 +291,8 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit)
291 } 291 }
292 292
293 ids->in_use++; 293 ids->in_use++;
294 if (idx > ids->max_id) 294 if (idx > ids->max_idx)
295 ids->max_id = idx; 295 ids->max_idx = idx;
296 return idx; 296 return idx;
297} 297}
298 298
@@ -431,20 +431,20 @@ static void ipc_kht_remove(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
431 */ 431 */
432void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp) 432void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
433{ 433{
434 int lid = ipcid_to_idx(ipcp->id); 434 int idx = ipcid_to_idx(ipcp->id);
435 435
436 idr_remove(&ids->ipcs_idr, lid); 436 idr_remove(&ids->ipcs_idr, idx);
437 ipc_kht_remove(ids, ipcp); 437 ipc_kht_remove(ids, ipcp);
438 ids->in_use--; 438 ids->in_use--;
439 ipcp->deleted = true; 439 ipcp->deleted = true;
440 440
441 if (unlikely(lid == ids->max_id)) { 441 if (unlikely(idx == ids->max_idx)) {
442 do { 442 do {
443 lid--; 443 idx--;
444 if (lid == -1) 444 if (idx == -1)
445 break; 445 break;
446 } while (!idr_find(&ids->ipcs_idr, lid)); 446 } while (!idr_find(&ids->ipcs_idr, idx));
447 ids->max_id = lid; 447 ids->max_idx = idx;
448 } 448 }
449} 449}
450 450
@@ -564,9 +564,9 @@ void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out)
564struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id) 564struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id)
565{ 565{
566 struct kern_ipc_perm *out; 566 struct kern_ipc_perm *out;
567 int lid = ipcid_to_idx(id); 567 int idx = ipcid_to_idx(id);
568 568
569 out = idr_find(&ids->ipcs_idr, lid); 569 out = idr_find(&ids->ipcs_idr, idx);
570 if (!out) 570 if (!out)
571 return ERR_PTR(-EINVAL); 571 return ERR_PTR(-EINVAL);
572 572
diff --git a/ipc/util.h b/ipc/util.h
index 6c5c77c61f85..e74564fe3375 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -113,12 +113,12 @@ void ipc_set_key_private(struct ipc_ids *, struct kern_ipc_perm *);
113int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg); 113int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);
114 114
115/** 115/**
116 * ipc_get_maxid - get the last assigned id 116 * ipc_get_maxidx - get the highest assigned index
117 * @ids: ipc identifier set 117 * @ids: ipc identifier set
118 * 118 *
119 * Called with ipc_ids.rwsem held for reading. 119 * Called with ipc_ids.rwsem held for reading.
120 */ 120 */
121static inline int ipc_get_maxid(struct ipc_ids *ids) 121static inline int ipc_get_maxidx(struct ipc_ids *ids)
122{ 122{
123 if (ids->in_use == 0) 123 if (ids->in_use == 0)
124 return -1; 124 return -1;
@@ -126,7 +126,7 @@ static inline int ipc_get_maxid(struct ipc_ids *ids)
126 if (ids->in_use == IPCMNI) 126 if (ids->in_use == IPCMNI)
127 return IPCMNI - 1; 127 return IPCMNI - 1;
128 128
129 return ids->max_id; 129 return ids->max_idx;
130} 130}
131 131
132/* 132/*
@@ -172,9 +172,9 @@ extern struct msg_msg *load_msg(const void __user *src, size_t len);
172extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst); 172extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst);
173extern int store_msg(void __user *dest, struct msg_msg *msg, size_t len); 173extern int store_msg(void __user *dest, struct msg_msg *msg, size_t len);
174 174
175static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int uid) 175static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int id)
176{ 176{
177 return uid / SEQ_MULTIPLIER != ipcp->seq; 177 return ipcid_to_seqx(id) != ipcp->seq;
178} 178}
179 179
180static inline void ipc_lock_object(struct kern_ipc_perm *perm) 180static inline void ipc_lock_object(struct kern_ipc_perm *perm)