Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1697569

Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to memcg state and event functions

From Andrew Morton <akpm@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to memcg state and event functions
Date 2017-07-26 23:30 +0200
Message-ID <u7C2u-5CF-13@gated-at.bofh.it> (permalink)
References <u7Aam-4qo-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, 26 Jul 2017 12:23:56 -0700 Matthias Kaehlcke <mka@chromium.org> wrote:

> In multiple instances enum values of an incorrect type are passed to
> mod_memcg_state() and other memcg functions. Apparently this is
> intentional, however clang rightfully generates tons of warnings about
> the mismatched types. Cast the offending values to the type expected
> by the called function. The casts add noise, but this seems preferable
> over losing the typesafe interface or/and disabling the warning.
> 
> ...
>
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -576,7 +576,7 @@ static inline void __mod_lruvec_state(struct lruvec *lruvec,
>  	if (mem_cgroup_disabled())
>  		return;
>  	pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> -	__mod_memcg_state(pn->memcg, idx, val);
> +	__mod_memcg_state(pn->memcg, (enum memcg_stat_item)idx, val);
>  	__this_cpu_add(pn->lruvec_stat->count[idx], val);
>  }

__mod_memcg_state()'s `idx' arg can be either enum memcg_stat_item or
enum memcg_stat_item.  I think it would be better to just admit to
ourselves that __mod_memcg_state() is more general than it appears, and
change it to take `int idx'.  I assume that this implicit cast of an
enum to an int will not trigger a clang warning?

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] mm: memcontrol: Cast mismatched enum types passed to memcg state and event functions Matthias Kaehlcke <mka@chromium.org> - 2017-07-26 21:30 +0200
  Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Andrew Morton <akpm@linux-foundation.org> - 2017-07-26 23:30 +0200
    Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Matthias Kaehlcke <mka@chromium.org> - 2017-07-26 23:50 +0200
      Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Andrew Morton <akpm@linux-foundation.org> - 2017-07-27 00:10 +0200
        Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Michal Hocko <mhocko@kernel.org> - 2017-07-27 09:30 +0200
          Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Johannes Weiner <hannes@cmpxchg.org> - 2017-07-27 16:20 +0200
            Re: [PATCH] mm: memcontrol: Cast mismatched enum types passed to  memcg state and event functions Matthias Kaehlcke <mka@chromium.org> - 2017-07-27 21:50 +0200

csiph-web