mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: kent.overstreet@linux.dev, bfoster@redhat.com,
	linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, patches@lists.linux.dev
Subject: Re: [PATCH 7/7] bcachefs: Fix -Wcompare-distinct-pointer-types in bch2_copygc_get_buckets()
Date: Wed, 13 Sep 2023 22:06:27 +0000	[thread overview]
Message-ID: <20230913220627.stso6sxqyraizqod@google.com> (raw)
In-Reply-To: <20230912-bcachefs-warning-fixes-v1-7-a1cc83a38836@kernel.org>

On Tue, Sep 12, 2023 at 12:15:44PM -0700, Nathan Chancellor wrote:
> When building bcachefs for 32-bit ARM, there is a warning when using
> max() to compare an expression involving 'size_t' with an 'unsigned
> long' literal:
>
>   fs/bcachefs/movinggc.c:159:21: error: comparison of distinct pointer types ('typeof (16UL) *' (aka 'unsigned long *') and 'typeof (buckets_in_flight->nr / 4) *' (aka 'unsigned int *')) [-Werror,-Wcompare-distinct-pointer-types]
>     159 |         size_t nr_to_get = max(16UL, buckets_in_flight->nr / 4);
>         |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   include/linux/minmax.h:76:19: note: expanded from macro 'max'
>      76 | #define max(x, y)       __careful_cmp(x, y, >)
>         |                         ^~~~~~~~~~~~~~~~~~~~~~
>   include/linux/minmax.h:38:24: note: expanded from macro '__careful_cmp'
>      38 |         __builtin_choose_expr(__safe_cmp(x, y), \
>         |                               ^~~~~~~~~~~~~~~~
>   include/linux/minmax.h:28:4: note: expanded from macro '__safe_cmp'
>      28 |                 (__typecheck(x, y) && __no_side_effects(x, y))
>         |                  ^~~~~~~~~~~~~~~~~
>   include/linux/minmax.h:22:28: note: expanded from macro '__typecheck'
>      22 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
>         |                    ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
>   1 error generated.
>
> On 64-bit architectures, size_t is 'unsigned long', so there is no
> warning when comparing these two expressions. Use max_t(size_t, ...) for
> this situation, eliminating the warning.
>
> Fixes: dd49018737d4 ("bcachefs: Rhashtable based buckets_in_flight for copygc")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  fs/bcachefs/movinggc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c
> index 256431a6dc0c..1cb441d90b34 100644
> --- a/fs/bcachefs/movinggc.c
> +++ b/fs/bcachefs/movinggc.c
> @@ -156,7 +156,7 @@ static int bch2_copygc_get_buckets(struct btree_trans *trans,
>  	struct bch_fs *c = trans->c;
>  	struct btree_iter iter;
>  	struct bkey_s_c k;
> -	size_t nr_to_get = max(16UL, buckets_in_flight->nr / 4);
> +	size_t nr_to_get = max_t(size_t, 16U, buckets_in_flight->nr / 4);
>  	size_t saw = 0, in_flight = 0, not_movable = 0, sectors = 0;
>  	int ret;
>
>
> --
> 2.42.0
>

  reply	other threads:[~2023-09-13 22:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 19:15 [PATCH 0/7] bcachefs compiler warning fixes for 32-bit Nathan Chancellor
2023-09-12 19:15 ` [PATCH 1/7] bcachefs: Fix -Wformat in bch2_set_bucket_needs_journal_commit() Nathan Chancellor
2023-09-13 21:42   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 2/7] bcachefs: Fix -Wformat in bch2_btree_key_cache_to_text() Nathan Chancellor
2023-09-13 21:43   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 3/7] bcachefs: Fix -Wformat in bch2_alloc_v4_invalid() Nathan Chancellor
2023-09-13 21:46   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 4/7] bcachefs: Fix -Wformat in bch2_bucket_gens_invalid() Nathan Chancellor
2023-09-13 21:46   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 5/7] bcachefs: Fix -Wincompatible-function-pointer-types-strict from key_invalid callbacks Nathan Chancellor
2023-09-13 21:57   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 6/7] bcachefs: Fix -Wcompare-distinct-pointer-types in do_encrypt() Nathan Chancellor
2023-09-13 21:59   ` Justin Stitt
2023-09-12 19:15 ` [PATCH 7/7] bcachefs: Fix -Wcompare-distinct-pointer-types in bch2_copygc_get_buckets() Nathan Chancellor
2023-09-13 22:06   ` Justin Stitt [this message]
2023-09-12 19:36 ` [PATCH 0/7] bcachefs compiler warning fixes for 32-bit Kent Overstreet

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=20230913220627.stso6sxqyraizqod@google.com \
    --to=justinstitt@google.com \
    --cc=bfoster@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=patches@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®