Skip to content

Commit f8dbe8d

Browse files
keestorvalds
authored andcommitted
ipc: drop non-RCU allocation
The only users of ipc_alloc() were ipc_rcu_alloc() and the on-heap sem_io fall-back memory. Better to just open-code these to make things easier to read. [manfred@colorfullife.com: Rediff due to inclusion of memset() into ipc_rcu_alloc()] Link: http://lkml.kernel.org/r/20170525185107.12869-5-manfred@colorfullife.com Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2cd648c commit f8dbe8d

3 files changed

Lines changed: 6 additions & 33 deletions

File tree

‎ipc/sem.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
13681368
}
13691369
sem_unlock(sma, -1);
13701370
rcu_read_unlock();
1371-
sem_io = ipc_alloc(sizeof(ushort)*nsems);
1371+
sem_io = kvmalloc_array(nsems, sizeof(ushort),
1372+
GFP_KERNEL);
13721373
if (sem_io == NULL) {
13731374
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
13741375
return -ENOMEM;
@@ -1402,7 +1403,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
14021403
rcu_read_unlock();
14031404

14041405
if (nsems > SEMMSL_FAST) {
1405-
sem_io = ipc_alloc(sizeof(ushort)*nsems);
1406+
sem_io = kvmalloc_array(nsems, sizeof(ushort),
1407+
GFP_KERNEL);
14061408
if (sem_io == NULL) {
14071409
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
14081410
return -ENOMEM;
@@ -1480,7 +1482,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
14801482
wake_up_q(&wake_q);
14811483
out_free:
14821484
if (sem_io != fast_sem_io)
1483-
ipc_free(sem_io);
1485+
kvfree(sem_io);
14841486
return err;
14851487
}
14861488

‎ipc/util.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,6 @@ void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
394394
ipcp->deleted = true;
395395
}
396396

397-
/**
398-
* ipc_alloc - allocate ipc space
399-
* @size: size desired
400-
*
401-
* Allocate memory from the appropriate pools and return a pointer to it.
402-
* NULL is returned if the allocation fails
403-
*/
404-
void *ipc_alloc(int size)
405-
{
406-
return kvmalloc(size, GFP_KERNEL);
407-
}
408-
409-
/**
410-
* ipc_free - free ipc space
411-
* @ptr: pointer returned by ipc_alloc
412-
*
413-
* Free a block created with ipc_alloc().
414-
*/
415-
void ipc_free(void *ptr)
416-
{
417-
kvfree(ptr);
418-
}
419-
420397
/**
421398
* ipc_rcu_alloc - allocate ipc space
422399
* @size: size desired
@@ -429,7 +406,7 @@ struct kern_ipc_perm *ipc_rcu_alloc(int size)
429406
/*
430407
* We prepend the allocation with the rcu struct
431408
*/
432-
struct kern_ipc_perm *out = ipc_alloc(size);
409+
struct kern_ipc_perm *out = kvmalloc(size, GFP_KERNEL);
433410
if (unlikely(!out))
434411
return NULL;
435412

‎ipc/util.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *);
107107
/* must be called with ipcp locked */
108108
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);
109109

110-
/* for rare, potentially huge allocations.
111-
* both function can sleep
112-
*/
113-
void *ipc_alloc(int size);
114-
void ipc_free(void *ptr);
115-
116110
/*
117111
* For allocation that need to be freed by RCU.
118112
* Objects are reference counted, they start with reference count 1.

0 commit comments

Comments
 (0)