From patchwork Sun Jul 9 16:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 117521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4546076vqx; Sun, 9 Jul 2023 10:15:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFi3s288ZK4F0ot4YRPFgTitb9WqVzD+YhR8WCbj607hPchvgP6TNm7aWeolT9XnLcbeMT3 X-Received: by 2002:a17:902:b110:b0:1b8:9cf2:35b0 with SMTP id q16-20020a170902b11000b001b89cf235b0mr7375835plr.41.1688922957234; Sun, 09 Jul 2023 10:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688922957; cv=none; d=google.com; s=arc-20160816; b=KY4gO3FSxK+SWTTfUtE22HuHr3zFNa7Eu0J6RpEO9PrbkZCFXc62gLeCRaCYoZ0M/K XpILgszp8cK0XeHVoWXEL8PkIUAsxTBHJcewa6fEqc1l/PO3xfoFgnfO5d/iejfbwwAG eWs4z0qEQWd48XIhiVEaJ8Tg7eZSfeFJQjXTD4wul7vKGMMd1u/ntEwKZAo7x15rreCb mbDUC2eWlUONBKrK0K6Kd393msh8Jx4+J+rYX/VESKSAujEWZK5nlChOpJKgMijtqyFr DKk0yvFxojpcZx5R8JKAOOtYsyUmPy7UE6qBgddqdQn+u0T0YBIlL4sJXBHEg8PnfGP8 Gz9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=y5RKgMsLoXKY+PpcxUdYWHasiu7hlqbJ+TzTtF5rZRs=; fh=CGAU0kRc6gJxbKt8GSflDO5pF5WF3t6VmL9ruHqcAwI=; b=DHBTJCRWzN3cv12pGr0QzFOsSFq8W8sp3k2ENBdxw8AQE3wqv3/NOlYnTaUkq52WBd hw29R/0E7+Tj8ZeEAmDmRiYbBp8/fFO791ETKKteaufiKnsBtelx09UJQgA1Cqh2g9c7 1CFwZUqbslIpmtOgml/haW/dEeyR5Sd9rcKtZ03M11NKRNbfKm4jC8rUwexPg8qXv2vY /XN7p6YuoyRaei9nOJUlOsB9WL97Fq9rgv7T0EX9Hs4BJhZ5GpO9sJp2gjywLUWuHZLl xFFUr0wZ3t5jI4KbfYhsedJkiXf4myTEUjExX5UaQ9Qy0ZmY7Q7LlZcToLxX+sK7sbHJ 3/UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=VzfbNDtI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170902d2cd00b001b7fd6f95f6si2019295plc.515.2023.07.09.10.15.44; Sun, 09 Jul 2023 10:15:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=VzfbNDtI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbjGIQNM (ORCPT + 99 others); Sun, 9 Jul 2023 12:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbjGIQNK (ORCPT ); Sun, 9 Jul 2023 12:13:10 -0400 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2424AFE for ; Sun, 9 Jul 2023 09:13:03 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id IX1vq6cfwbalEIX1vq7Ijw; Sun, 09 Jul 2023 18:13:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1688919180; bh=y5RKgMsLoXKY+PpcxUdYWHasiu7hlqbJ+TzTtF5rZRs=; h=From:To:Cc:Subject:Date; b=VzfbNDtIbKrHXxPHzeNNL/V2v4EWlxaMQNd4uh47kMpWMegEWUK+Cgt138sn708ic 6PEeCySdmUNW1HTuwVC/yWKPPb8Vd5dnQOhvhohjPNK2Vd26GvMrVtjOgFpqYkts5K Oa0WiIvB8KBBK5rAYxaHqGUqCIVnaQ2E6dUdx9EVbEoBD9utkjTl5A+NQiYxEPqLqy t/4URf0KqwxtjgzAbqzbTz8UKZ8q+zq9t7vzsuLGCT7UXkJy8+zekZIKrcET2yGLp3 NZQ/awKDEmeNyrlZ7BNBxRMTTP0ZUXr1HcCAPU4MMK2BQ53AYTTKO4Mp4VwuB7ILyI U7c4b34mxNw+w== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 09 Jul 2023 18:13:00 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: jannh@google.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] ipc/sem: Use flexible array in 'struct sem_undo' Date: Sun, 9 Jul 2023 18:12:55 +0200 Message-Id: <1ba993d443ad7e16ac2b1902adab1f05ebdfa454.1688918791.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FORGED_SPF_HELO,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1770964078587774321 X-GMAIL-MSGID: 1770964078587774321 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. Signed-off-by: Christophe JAILLET --- Not sure who to put in copy, get_maintainer.pl is of litle help. --- ipc/sem.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ipc/sem.c b/ipc/sem.c index 00f88aa01ac5..a39cdc7bf88f 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -152,7 +152,7 @@ struct sem_undo { struct list_head list_id; /* per semaphore array list: * all undos for one array */ int semid; /* semaphore set identifier */ - short *semadj; /* array of adjustments */ + short semadj[]; /* array of adjustments */ /* one per semaphore */ }; @@ -1938,8 +1938,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid) rcu_read_unlock(); /* step 2: allocate new undo structure */ - new = kvzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, - GFP_KERNEL_ACCOUNT); + new = kvzalloc(struct_size(new, semadj, nsems), GFP_KERNEL_ACCOUNT); if (!new) { ipc_rcu_putref(&sma->sem_perm, sem_rcu_free); return ERR_PTR(-ENOMEM); @@ -1967,7 +1966,6 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid) goto success; } /* step 5: initialize & link new undo structure */ - new->semadj = (short *) &new[1]; new->ulp = ulp; new->semid = semid; assert_spin_locked(&ulp->lock);