Message ID | 9d99ea2090739f816d0dc0c4ebaa42b26fc48a9e.1689533270.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;chrisben.tianve@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <christophe.jaillet@wanadoo.fr> To: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>, Joseph Qi <joseph.qi@linux.alibaba.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, 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: <c645911ffd2720fce5e344c17de642518cd0db52.1689533270.git.christophe.jaillet@wanadoo.fr> References: <c645911ffd2720fce5e344c17de642518cd0db52.1689533270.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771606246105010563 X-GMAIL-MSGID: 1771606246105010563 |
Series |
[1/2] ocfs2: Use flexible array in 'struct ocfs2_recovery_map'
|
|
Commit Message
Christophe JAILLET
July 16, 2023, 6:48 p.m. UTC
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 <christophe.jaillet@wanadoo.fr>
---
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(-)
Comments
On 7/17/23 2:48 AM, Christophe JAILLET wrote: > 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 <christophe.jaillet@wanadoo.fr> Looks fine. Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> > --- > 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;
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;