Skip to content

Commit

Permalink
ipc: drop non-RCU allocation
Browse files Browse the repository at this point in the history
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.

[[email protected]: Rediff due to inclusion of memset() into ipc_rcu_alloc()]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Manfred Spraul <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Jul 12, 2017
1 parent 2cd648c commit f8dbe8d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
8 changes: 5 additions & 3 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
}
sem_unlock(sma, -1);
rcu_read_unlock();
sem_io = ipc_alloc(sizeof(ushort)*nsems);
sem_io = kvmalloc_array(nsems, sizeof(ushort),
GFP_KERNEL);
if (sem_io == NULL) {
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
return -ENOMEM;
Expand Down Expand Up @@ -1402,7 +1403,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
rcu_read_unlock();

if (nsems > SEMMSL_FAST) {
sem_io = ipc_alloc(sizeof(ushort)*nsems);
sem_io = kvmalloc_array(nsems, sizeof(ushort),
GFP_KERNEL);
if (sem_io == NULL) {
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
return -ENOMEM;
Expand Down Expand Up @@ -1480,7 +1482,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
wake_up_q(&wake_q);
out_free:
if (sem_io != fast_sem_io)
ipc_free(sem_io);
kvfree(sem_io);
return err;
}

Expand Down
25 changes: 1 addition & 24 deletions ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,29 +394,6 @@ void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
ipcp->deleted = true;
}

/**
* ipc_alloc - allocate ipc space
* @size: size desired
*
* Allocate memory from the appropriate pools and return a pointer to it.
* NULL is returned if the allocation fails
*/
void *ipc_alloc(int size)
{
return kvmalloc(size, GFP_KERNEL);
}

/**
* ipc_free - free ipc space
* @ptr: pointer returned by ipc_alloc
*
* Free a block created with ipc_alloc().
*/
void ipc_free(void *ptr)
{
kvfree(ptr);
}

/**
* ipc_rcu_alloc - allocate ipc space
* @size: size desired
Expand All @@ -429,7 +406,7 @@ struct kern_ipc_perm *ipc_rcu_alloc(int size)
/*
* We prepend the allocation with the rcu struct
*/
struct kern_ipc_perm *out = ipc_alloc(size);
struct kern_ipc_perm *out = kvmalloc(size, GFP_KERNEL);
if (unlikely(!out))
return NULL;

Expand Down
6 changes: 0 additions & 6 deletions ipc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *);
/* must be called with ipcp locked */
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg);

/* for rare, potentially huge allocations.
* both function can sleep
*/
void *ipc_alloc(int size);
void ipc_free(void *ptr);

/*
* For allocation that need to be freed by RCU.
* Objects are reference counted, they start with reference count 1.
Expand Down

0 comments on commit f8dbe8d

Please sign in to comment.