Skip to content

Commit 68f9fb8

Browse files
author
Rafael Aquini
committed
ipc/sem: use flexible array in 'struct sem_undo'
JIRA: https://issues.redhat.com/browse/RHEL-83456 This patch is a backport of the following upstream commit: commit b46fae0 Author: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Date: Sun Jul 9 18:12:55 2023 +0200 ipc/sem: use flexible array in 'struct sem_undo' Turn 'semadj' in 'struct sem_undo' into a flexible array. The advantages are: - save the size of a pointer when the new undo structure is allocated - avoid some always ugly pointer arithmetic to get the address of semadj - avoid an indirection when the array is accessed While at it, use struct_size() to compute the size of the new undo structure. Link: https://lkml.kernel.org/r/1ba993d443ad7e16ac2b1902adab1f05ebdfa454.1688918791.git.christophe.jaillet@wanadoo.fr Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Reviewed-by: Manfred Spraul <manfred@colorfullife.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Jann Horn <jannh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Rafael Aquini <raquini@redhat.com>
1 parent dd76e4a commit 68f9fb8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

ipc/sem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct sem_undo {
152152
struct list_head list_id; /* per semaphore array list:
153153
* all undos for one array */
154154
int semid; /* semaphore set identifier */
155-
short *semadj; /* array of adjustments */
155+
short semadj[]; /* array of adjustments */
156156
/* one per semaphore */
157157
};
158158

@@ -1938,8 +1938,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
19381938
rcu_read_unlock();
19391939

19401940
/* step 2: allocate new undo structure */
1941-
new = kvzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems,
1942-
GFP_KERNEL_ACCOUNT);
1941+
new = kvzalloc(struct_size(new, semadj, nsems), GFP_KERNEL_ACCOUNT);
19431942
if (!new) {
19441943
ipc_rcu_putref(&sma->sem_perm, sem_rcu_free);
19451944
return ERR_PTR(-ENOMEM);
@@ -1967,7 +1966,6 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
19671966
goto success;
19681967
}
19691968
/* step 5: initialize & link new undo structure */
1970-
new->semadj = (short *) &new[1];
19711969
new->ulp = ulp;
19721970
new->semid = semid;
19731971
assert_spin_locked(&ulp->lock);

0 commit comments

Comments
 (0)