Skip to contentSkip to conversation

mm: zsmalloc: Replace return type int with bool

PATCH Superseded Souptick Joarder 5 participants 10 messages Feb 19, 2018 – Feb 20, 2018

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: zsmalloc: Replace return type int with bool

zs_register_migration() returns either 0 or 1. So the return type int should be replaced with bool.

---
 mm/zsmalloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/zsmalloc.c +5 -5
index c301350..e238354 100644
@@ -295,7 +295,7 @@ struct mapping_area {
 };
 
 #ifdef CONFIG_COMPACTION
-static int zs_register_migration(struct zs_pool *pool);
+static bool zs_register_migration(struct zs_pool *pool);
 static void zs_unregister_migration(struct zs_pool *pool);
 static void migrate_lock_init(struct zspage *zspage);
 static void migrate_read_lock(struct zspage *zspage);
@@ -306,7 +306,7 @@ struct mapping_area {
 #else
 static int zsmalloc_mount(void) { return 0; }
 static void zsmalloc_unmount(void) {}
-static int zs_register_migration(struct zs_pool *pool) { return 0; }
+static bool zs_register_migration(struct zs_pool *pool) { return 0; }
 static void zs_unregister_migration(struct zs_pool *pool) {}
 static void migrate_lock_init(struct zspage *zspage) {}
 static void migrate_read_lock(struct zspage *zspage) {}
@@ -2101,17 +2101,17 @@ void zs_page_putback(struct page *page)
 	.putback_page = zs_page_putback,
 };
 
-static int zs_register_migration(struct zs_pool *pool)
+static bool zs_register_migration(struct zs_pool *pool)
 {
 	pool->inode = alloc_anon_inode(zsmalloc_mnt->mnt_sb);
 	if (IS_ERR(pool->inode)) {
 		pool->inode = NULL;
-		return 1;
+		return true;
 	}
 
 	pool->inode->i_mapping->private_data = pool;
 	pool->inode->i_mapping->a_ops = &zsmalloc_aops;
-	return 0;
+	return false;
 }
 
 static void zs_unregister_migration(struct zs_pool *pool)

--
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 22 lines · Souptick Joarder

zs_register_migration() returns either 0 or 1. So the return type int should be replaced with bool.

---
 mm/zsmalloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/zsmalloc.c +1 -1
index c301350..e238354 100644
@@ -295,7 +295,7 @@ struct mapping_area {
 };
 
 #ifdef CONFIG_COMPACTION
-static int zs_register_migration(struct zs_pool *pool);
+static bool zs_register_migration(struct zs_pool *pool);
 static void zs_unregister_migration(struct zs_pool *pool);
 static void migrate_lock_init(struct zspage *zspage);
 static void migrate_read_lock(struct zspage *zspage);

