From patchwork Sun Jul 16 18:48:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 120923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp746109vqt; Sun, 16 Jul 2023 12:24:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlE5Kw8ANCQxKroWbtB5i8q1yLFvBbLyIZlFWxN81+DmwO+h//KbW9yU469t7njgoeNMhAQO X-Received: by 2002:aa7:c9ca:0:b0:51d:9477:7826 with SMTP id i10-20020aa7c9ca000000b0051d94777826mr9435151edt.0.1689535453230; Sun, 16 Jul 2023 12:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689535453; cv=none; d=google.com; s=arc-20160816; b=U8leuFw/fGtcMEKvmmz45YVbY6eTI199j1LP+cK517wBsSH5NUgdLPmM7Nu6xWYkkl mSa7wsIm04MxJN12Az1pYZq7kP1cUGD1HYsTuQtMZtrx1XrQJvYs/eyQ9iwqfIUeD4wD 9bpIhw2Ddz6R1/0jccbX5LtfTDeCPPSZN09dy4pxGsN4ZMtEqclnWJEe0CFy+akA2Bgf R85yBqZ7RNauro7o/DHfwoQaHQ1pY5byfr69Qc18oL/kb+X2KgspTePKqDVp5j62wHAD dSrS7aQ4lKke1QsyCk2zFD3FyiUSBBOB/L2dgFTPgZh4w4i98KVNxvcAbGPXALpMwmP2 svlA== 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=dRGXf+8+arzdqmH6oSLRzr2Fhx/BMcRgYEg7UM8rSZs=; fh=qEXDlo8x/tE9rmACbw/QFrVSYOuPq28HBMDbO0vMJv0=; b=SruzjhOaqirRa3n2hNyy6nnkBJR3zhqh/WtqrtdFv0cPpVL2+uVkuqAisRvIYC5+yZ MARw9GMY0sQCccO9nRgUG8xSBW/gtI1uzFUasTjjWBqzMU7jGLME+GZ+pDaGzHxCjRpn VwSLk+XirIEwXKfptJr6cHIrB6f63rT5beSsoIMBHw0uZV6Gj6jtdlbU5NzwI2u33ja4 7FmAy+a3r1ajFbjfWwVMOIy3HVTxds4UENimLWN2hnBEv+j29yK0YrsI4ny9VA73EqGj 3xtu+9DrDuOE1ZV6gKCi3yrnTNyQ9g40cLzmSVNrZEVYHy76OAuU5mLxyfusiby9NR5X esGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=GD1eJW8v; 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 d4-20020a056402078400b0051fea43cedfsi3468948edy.384.2023.07.16.12.23.49; Sun, 16 Jul 2023 12:24:13 -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=GD1eJW8v; 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 S230163AbjGPStY (ORCPT + 99 others); Sun, 16 Jul 2023 14:49:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjGPStV (ORCPT ); Sun, 16 Jul 2023 14:49:21 -0400 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FFA31B7 for ; Sun, 16 Jul 2023 11:49:18 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id L6nlqoZFfmJSQL6nmqovE2; Sun, 16 Jul 2023 20:49:06 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689533346; bh=dRGXf+8+arzdqmH6oSLRzr2Fhx/BMcRgYEg7UM8rSZs=; h=From:To:Cc:Subject:Date; b=GD1eJW8vGIAYcERLMhvYqucDWu3L7whDYw+L779/LUftZDaKx7xCMEPxf+2rjlS1d qfKh5VF7YJYytQIZG50ePkaXq1MDVoA7lcNHHZuHvUU0iJGjkbsnDlyMBn2aKTocIL aYmrV/Kaa6NtIxF8uMvwwOAzy+YxYLEn6S1Hzi/QzGBCqlEYOkuka0BGm1gvCCLF6L l0lGdK+5TzTWmzdZDM8SB+ORlQhf6dMnuwf+FN/u/dF2kNFUkxWnJfgSCY/O2gLko0 xTzJ3r7arfPb6etGCxm3PkrxO9DD7zSmRQGan4cNDTM/8lC8A+bcL2OKnPDFJuGvbx aerJgaNL7UH3A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 16 Jul 2023 20:49:06 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Mark Fasheh , Joel Becker , Joseph Qi Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , ocfs2-devel@lists.linux.dev Subject: [PATCH 1/2] ocfs2: Use flexible array in 'struct ocfs2_recovery_map' Date: Sun, 16 Jul 2023 20:48:56 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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: 1771606327675238588 X-GMAIL-MSGID: 1771606327675238588 Turn 'rm_entries' in 'struct ocfs2_recovery_map' 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 'rm_entries' - 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 Reviewed-by: Joseph Qi --- fs/ocfs2/journal.c | 5 +---- fs/ocfs2/journal.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 25d8072ccfce..2f7e70109020 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -178,16 +178,13 @@ int ocfs2_recovery_init(struct ocfs2_super *osb) osb->recovery_thread_task = NULL; init_waitqueue_head(&osb->recovery_event); - rm = kzalloc(sizeof(struct ocfs2_recovery_map) + - osb->max_slots * sizeof(unsigned int), + rm = kzalloc(struct_size(rm, rm_entries, osb->max_slots), GFP_KERNEL); if (!rm) { mlog_errno(-ENOMEM); return -ENOMEM; } - rm->rm_entries = (unsigned int *)((char *)rm + - sizeof(struct ocfs2_recovery_map)); osb->recovery_map = rm; return 0; diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h index 41c382f68529..41c9fe7e62f9 100644 --- a/fs/ocfs2/journal.h +++ b/fs/ocfs2/journal.h @@ -29,7 +29,7 @@ struct ocfs2_dinode; struct ocfs2_recovery_map { unsigned int rm_used; - unsigned int *rm_entries; + unsigned int rm_entries[]; };