linux-audit.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH] audit: Use struct_size() helper in alloc_chunk
Date: Mon, 1 Jun 2020 11:36:09 -0400	[thread overview]
Message-ID: <CAHC9VhRcpqs6TGoqK_soTz8Jo5BCDfhq1kqKGGJeJpbXhWZRsg@mail.gmail.com> (raw)
In-Reply-To: <20200524205238.GA17576@embeddedor>

On Sun, May 24, 2020 at 4:47 PM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
>
> struct audit_chunk {
>         ...
>         struct node {
>                 struct list_head list;
>                 struct audit_tree *owner;
>                 unsigned index;         /* index; upper bit indicates 'will prune' */
>         } owners[];
> };
>
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
>
> So, replace the following form:
>
> offsetof(struct audit_chunk, owners) + count * sizeof(struct node);
>
> with:
>
> struct_size(chunk, owners, count)
>
> This code was detected with the help of Coccinelle.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  kernel/audit_tree.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Thanks, this looks reasonable to me, but it came in too late for the
v5.8 merge window (I dislike taking changes past -rc5/6 unless
critical).  Once the merge window closes I'll merge this into
audit/next.

-- 
paul moore
www.paul-moore.com

--
Linux-audit mailing list
Linux-audit@redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit


  reply	other threads:[~2020-06-01 15:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 20:52 [PATCH] audit: Use struct_size() helper in alloc_chunk Gustavo A. R. Silva
2020-06-01 15:36 ` Paul Moore [this message]
2020-06-01 15:51   ` Gustavo A. R. Silva
2020-06-17 20:45   ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHC9VhRcpqs6TGoqK_soTz8Jo5BCDfhq1kqKGGJeJpbXhWZRsg@mail.gmail.com \
    --to=paul@paul-moore.com \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).