From: Chen Gang <chengang@emindsoft.com.cn>
To: Rik van Riel <riel@redhat.com>,
akpm@linux-foundation.org, trivial@kernel.org
Cc: vdavydov@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.cz,
davem@davemloft.net, tj@kernel.org, linux-kernel@vger.kernel.org,
Chen Gang <gang.chen.5i5j@gmail.com>
Subject: Re: [PATCH trivial] include/linux/memcontrol.h: Clean up code only
Date: Fri, 10 Jun 2016 08:26:00 +0800 [thread overview]
Message-ID: <575A0918.4030009@emindsoft.com.cn> (raw)
In-Reply-To: <1465493968.15275.3.camel@redhat.com>
On 6/10/16 01:39, Rik van Riel wrote:
> On Thu, 2016-06-09 at 23:23 +0800, chengang@emindsoft.com.cn wrote:
>> From: Chen Gang <chengang@emindsoft.com.cn>
>>
>> Merge several statements to one return statement, since the new
>> return
>> statement is still simple enough.
>
> This code is not simple, and any change that
> makes it harder to read needs a good reason.
>
> At least in my opinion, your return statement
> merging thing makes the code harder to read.
>
For me, every member has his/her own taste, we need talk about it case
by case.
[...]
>>
>> static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg)
>> {
>> - if (mem_cgroup_disabled())
>> - return 0;
>> -
>> - return memcg->css.id;
>> + return mem_cgroup_disabled() ? 0 : memcg->css.id;
>> }
>>
For me, this is the simplest way for using "? :", so it is easy enough (
I guess, Linux kernel does not completely reject "? :").
>> /**
>> @@ -341,10 +338,7 @@ static inline unsigned short
>> mem_cgroup_id(struct mem_cgroup *memcg)
>> */
>> static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short
>> id)
>> {
>> - struct cgroup_subsys_state *css;
>> -
>> - css = css_from_id(id, &memory_cgrp_subsys);
>> - return mem_cgroup_from_css(css);
>> + return mem_cgroup_from_css(css_from_id(id, &memory_cgrp_subsys));
>> }
>>
For me, this case may depend on various members' tastes (although it is
simple enough to me -- it is in one line within 80 columns, and related
with 2 functions' call).
For this case, if any of another member suggests to keep original code
no touch, too, I shall send patch v2 for it (keep it no touch).
>> /**
>> @@ -390,9 +384,7 @@ ino_t page_cgroup_ino(struct page *page);
>>
>> static inline bool mem_cgroup_online(struct mem_cgroup *memcg)
>> {
>> - if (mem_cgroup_disabled())
>> - return true;
>> - return !!(memcg->css.flags & CSS_ONLINE);
>> + return mem_cgroup_disabled() || (memcg->css.flags & CSS_ONLINE);
>> }
>>
For me, this is almost the simplest way for using "||", we can find
this case in include/linux (60+ cases for '||', and 150+ for '&&'), and
the new return statement is in one line within 80 columns.
The new return statement is not the simplest, but it is still simple
enough (which should be better than original several lines statements).
Thanks.
--
Chen Gang (陈刚)
Managing Natural Environments is the Duty of Human Beings.
prev parent reply other threads:[~2016-06-10 0:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-09 15:23 [PATCH trivial] include/linux/memcontrol.h: Clean up code only chengang
2016-06-09 15:46 ` Michal Hocko
2016-06-10 0:40 ` Chen Gang
2016-06-10 6:14 ` Michal Hocko
2016-06-10 8:34 ` Chen Gang
2016-06-09 17:39 ` Rik van Riel
2016-06-10 0:26 ` Chen Gang [this message]
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=575A0918.4030009@emindsoft.com.cn \
--to=chengang@emindsoft.com.cn \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=gang.chen.5i5j@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.cz \
--cc=riel@redhat.com \
--cc=tj@kernel.org \
--cc=trivial@kernel.org \
--cc=vdavydov@virtuozzo.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