mm/zsmalloc.c struct mapping_area { · line 309

Quoted 5 lines
mm/zsmalloc.c +1 -1
@@ -306,7 +306,7 @@ struct mapping_area {
 #else
 static int zsmalloc_mount(void) { return 0; }
 static void zsmalloc_unmount(void) {}
-static int zs_register_migration(struct zs_pool *pool) { return 0; }
+static bool zs_register_migration(struct zs_pool *pool) { return 0; }
                                                             return false;
Quoted 15 lines
mm/zsmalloc.c +2 -2
 static void zs_unregister_migration(struct zs_pool *pool) {}
 static void migrate_lock_init(struct zspage *zspage) {}
 static void migrate_read_lock(struct zspage *zspage) {}
@@ -2101,17 +2101,17 @@ void zs_page_putback(struct page *page)
 	.putback_page = zs_page_putback,
 };
 
-static int zs_register_migration(struct zs_pool *pool)
+static bool zs_register_migration(struct zs_pool *pool)
 {
 	pool->inode = alloc_anon_inode(zsmalloc_mnt->mnt_sb);
 	if (IS_ERR(pool->inode)) {
 		pool->inode = NULL;
-		return 1;
+		return true;

mm/zsmalloc.c void zs_page_putback(struct page *page)

Quoted 10 lines
mm/zsmalloc.c +1 -2
 	}
 
 	pool->inode->i_mapping->private_data = pool;
 	pool->inode->i_mapping->a_ops = &zsmalloc_aops;
-	return 0;
+	return false;
 }
 
 static void zs_unregister_migration(struct zs_pool *pool)
--

thanks,

Signature · 7 lines
~Randy

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

[PATCH] mm: zsmalloc: fix boolreturn.cocci warnings

In reply to Souptick Joarder
mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

From: Fengguang Wu <[email protected]>

mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

Return statements in functions returning bool should use true/false instead of 1/0.
Generated by: scripts/coccinelle/misc/boolreturn.cocci

Fixes 3d58cbb028bb ("mm: zsmalloc: Replace return type int with bool")
CC Souptick Joarder <[email protected]>

---

 zsmalloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/zsmalloc.c +1 -1
@@ -306,7 +306,7 @@ static void SetZsPageMovable(struct zs_p
 #else
 static int zsmalloc_mount(void) { return 0; }
 static void zsmalloc_unmount(void) {}
-static bool zs_register_migration(struct zs_pool *pool) { return 0; }
+static bool zs_register_migration(struct zs_pool *pool) { return false; }
 static void zs_unregister_migration(struct zs_pool *pool) {}
 static void migrate_lock_init(struct zspage *zspage) {}
 static void migrate_read_lock(struct zspage *zspage) {}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Souptick Joarder
Thank you for the patch! Perhaps something to improve:

Hi Souptick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.16-rc2 next-20180219]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Souptick-Joarder/mm-zsmalloc-Replace-return-type-int-with-bool/20180220-070147
base:   git://git.cmpxchg.org/linux-mmotm.git master

coccinelle warnings: (new ones prefixed by >>)

>> mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 12 lines · kbuild test robot

Hi Souptick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.16-rc2 next-20180219]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Souptick-Joarder/mm-zsmalloc-Replace-return-type-int-with-bool/20180220-070147
base:   git://git.cmpxchg.org/linux-mmotm.git master
Quoted 6 lines

coccinelle warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

Please review and possibly fold the followup patch.

OK, I will send the v2.

Quoted 3 lines

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#5 lore raw

Hi Souptick,

Quoted 13 lines · Souptick Joarder
Quoted 12 lines · kbuild test robot

Hi Souptick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.16-rc2 next-20180219]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Souptick-Joarder/mm-zsmalloc-Replace-return-type-int-with-bool/20180220-070147
base:   git://git.cmpxchg.org/linux-mmotm.git master
Quoted 8 lines
Quoted 6 lines

coccinelle warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

Please review and possibly fold the followup patch.

OK, I will send the v2.

First of all, thanks for the patch.

Yub, bool could be more appropriate. However, there are lots of other places in kernel where use int instead of bool.
If we fix every such places with each patch, it would be very painful. If you believe it's really worth, it would be better to find/fix every such places in one patch. But I'm not sure it's worth.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 25 lines · Minchan Kim

Hi Souptick,

Quoted 13 lines · Souptick Joarder
Quoted 12 lines · kbuild test robot

Hi Souptick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.16-rc2 next-20180219]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Souptick-Joarder/mm-zsmalloc-Replace-return-type-int-with-bool/20180220-070147
base:   git://git.cmpxchg.org/linux-mmotm.git master
Quoted 8 lines
Quoted 6 lines

coccinelle warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

mm/zsmalloc.c:309:65-66: WARNING: return of 0/1 in function 'zs_register_migration' with return type bool

Please review and possibly fold the followup patch.

OK, I will send the v2.

Quoted 8 lines

First of all, thanks for the patch.

