linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Mike Kravetz <mike.kravetz@oracle.com>,
	Davidlohr Bueso <dave@stgolabs.net>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Ilie Halip <ilie.halip@gmail.com>,
	David Bolvansky <david.bolvansky@gmail.com>,
	linux-mm@kvack.org, clang-built-linux@googlegroups.com
Subject: -Wsizeof-array-div in mm/hugetlb.c
Date: Tue, 17 Sep 2019 00:34:44 -0700	[thread overview]
Message-ID: <20190917073444.GA14505@archlinux-threadripper> (raw)

Hi all,

Clang recently added a new diagnostic in r371605, -Wsizeof-array-div,
that tries to warn when sizeof(X) / sizeof(Y) does not compute the
number of elements in an array X (i.e., sizeof(Y) is wrong). See that
commit for more details:

https://github.com/llvm/llvm-project/commit/3240ad4ced0d3223149b72a4fc2a4d9b67589427

There is a warning in mm/hugetlb.c in hugetlb_fault_mutex_hash:

mm/hugetlb.c:4055:40: warning: expression does not compute the number of
elements in this array; element type is 'unsigned long', not 'u32' (aka
'unsigned int') [-Wsizeof-array-div]
        hash = jhash2((u32 *)&key, sizeof(key)/sizeof(u32), 0);
                                          ~~~ ^
mm/hugetlb.c:4049:16: note: array 'key' declared here
        unsigned long key[2];
                      ^
1 warning generated.

Should this warning be silenced? What is the reasoning behind having key
be an array of unsigned longs but representing it as an array of u32s?
Would it be better to avoid the cast and have it just be an array of
u32s directly? I am not familiar with this code so I may be naive for
asking such questions but we'd like to get these warnings cleaned up so
that this warning can be useful down the road.

Cheers,
Nathan


             reply	other threads:[~2019-09-17  7:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17  7:34 Nathan Chancellor [this message]
2019-09-17 21:06 ` Mike Kravetz
2019-09-17 21:09   ` Dávid Bolvanský

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=20190917073444.GA14505@archlinux-threadripper \
    --to=natechancellor@gmail.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dave@stgolabs.net \
    --cc=david.bolvansky@gmail.com \
    --cc=ilie.halip@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=ndesaulniers@google.com \
    /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