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: 13314870 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37FFA748C for ; Sun, 16 Jul 2023 18:56:43 +0000 (UTC) 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 Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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[]; }; From patchwork Sun Jul 16 18:48:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13314871 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0171C748C for ; Sun, 16 Jul 2023 18:56:52 +0000 (UTC) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id L6nlqoZFfmJSQL6nyqovEY; Sun, 16 Jul 2023 20:49:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689533355; bh=oXFfPn5WpEoNL6C6p4wE0Mawt3VwLpg29Dnt35c5y/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QwyYyRyRYJX9aBDwtDMwdqMBNfWwiY2IqxhldV2xxLfH3nywHnxtaUPSNYKA6SF6o fQ4LAe9FVV5xXc/LpybW0+mu0ZWAba9ublz9vHPmaQLiUNfLNVPJ/+4N3NdnxzrHGB MtkhexTxfkdM/9X4l/GzjKbLEo0ZNSyhYnxLmmT8+NsNuYKBfN9b3eLTr6fyYSmdRM SDdc26oqLsUcTNKg/agP1MLmzkHgLSdTs9jH4gcguRJNYfyQhLJ4an119CKvvWBVCC DwNIG8ZugG3uZdM355bmiruAr0Dw+zMPnnfpg+iG10pvu02bepEmZkA2NNtmpn/zi6 6Hhu9p5Uw5Yow== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 16 Jul 2023 20:49:15 +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 2/2] ocfs2: Use struct_size() Date: Sun, 16 Jul 2023 20:48:57 +0200 Message-Id: <9d99ea2090739f816d0dc0c4ebaa42b26fc48a9e.1689533270.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use struct_size() instead of hand-writing it, when allocating a structure with a flex array. This is less verbose. Signed-off-by: Christophe JAILLET Reviewed-by: Joseph Qi --- It will also be helpful if the __counted_by() annotation is added with a Coccinelle script such as: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=devel/counted_by&id=adc5b3cb48a049563dc673f348eab7b6beba8a9b --- fs/ocfs2/journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 2f7e70109020..4e779efe2a4e 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -114,9 +114,9 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb) if (osb->replay_map) return 0; - replay_map = kzalloc(sizeof(struct ocfs2_replay_map) + - (osb->max_slots * sizeof(char)), GFP_KERNEL); - + replay_map = kzalloc(struct_size(replay_map, rm_replay_slots, + osb->max_slots), + GFP_KERNEL); if (!replay_map) { mlog_errno(-ENOMEM); return -ENOMEM;