Yub, bool could be more appropriate. However, there are lots of other places in kernel where use int instead of bool.
If we fix every such places with each patch, it would be very painful. If you believe it's really worth, it would be better to find/fix every such places in one patch. But I'm not sure it's worth.

Sure, I will create patch series and send it.

Quoted 1 line

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 9 lines · Souptick Joarder
Quoted 6 lines · Minchan Kim

Yub, bool could be more appropriate. However, there are lots of other places in kernel where use int instead of bool.
If we fix every such places with each patch, it would be very painful. If you believe it's really worth, it would be better to find/fix every such places in one patch. But I'm not sure it's worth.

Sure, I will create patch series and send it.

Please don't. If you're touching a function for another reason, it's fine to convert it to return bool. A series of patches converting every function in the kernel that could be converted will not make friends.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 9 lines · Matthew Wilcox
Quoted 8 lines · Souptick Joarder
Quoted 6 lines · Minchan Kim

Yub, bool could be more appropriate. However, there are lots of other places in kernel where use int instead of bool.
If we fix every such places with each patch, it would be very painful. If you believe it's really worth, it would be better to find/fix every such places in one patch. But I'm not sure it's worth.

Quoted 5 lines
Quoted 1 line

Sure, I will create patch series and send it.

Please don't. If you're touching a function for another reason, it's fine to convert it to return bool. A series of patches converting every function in the kernel that could be converted will not make friends.

... but if you're looking for something to do, here's something from my TODO list that's in the same category.

The vm_ops fault, huge_fault, page_mkwrite and pfn_mkwrite handlers are currently defined to return an int (see linux/mm.h). Unlike the majority of functions which return int, these functions are supposed to return one or more of the VM_FAULT flags. There's general agreement that this should become a new typedef, vm_fault_t. We can do a gradual conversion; start off by adding

typedef int vm_fault_t;

to linux/mm.h. Then the individual drivers can be converted (one patch per driver) to return vm_fault_t from those handlers (probably about 180 patches, so take it slowly). Once all drivers are converted, we can change that typedef to:

typedef enum {
	VM_FAULT_OOM	= 1,
	VM_FAULT_SIGBUS	= 2,
	VM_FAULT_MAJOR	= 4,

...
} vm_fault_t;

and then the compiler will warn if anyone tries to introduce a new handler that returns int.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Hi Matthew,

Quoted 10 lines · Matthew Wilcox
Quoted 9 lines · Matthew Wilcox
Quoted 8 lines · Souptick Joarder
Quoted 6 lines · Minchan Kim

Yub, bool could be more appropriate. However, there are lots of other places in kernel where use int instead of bool.
If we fix every such places with each patch, it would be very painful. If you believe it's really worth, it would be better to find/fix every such places in one patch. But I'm not sure it's worth.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Sure, I will create patch series and send it.

Please don't. If you're touching a function for another reason, it's fine to convert it to return bool. A series of patches converting every function in the kernel that could be converted will not make friends.

... but if you're looking for something to do, here's something from my TODO list that's in the same category.

Thanks. I would like to take it.

Quoted 22 lines

The vm_ops fault, huge_fault, page_mkwrite and pfn_mkwrite handlers are currently defined to return an int (see linux/mm.h). Unlike the majority of functions which return int, these functions are supposed to return one or more of the VM_FAULT flags. There's general agreement that this should become a new typedef, vm_fault_t. We can do a gradual conversion; start off by adding

typedef int vm_fault_t;

to linux/mm.h. Then the individual drivers can be converted (one patch per driver) to return vm_fault_t from those handlers (probably about 180 patches, so take it slowly). Once all drivers are converted, we can change that typedef to:

typedef enum {
VM_FAULT_OOM = 1,
VM_FAULT_SIGBUS = 2,
VM_FAULT_MAJOR = 4,
...
} vm_fault_t;

Quoted 3 lines

and then the compiler will warn if anyone tries to introduce a new handler that returns int.

Let me go through the shared details and will reply you back before making any changes.

-Souptick

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>