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[]; }; 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: 120921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp745682vqt; Sun, 16 Jul 2023 12:22:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlH4SVHlYnhqQVnwToWbTAyPqk83ntduc6bwRxWbZjkI1ATuTRI5Xz6DGJvAKHSwSRYGCl/j X-Received: by 2002:a17:906:6499:b0:993:f2c2:750b with SMTP id e25-20020a170906649900b00993f2c2750bmr8702938ejm.17.1689535375430; Sun, 16 Jul 2023 12:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689535375; cv=none; d=google.com; s=arc-20160816; b=Fgh6w6Xt0PXyA0vcd5Lte+DBsM0xAlqLi1WpM+VOWdbcp60TlvR33TKh7pC8iLUodI 9RbJ4DUZS7z+4l5Re2acrVRhuPU/HdmuYK/hSW5hfrdAuqjCSWa7VwdD9zjsz35DSLPm GEDix+8l5y8Swu/IL7TylSCUIiLg/lruvHM7FBxR84JajuvoE1jdIxEP+LVKAOf5Qtld y01GRtj4O60TLW8im16cPrfaGNWgH3eyw4TTmz0D6upZk2/ocNNvI3npngmIPhQwRvyI EjdUiMC+ErlsXOFMcqoUykGysUXHx1U4pQt4uvc0O2HIi5e8vztJ2aULe+FpNDqps9C7 qiSQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oXFfPn5WpEoNL6C6p4wE0Mawt3VwLpg29Dnt35c5y/Y=; fh=qEXDlo8x/tE9rmACbw/QFrVSYOuPq28HBMDbO0vMJv0=; b=UNuh03vVx7XNvY4CD4mARA5KHZ0qYx9GZzwqeOUuiug6inwNv/BzqXAWJwQlqo9zfX iIIRw7Hep8NZUF4ouAMe3/ZgjNk8PpmSku56euaF3hiNg5WA/57Uiyvsd9gvu01K3T2m 6P0H8tUChrjAecVLEG0yVO6viILVW7G2VIMzf2ZlbpiVXZgug/DdxqYrRhdB5PDLCnAo ac4rCCH7JcMbcpcFkY8XEJyf7sO2f25jRBguL+pBDbbeDMMF6ZIyuh3bsxsWX93T3b7Q AraN1SqVtG2c+I5Uzg7W6DJLtWE5cGeJn+rJivwyxJws4VftZE0xiXWR2ACEFvnmrVCI +k4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=QwyYyRyR; 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 x7-20020a1709064a8700b0098e422d6759si13344175eju.554.2023.07.16.12.22.29; Sun, 16 Jul 2023 12:22:55 -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=QwyYyRyR; 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 S230144AbjGPStW (ORCPT + 99 others); Sun, 16 Jul 2023 14:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjGPStV (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 0FE5A1B5 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 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: 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: 1771606246105010563 X-GMAIL-MSGID: 1771606246105010563 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;