linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH trivial] include/linux/mempolicy.h: Clean up code
       [not found] <CACVxJT9DUrU+tEOg5nkpoo6d_LaAtUOLqzz_q=7AEsiarwnKjw@mail.gmail.com>
@ 2016-06-10 12:24 ` Alexey Dobriyan
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Dobriyan @ 2016-06-10 12:24 UTC (permalink / raw)
  To: chengang; +Cc: Linux Kernel

On Fri, Jun 10, 2016 at 3:23 PM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
>> Use one return statement instead of multiple statements,
>> since the new return statement is still simple enough.
>
> Multiple statements are very readable exactly
> because one doesn't need to think of negations etc.
>
>> static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
>>  {
>> - if (a == b)
>> - return true;
>> - return __mpol_equal(a, b);
>> + return (a == b) || __mpol_equal(a, b);
>>  }
>
>
>
>>  struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
>> - unsigned long addr);
>> + unsigned long addr);
>
> For prototypes "one line per prototype, no extern" policy should be adopted.
>
>> - if (vma->vm_file &&
>> + return !(vma->vm_file &&
>>   gfp_zone(mapping_gfp_mask(vma->vm_file->f_mapping))
>> - < policy_zone)
>> - return false;
>> - return true;
>> + < policy_zone);
>
> If you align gfp_zone() call to "if (" then second test
> would even fit into one line!
>
> Who told you that shoving everything into one expression
> makes it easier to understand?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH trivial] include/linux/mempolicy.h: Clean up code
@ 2016-06-10  4:46 chengang
  0 siblings, 0 replies; 2+ messages in thread
From: chengang @ 2016-06-10  4:46 UTC (permalink / raw)
  To: akpm, trivial
  Cc: vdavydov, mhocko, riel, rientjes, hughd, nzimmer, baiyaowei,
	linux-kernel, Chen Gang, Chen Gang

From: Chen Gang <chengang@emindsoft.com.cn>

Use one return statement instead of multiple statements, since the new
return statement is still simple enough.

Let the second line function parameter almost align with the first line
function parameter.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 include/linux/mempolicy.h | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index 4429d25..3d7e9c0 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -85,9 +85,7 @@ static inline void mpol_cond_put(struct mempolicy *pol)
 extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
 static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
 {
-	if (pol)
-		pol = __mpol_dup(pol);
-	return pol;
+	return pol ? __mpol_dup(pol) : NULL;
 }
 
 #define vma_policy(vma) ((vma)->vm_policy)
@@ -101,9 +99,7 @@ static inline void mpol_get(struct mempolicy *pol)
 extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b);
 static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
 {
-	if (a == b)
-		return true;
-	return __mpol_equal(a, b);
+	return (a == b) || __mpol_equal(a, b);
 }
 
 /*
@@ -136,7 +132,7 @@ struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
 
 struct mempolicy *get_task_policy(struct task_struct *p);
 struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
-		unsigned long addr);
+				unsigned long addr);
 bool vma_policy_mof(struct vm_area_struct *vma);
 
 extern void numa_default_policy(void);
@@ -150,7 +146,7 @@ extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
 				struct mempolicy **mpol, nodemask_t **nodemask);
 extern bool init_nodemask_of_mempolicy(nodemask_t *mask);
 extern bool mempolicy_nodemask_intersects(struct task_struct *tsk,
-				const nodemask_t *mask);
+					const nodemask_t *mask);
 extern unsigned int mempolicy_slab_node(void);
 
 extern enum zone_type policy_zone;
@@ -187,11 +183,9 @@ static inline bool vma_migratable(struct vm_area_struct *vma)
 	 * do so then migration (at least from node to node) is not
 	 * possible.
 	 */
-	if (vma->vm_file &&
+	return !(vma->vm_file &&
 		gfp_zone(mapping_gfp_mask(vma->vm_file->f_mapping))
-								< policy_zone)
-			return false;
-	return true;
+								< policy_zone);
 }
 
 extern int mpol_misplaced(struct page *, struct vm_area_struct *, unsigned long);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-10 12:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CACVxJT9DUrU+tEOg5nkpoo6d_LaAtUOLqzz_q=7AEsiarwnKjw@mail.gmail.com>
2016-06-10 12:24 ` [PATCH trivial] include/linux/mempolicy.h: Clean up code Alexey Dobriyan
2016-06-10  4:46 chengang

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).