2015-04-29 19:21:42

by David Howells

[permalink] [raw]
Subject: [RFC][PATCH 00/13] Convert bitop funcs to bool return type and propagate to various callers/users


Attached are a bunch of patches that convert bitop functions that return a
boolean value (eg. test_and_set_bit()) to return a bool type rather than an
integer. This is then propagated to a number of callers and users of these
functions.

The patches can also be found here:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=bool-experimental

Note that this only touches the x86 arch and only for my configuration. I
haven't tried any other arches as yet nor other configurations.

This allows the compiler to make slightly better optimisations in some cases,
though functions that used to return a non-zero/zero integer as true/false now
get slightly bigger as they have to return one/zero instead (typically a
matter of 3 bytes or so on x86_64). Quite a few functions, however, get
smaller but in most cases, because the altered functions are inline, and
because if() converts the value to bool anyway, there is no change.

Further, with gcc-5, warnings are given about using an unwrapped '!' operator
on the LHS of a comparison expression. Note that these warnings aren't given
if the thing on the RHS is a bool.

Yet further, it permits "!!test_bit()" constructs to be converted to
"test_bit()" as the "!!" becomes redundant.

On my test kernel which has a bunch of drivers built in sufficient to boot my
test box, a reduction in .text size of 256 bytes is seen. Below is a table
detailing the changes in size of individual function objects:

warthog>../compare-elf.pl build/vmlinux.old build/vmlinux
build/vmlinux.old has 65065 symbols
build/vmlinux has 65065 symbols
ELF 1 ADDR ELF 2 ADDR SIZE2 dSIZ NAME
================ ================ ===== ==== ================
ffffffff81006305 ffffffff81006305 24 +5 default_check_phys_apicid
ffffffff81029070 ffffffff81029074 265 -5 perf_ibs_stop
ffffffff8102ec75 ffffffff8102ec75 15 -2 default_apic_id_valid
ffffffff8102ecaa ffffffff8102eca8 20 +3 default_check_apicid_used
ffffffff81032008 ffffffff81032009 15 -2 default_apic_id_valid
ffffffff810320ed ffffffff810320ec 45 +5 flat_apic_id_registered
ffffffff81035be3 ffffffff81035be7 279 -6 kern_addr_valid
ffffffff810360f9 ffffffff810360f7 330 -17 dump_pagetable
ffffffff810362e6 ffffffff810362d3 50 -11 spurious_fault_check
ffffffff81036323 ffffffff81036305 301 -16 spurious_fault
ffffffff810365f3 ffffffff810365c5 821 -20 no_context
ffffffff81037f2e ffffffff81037eec 343 -5 unmap_pmd_range
ffffffff810385ad ffffffff81038566 189 -10 lookup_address_in_pgd
ffffffff8103b126 ffffffff8103b0d5 24 -6 ptep_set_access_flags
ffffffff8103b144 ffffffff8103b0ed 24 -3 ptep_test_and_clear_young
ffffffff8103b1b8 ffffffff8103b15e 110 -3 pud_set_huge
ffffffff8103b229 ffffffff8103b1cc 110 -3 pmd_set_huge
ffffffff8103b29a ffffffff8103b23a 35 -3 pud_clear_huge
ffffffff8103b2c0 ffffffff8103b25d 22 -16 pmd_clear_huge
ffffffff8103b586 ffffffff8103b513 374 -10 gup_pud_range
ffffffff810452b1 ffffffff81045231 23 +5 test_taint
ffffffff81075009 ffffffff81074f8e 1936 +5 select_task_rq_fair
ffffffff81090f33 ffffffff81090ebd 47 +5 memory_bm_test_bit
ffffffff810b36f2 ffffffff810b3681 28 +3 tick_is_broadcast_device
ffffffff810b38f1 ffffffff810b3883 30 +5 tick_check_broadcast_expi
ffffffff810b3a33 ffffffff810b39ca 244 +2 tick_device_uses_broadcas
ffffffff810b3d2c ffffffff810b3cc5 16 -2 tick_broadcast_oneshot_ac
ffffffff810cde6c ffffffff810cde03 536 +10 __cpuset_node_allowed
ffffffff81109c5a ffffffff81109bfb 1362 -16 generic_file_read_iter
ffffffff81111e1e ffffffff81111daf 349 -3 __test_set_page_writeback
ffffffff8111207a ffffffff81112008 94 -3 set_page_dirty
ffffffff81112128 ffffffff811120b3 181 -3 clear_page_dirty_for_io
ffffffff811127f6 ffffffff8111277e 209 -3 __set_page_dirty_nobuffer
ffffffff8111421b ffffffff811141a0 30 -3 __set_page_dirty_no_write
ffffffff8111423c ffffffff811141be 405 -6 test_clear_page_writeback
ffffffff81119e57 ffffffff81119dd3 2605 -7 shrink_page_list
ffffffff8112aa62 ffffffff8112a9d7 706 -23 follow_page_mask
ffffffff8112ca3a ffffffff8112c998 1383 -24 unmap_single_vma
ffffffff8112d17c ffffffff8112d0c2 1151 +1 do_wp_page
ffffffff8112ea0e ffffffff8112e955 3453 -1 handle_mm_fault
ffffffff811303a4 ffffffff811302ea 563 -2 munlock_vma_pages_range
ffffffff811321ab ffffffff811320ef 138 +6 vma_wants_writenotify
ffffffff81133f59 ffffffff81133ea3 1091 -11 change_protection
ffffffff811343a7 ffffffff811342e6 445 -1 mprotect_fixup
ffffffff81135bb5 ffffffff81135af3 674 -24 try_to_unmap_one
ffffffff81136b0c ffffffff81136a32 256 -3 page_referenced
ffffffff8114026d ffffffff81140190 364 +12 queue_pages_pte_range
ffffffff81183d5b ffffffff81183c8a 159 -19 __set_page_dirty_buffers
ffffffff811abf09 ffffffff811abe25 331 -15 gather_pte_stats
ffffffff811ac063 ffffffff811abf70 456 -13 smaps_pte_range
ffffffff811c5e3e ffffffff811c5d3e 476 +9 ext3_orphan_get
ffffffff811e0645 ffffffff811e054e 490 +9 ext4_orphan_get
ffffffff811fce65 ffffffff811fcd77 479 -9 ext4_commit_super
ffffffff8122689d ffffffff812267a6 177 -3 __journal_refile_buffer
ffffffff8122a315 ffffffff8122a21b 208 +2 journal_cancel_revoke
ffffffff8122fdad ffffffff8122fcb5 176 -3 __jbd2_journal_refile_buf
ffffffff812340cc ffffffff81233fd1 210 +3 jbd2_journal_cancel_revok
ffffffff812dbe40 ffffffff812dbd48 22 +3 radix_tree_tagged
ffffffff812e48f9 ffffffff812e47f9 75 -6 __bitmap_equal
ffffffff812e497b ffffffff812e4875 81 -2 __bitmap_and
ffffffff812e4a1c ffffffff812e4914 87 -2 __bitmap_andnot
ffffffff812e4a75 ffffffff812e496b 77 -6 __bitmap_intersects
ffffffff812e4ac8 ffffffff812e49b8 80 -6 __bitmap_subset
ffffffff8142eb56 ffffffff8142ea36 1171 -5 input_handle_event
ffffffff8142f05a ffffffff8142ef35 386 -2 input_inject_event
ffffffff814bfc55 ffffffff814bfb35 343 -3 flow_cache_flush
ffffffff814ce9cf ffffffff814ce8ac 374 +3 netlink_has_listeners
ffffffff814cf076 ffffffff814cef56 77 +5 netlink_update_socket_mc

As can be seen, most of the size changes are negative indicating the function
ended up smaller. After changing the return values of the bitops functions, I
attacked things that appeared in this list, trying to make them smaller.

The script that generated the above table is:

#!/usr/bin/perl -w
#
# Compare the layout of ELF files
#
use strict;
no warnings 'portable'; # Support for 64-bit ints required

die "Format: compare-elf.pl <file1> <file2>\n" unless ($#ARGV == 1);

###############################################################################
#
# Use readelf to scan a file; load the data into an array and sort it.
#
###############################################################################
sub read_elf($$) {
my ($file, $array) = @_;

@{$array} = ();

open FD, "readelf -s $file|" || die "$file";
while (<FD>) {
chomp;
next if ($_ eq "");
next if (/^\s+Num:/);
next if (/^Symbol table/);
$_ =~ s/^ +//;

my @bits = split(/\s+/, $_);
die "Odd line ", $#bits, ": '$_'\n" unless ($#bits >= 6);

my ($num, $value, $size, $type, $bind, $vis, $section, $name) = @bits;

if ($size =~ /^0x/) {
$size = hex($size);
} else {
$size = int($size);
}
next if ($type eq "FILE");
next if ($type eq "SECTION");
push @{$array}, [ hex($value), $size, $type, $name ];
}
}

my @sysmap1;
my @sysmap2;

read_elf($ARGV[0], \@sysmap1);
read_elf($ARGV[1], \@sysmap2);

@sysmap1 = sort { $a->[0] <=> $b->[0] } @sysmap1;
@sysmap2 = sort { $a->[0] <=> $b->[0] } @sysmap2;

print $ARGV[0], " has ", $#sysmap1 + 1, " symbols\n";
print $ARGV[1], " has ", $#sysmap2 + 1, " symbols\n";

my $i1 = 0;
my $i2 = 0;
my $offset = 0;

print("ELF 1 ADDR ELF 2 ADDR SIZE2 dSIZ NAME\n");
print("================ ================ ===== ==== ================\n");
while ($i1 <= $#sysmap1) {
my $this1 = $sysmap1[$i1++];
my $this2 = $sysmap2[$i2++];

if ($this1->[1] != $this2->[1]) {
printf("%016x %016x %5d %+4d %s\n",
$this1->[0],
$this2->[0],
$this2->[1],
$this2->[1] - $this1->[1],
$this1->[3]);
}
}


David
---
David Howells (13):
Make the x86 bitops like test_bit() return bool
Make bitmap functions that return boolean values return a bool type
Make generic bitops return bool
Make cpumask functions that return boolean values return bool
Make nodemask functions that return a boolean value return bool
Make a bunch of mm funcs return bool when they're returning a boolean value
Make some apic functions return bool when returning a boolean value
Make tick functions that return a boolean value return bool
input: Use bool and don't use !! on test_bit
Use bool with jbd2_journal_cancel_revoke()
test_taint() should return bool
netlink: Use bool when returning boolean values
Make xfrm functions that return a boolean value return bool


arch/x86/include/asm/apic.h | 22 +++---
arch/x86/include/asm/bitops.h | 28 ++++---
arch/x86/include/asm/pgtable.h | 110 ++++++++++++++--------------
arch/x86/include/asm/rmwcc.h | 4 +
arch/x86/kernel/apic/apic_flat_64.c | 2 -
arch/x86/kernel/apic/apic_noop.c | 2 -
arch/x86/kernel/setup.c | 2 -
arch/x86/mm/pgtable.c | 62 ++++++++--------
drivers/hid/hid-input.c | 4 +
drivers/input/input.c | 12 ++-
drivers/staging/lustre/lustre/llite/rw26.c | 2 -
fs/afs/internal.h | 2 -
fs/afs/write.c | 2 -
fs/buffer.c | 4 +
fs/ceph/addr.c | 6 +-
fs/ext3/inode.c | 2 -
fs/ext4/inode.c | 2 -
fs/gfs2/aops.c | 4 +
fs/jbd2/revoke.c | 10 +--
fs/libfs.c | 4 +
include/asm-generic/bitops/ext2-atomic.h | 4 +
include/asm-generic/bitops/le.h | 10 +--
include/asm-generic/pgtable.h | 32 ++++----
include/linux/bitmap.h | 30 ++++----
include/linux/buffer_head.h | 8 +-
include/linux/clockchips.h | 6 +-
include/linux/cpumask.h | 12 ++-
include/linux/fs.h | 4 +
include/linux/hugetlb.h | 16 ++--
include/linux/hugetlb_inline.h | 6 +-
include/linux/jbd2.h | 2 -
include/linux/kernel.h | 2 -
include/linux/mm.h | 14 ++--
include/linux/netfilter/nfnetlink.h | 2 -
include/linux/netlink.h | 2 -
include/linux/nodemask.h | 16 ++--
include/linux/page-flags.h | 28 ++++---
include/linux/radix-tree.h | 2 -
include/linux/suspend.h | 2 -
include/linux/swap.h | 2 -
include/net/xfrm.h | 8 +-
kernel/panic.c | 2 -
kernel/power/snapshot.c | 8 +-
kernel/time/tick-broadcast.c | 16 ++--
kernel/time/tick-internal.h | 6 +-
lib/bitmap.c | 32 ++++----
lib/radix-tree.c | 4 +
mm/mmap.c | 16 ++--
mm/page-writeback.c | 44 ++++++-----
mm/page_io.c | 2 -
net/netfilter/nfnetlink.c | 2 -
net/netlink/af_netlink.c | 21 +++--
52 files changed, 324 insertions(+), 323 deletions(-)


2015-04-29 19:21:49

by David Howells

[permalink] [raw]
Subject: [PATCH 01/13] Make the x86 bitops like test_bit() return bool

Make the x86 bitop functions like test_bit() return bool rather than an
integer. This permits gcc-5 to make better choices and can reduce the code
size overall and allows some warnings to be evaded.
---

arch/x86/include/asm/bitops.h | 28 ++++++++++++++--------------
arch/x86/include/asm/rmwcc.h | 4 ++--
2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index cfe3b954d5e4..7bbcce00b43d 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -201,7 +201,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
-static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
+static inline bool test_and_set_bit(long nr, volatile unsigned long *addr)
{
GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
}
@@ -213,7 +213,7 @@ static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
*
* This is the same as test_and_set_bit on x86.
*/
-static __always_inline int
+static __always_inline bool
test_and_set_bit_lock(long nr, volatile unsigned long *addr)
{
return test_and_set_bit(nr, addr);
@@ -228,7 +228,7 @@ test_and_set_bit_lock(long nr, volatile unsigned long *addr)
* If two examples of this operation race, one can appear to succeed
* but actually fail. You must protect multiple accesses with a lock.
*/
-static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
+static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr)
{
int oldbit;

@@ -236,7 +236,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
"sbb %0,%0"
: "=r" (oldbit), ADDR
: "Ir" (nr));
- return oldbit;
+ return oldbit != 0;
}

/**
@@ -247,7 +247,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
-static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
+static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr)
{
GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
}
@@ -268,7 +268,7 @@ static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
* accessed from a hypervisor on the same CPU if running in a VM: don't change
* this without also updating arch/x86/kernel/kvm.c
*/
-static inline int __test_and_clear_bit(long nr, volatile unsigned long *addr)
+static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr)
{
int oldbit;

@@ -276,11 +276,11 @@ static inline int __test_and_clear_bit(long nr, volatile unsigned long *addr)
"sbb %0,%0"
: "=r" (oldbit), ADDR
: "Ir" (nr));
- return oldbit;
+ return oldbit != 0;
}

/* WARNING: non atomic and it can be reordered! */
-static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
+static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr)
{
int oldbit;

@@ -289,7 +289,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
: "=r" (oldbit), ADDR
: "Ir" (nr) : "memory");

- return oldbit;
+ return oldbit != 0;
}

/**
@@ -300,18 +300,18 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
-static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
+static inline bool test_and_change_bit(long nr, volatile unsigned long *addr)
{
GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
}

-static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
+static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr)
{
return ((1UL << (nr & (BITS_PER_LONG-1))) &
(addr[nr >> _BITOPS_LONG_SHIFT])) != 0;
}

-static inline int variable_test_bit(long nr, volatile const unsigned long *addr)
+static inline bool variable_test_bit(long nr, volatile const unsigned long *addr)
{
int oldbit;

@@ -320,7 +320,7 @@ static inline int variable_test_bit(long nr, volatile const unsigned long *addr)
: "=r" (oldbit)
: "m" (*(unsigned long *)addr), "Ir" (nr));

- return oldbit;
+ return oldbit != 0;
}

#if 0 /* Fool kernel-doc since it doesn't do macros yet */
@@ -329,7 +329,7 @@ static inline int variable_test_bit(long nr, volatile const unsigned long *addr)
* @nr: bit number to test
* @addr: Address to start counting from
*/
-static int test_bit(int nr, const volatile unsigned long *addr);
+static bool test_bit(int nr, const volatile unsigned long *addr);
#endif

#define test_bit(nr, addr) \
diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
index 8f7866a5b9a4..a712ef68541f 100644
--- a/arch/x86/include/asm/rmwcc.h
+++ b/arch/x86/include/asm/rmwcc.h
@@ -8,9 +8,9 @@ do { \
asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
: : "m" (var), ## __VA_ARGS__ \
: "memory" : cc_label); \
- return 0; \
+ return false; \
cc_label: \
- return 1; \
+ return true; \
} while (0)

#define GEN_UNARY_RMWcc(op, var, arg0, cc) \

2015-04-29 19:21:55

by David Howells

[permalink] [raw]
Subject: [PATCH 02/13] Make bitmap functions that return boolean values return a bool type

Make bitmap functions that return boolean values return a bool type. This
permits gcc to make better choices and produce fewer warnings.

Signed-off-by: David Howells <[email protected]>
---

include/linux/bitmap.h | 30 +++++++++++++++---------------
lib/bitmap.c | 32 ++++++++++++++++----------------
2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index ea17cca9e685..46c6cca6fcb4 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -87,9 +87,9 @@
* lib/bitmap.c provides these functions:
*/

-extern int __bitmap_empty(const unsigned long *bitmap, unsigned int nbits);
-extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits);
-extern int __bitmap_equal(const unsigned long *bitmap1,
+extern bool __bitmap_empty(const unsigned long *bitmap, unsigned int nbits);
+extern bool __bitmap_full(const unsigned long *bitmap, unsigned int nbits);
+extern bool __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
unsigned int nbits);
@@ -97,17 +97,17 @@ extern void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
unsigned int shift, unsigned int nbits);
extern void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
unsigned int shift, unsigned int nbits);
-extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
- const unsigned long *bitmap2, unsigned int nbits);
+extern bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, unsigned int nbits);
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
-extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+extern bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
-extern int __bitmap_intersects(const unsigned long *bitmap1,
+extern bool __bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
-extern int __bitmap_subset(const unsigned long *bitmap1,
+extern bool __bitmap_subset(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);

@@ -209,7 +209,7 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
}
}

-static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
+static inline bool bitmap_and(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
@@ -235,7 +235,7 @@ static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
__bitmap_xor(dst, src1, src2, nbits);
}

-static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
+static inline bool bitmap_andnot(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
@@ -252,7 +252,7 @@ static inline void bitmap_complement(unsigned long *dst, const unsigned long *sr
__bitmap_complement(dst, src, nbits);
}

-static inline int bitmap_equal(const unsigned long *src1,
+static inline bool bitmap_equal(const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
@@ -261,7 +261,7 @@ static inline int bitmap_equal(const unsigned long *src1,
return __bitmap_equal(src1, src2, nbits);
}

-static inline int bitmap_intersects(const unsigned long *src1,
+static inline bool bitmap_intersects(const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
@@ -270,7 +270,7 @@ static inline int bitmap_intersects(const unsigned long *src1,
return __bitmap_intersects(src1, src2, nbits);
}

-static inline int bitmap_subset(const unsigned long *src1,
+static inline bool bitmap_subset(const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
@@ -279,7 +279,7 @@ static inline int bitmap_subset(const unsigned long *src1,
return __bitmap_subset(src1, src2, nbits);
}

-static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
+static inline bool bitmap_empty(const unsigned long *src, unsigned nbits)
{
if (small_const_nbits(nbits))
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
@@ -287,7 +287,7 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
return find_first_bit(src, nbits) == nbits;
}

-static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
+static inline bool bitmap_full(const unsigned long *src, unsigned int nbits)
{
if (small_const_nbits(nbits))
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 64c0926f5dd8..663a82df8f38 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -42,19 +42,19 @@
* for the best explanations of this ordering.
*/

-int __bitmap_equal(const unsigned long *bitmap1,
+bool __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] != bitmap2[k])
- return 0;
+ return false;

if (bits % BITS_PER_LONG)
if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
- return 0;
+ return false;

- return 1;
+ return true;
}
EXPORT_SYMBOL(__bitmap_equal);

@@ -150,7 +150,7 @@ void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
}
EXPORT_SYMBOL(__bitmap_shift_left);

-int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k;
@@ -188,7 +188,7 @@ void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
}
EXPORT_SYMBOL(__bitmap_xor);

-int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k;
@@ -204,33 +204,33 @@ int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
}
EXPORT_SYMBOL(__bitmap_andnot);

-int __bitmap_intersects(const unsigned long *bitmap1,
- const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_intersects(const unsigned long *bitmap1,
+ const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] & bitmap2[k])
- return 1;
+ return true;

if (bits % BITS_PER_LONG)
if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
- return 1;
- return 0;
+ return true;
+ return false;
}
EXPORT_SYMBOL(__bitmap_intersects);

-int __bitmap_subset(const unsigned long *bitmap1,
- const unsigned long *bitmap2, unsigned int bits)
+bool __bitmap_subset(const unsigned long *bitmap1,
+ const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] & ~bitmap2[k])
- return 0;
+ return false;

if (bits % BITS_PER_LONG)
if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
- return 0;
- return 1;
+ return false;
+ return true;
}
EXPORT_SYMBOL(__bitmap_subset);

2015-04-29 19:24:55

by David Howells

[permalink] [raw]
Subject: [PATCH 03/13] Make generic bitops return bool

Make generic bit handling functions return a bool type when they're returning
a simple boolean value. This allows gcc to make better choices and produce
better warnings.

Signed-off-by: David Howells <[email protected]>
---

include/asm-generic/bitops/ext2-atomic.h | 4 ++--
include/asm-generic/bitops/le.h | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/asm-generic/bitops/ext2-atomic.h b/include/asm-generic/bitops/ext2-atomic.h
index 87f0f109d7f1..8048f8b38720 100644
--- a/include/asm-generic/bitops/ext2-atomic.h
+++ b/include/asm-generic/bitops/ext2-atomic.h
@@ -7,7 +7,7 @@

#define ext2_set_bit_atomic(lock, nr, addr) \
({ \
- int ret; \
+ bool ret; \
spin_lock(lock); \
ret = __test_and_set_bit_le(nr, addr); \
spin_unlock(lock); \
@@ -16,7 +16,7 @@

#define ext2_clear_bit_atomic(lock, nr, addr) \
({ \
- int ret; \
+ bool ret; \
spin_lock(lock); \
ret = __test_and_clear_bit_le(nr, addr); \
spin_unlock(lock); \
diff --git a/include/asm-generic/bitops/le.h b/include/asm-generic/bitops/le.h
index 61731543c00e..c610b9943a08 100644
--- a/include/asm-generic/bitops/le.h
+++ b/include/asm-generic/bitops/le.h
@@ -49,7 +49,7 @@ extern unsigned long find_next_bit_le(const void *addr,
#error "Please fix <asm/byteorder.h>"
#endif

-static inline int test_bit_le(int nr, const void *addr)
+static inline bool test_bit_le(int nr, const void *addr)
{
return test_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}
@@ -74,22 +74,22 @@ static inline void __clear_bit_le(int nr, void *addr)
__clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}

-static inline int test_and_set_bit_le(int nr, void *addr)
+static inline bool test_and_set_bit_le(int nr, void *addr)
{
return test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}

-static inline int test_and_clear_bit_le(int nr, void *addr)
+static inline bool test_and_clear_bit_le(int nr, void *addr)
{
return test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}

-static inline int __test_and_set_bit_le(int nr, void *addr)
+static inline bool __test_and_set_bit_le(int nr, void *addr)
{
return __test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}

-static inline int __test_and_clear_bit_le(int nr, void *addr)
+static inline bool __test_and_clear_bit_le(int nr, void *addr)
{
return __test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
}

2015-04-29 19:22:08

by David Howells

[permalink] [raw]
Subject: [PATCH 04/13] Make cpumask functions that return boolean values return bool

Make cpumask functions that return boolean values return bool so that gcc can
make better choices.

Signed-off-by: David Howells <[email protected]>
---

include/linux/cpumask.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 27e285b92b5f..7afeb854d349 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -289,9 +289,9 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
* @cpu: cpu number (< nr_cpu_ids)
* @cpumask: the cpumask pointer
*
- * Returns 1 if @cpu is set in @cpumask, else returns 0
+ * Returns true if @cpu is set in @cpumask
*/
-static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
+static inline bool cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
{
return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
}
@@ -301,11 +301,11 @@ static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
* @cpu: cpu number (< nr_cpu_ids)
* @cpumask: the cpumask pointer
*
- * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
+ * Returns true if @cpu is set in old bitmap of @cpumask
*
* test_and_set_bit wrapper for cpumasks.
*/
-static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
+static inline bool cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
{
return test_and_set_bit(cpumask_check(cpu), cpumask_bits(cpumask));
}
@@ -315,11 +315,11 @@ static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *cpumask)
* @cpu: cpu number (< nr_cpu_ids)
* @cpumask: the cpumask pointer
*
- * Returns 1 if @cpu is set in old bitmap of @cpumask, else returns 0
+ * Returns true if @cpu is set in old bitmap of @cpumask
*
* test_and_clear_bit wrapper for cpumasks.
*/
-static inline int cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
+static inline bool cpumask_test_and_clear_cpu(int cpu, struct cpumask *cpumask)
{
return test_and_clear_bit(cpumask_check(cpu), cpumask_bits(cpumask));
}

2015-04-29 19:22:15

by David Howells

[permalink] [raw]
Subject: [PATCH 05/13] Make nodemask functions that return a boolean value return bool

Make nodemask functions that return a boolean value return bool as this allows
gcc to make better choices.

Signed-off-by: David Howells <[email protected]>
---

include/linux/nodemask.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 6e85889cf9ab..520dcb59f53d 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -141,7 +141,7 @@ static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits)

#define node_test_and_set(node, nodemask) \
__node_test_and_set((node), &(nodemask))
-static inline int __node_test_and_set(int node, nodemask_t *addr)
+static inline bool __node_test_and_set(int node, nodemask_t *addr)
{
return test_and_set_bit(node, addr->bits);
}
@@ -188,7 +188,7 @@ static inline void __nodes_complement(nodemask_t *dstp,

#define nodes_equal(src1, src2) \
__nodes_equal(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_equal(const nodemask_t *src1p,
+static inline bool __nodes_equal(const nodemask_t *src1p,
const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_equal(src1p->bits, src2p->bits, nbits);
@@ -196,7 +196,7 @@ static inline int __nodes_equal(const nodemask_t *src1p,

#define nodes_intersects(src1, src2) \
__nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_intersects(const nodemask_t *src1p,
+static inline bool __nodes_intersects(const nodemask_t *src1p,
const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_intersects(src1p->bits, src2p->bits, nbits);
@@ -204,20 +204,20 @@ static inline int __nodes_intersects(const nodemask_t *src1p,

#define nodes_subset(src1, src2) \
__nodes_subset(&(src1), &(src2), MAX_NUMNODES)
-static inline int __nodes_subset(const nodemask_t *src1p,
+static inline bool __nodes_subset(const nodemask_t *src1p,
const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_subset(src1p->bits, src2p->bits, nbits);
}

#define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
-static inline int __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
+static inline bool __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
{
return bitmap_empty(srcp->bits, nbits);
}

#define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
-static inline int __nodes_full(const nodemask_t *srcp, unsigned int nbits)
+static inline bool __nodes_full(const nodemask_t *srcp, unsigned int nbits)
{
return bitmap_full(srcp->bits, nbits);
}
@@ -395,7 +395,7 @@ enum node_states {
extern nodemask_t node_states[NR_NODE_STATES];

#if MAX_NUMNODES > 1
-static inline int node_state(int node, enum node_states state)
+static inline bool node_state(int node, enum node_states state)
{
return node_isset(node, node_states[state]);
}
@@ -446,7 +446,7 @@ static inline void node_set_offline(int nid)

#else

-static inline int node_state(int node, enum node_states state)
+static inline bool node_state(int node, enum node_states state)
{
return node == 0;
}

2015-04-29 19:24:27

by David Howells

[permalink] [raw]
Subject: [PATCH 06/13] Make a bunch of mm funcs return bool when they're returning a boolean value

Make a bunch of mm funcs return bool when they're really returning a boolean
value. A lot of these end up building on test_bit() and co. anyway.

Note that this covers:

(1) PTE/PMD/PUD/PGD testing functions, such as pte_dirty().

(2) PTE/PMD/PUD/PGD modification functions that return boolean values, such
as ptep_clear_flush_young() and pmd_set_huge().

(3) *set_page_dirty() functions, including the address_space_operations func
pointer of that name.

(4) Various hugepages test functions, eg. is_file_hugepages().

(5) page->flags testing and modify-test functions, eg. PageUptodate().

(6) mapping_tagged() and radix_tree_tagged(). More of the radix tree code
could probably converted than just this.

(7) Various other mm functions that return boolean values,
eg. vma_wants_writenotify().

Note that a lot of these functions are inline, so changing to returning a bool
usually has no impact since if() is going to convert the result to bool
anyway.

Signed-off-by: David Howells <[email protected]>
---

arch/x86/include/asm/pgtable.h | 110 ++++++++++++++--------------
arch/x86/mm/pgtable.c | 62 ++++++++--------
drivers/staging/lustre/lustre/llite/rw26.c | 2 -
fs/afs/internal.h | 2 -
fs/afs/write.c | 2 -
fs/buffer.c | 4 +
fs/ceph/addr.c | 6 +-
fs/ext3/inode.c | 2 -
fs/ext4/inode.c | 2 -
fs/gfs2/aops.c | 4 +
fs/libfs.c | 4 +
include/asm-generic/pgtable.h | 32 ++++----
include/linux/buffer_head.h | 8 +-
include/linux/fs.h | 4 +
include/linux/hugetlb.h | 16 ++--
include/linux/hugetlb_inline.h | 6 +-
include/linux/mm.h | 14 ++--
include/linux/page-flags.h | 28 ++++---
include/linux/radix-tree.h | 2 -
include/linux/suspend.h | 2 -
include/linux/swap.h | 2 -
kernel/power/snapshot.c | 8 +-
lib/radix-tree.c | 4 +
mm/mmap.c | 16 ++--
mm/page-writeback.c | 44 ++++++-----
mm/page_io.c | 2 -
26 files changed, 194 insertions(+), 194 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index fe57e7a98839..be3712885a9f 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -90,47 +90,47 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
* The following only work if pte_present() is true.
* Undefined behaviour if not..
*/
-static inline int pte_dirty(pte_t pte)
+static inline bool pte_dirty(pte_t pte)
{
return pte_flags(pte) & _PAGE_DIRTY;
}

-static inline int pte_young(pte_t pte)
+static inline bool pte_young(pte_t pte)
{
return pte_flags(pte) & _PAGE_ACCESSED;
}

-static inline int pmd_dirty(pmd_t pmd)
+static inline bool pmd_dirty(pmd_t pmd)
{
return pmd_flags(pmd) & _PAGE_DIRTY;
}

-static inline int pmd_young(pmd_t pmd)
+static inline bool pmd_young(pmd_t pmd)
{
return pmd_flags(pmd) & _PAGE_ACCESSED;
}

-static inline int pte_write(pte_t pte)
+static inline bool pte_write(pte_t pte)
{
return pte_flags(pte) & _PAGE_RW;
}

-static inline int pte_huge(pte_t pte)
+static inline bool pte_huge(pte_t pte)
{
return pte_flags(pte) & _PAGE_PSE;
}

-static inline int pte_global(pte_t pte)
+static inline bool pte_global(pte_t pte)
{
return pte_flags(pte) & _PAGE_GLOBAL;
}

-static inline int pte_exec(pte_t pte)
+static inline bool pte_exec(pte_t pte)
{
return !(pte_flags(pte) & _PAGE_NX);
}

-static inline int pte_special(pte_t pte)
+static inline bool pte_special(pte_t pte)
{
return pte_flags(pte) & _PAGE_SPECIAL;
}
@@ -152,23 +152,23 @@ static inline unsigned long pud_pfn(pud_t pud)

#define pte_page(pte) pfn_to_page(pte_pfn(pte))

-static inline int pmd_large(pmd_t pte)
+static inline bool pmd_large(pmd_t pte)
{
return pmd_flags(pte) & _PAGE_PSE;
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-static inline int pmd_trans_splitting(pmd_t pmd)
+static inline bool pmd_trans_splitting(pmd_t pmd)
{
return pmd_val(pmd) & _PAGE_SPLITTING;
}

-static inline int pmd_trans_huge(pmd_t pmd)
+static inline bool pmd_trans_huge(pmd_t pmd)
{
return pmd_val(pmd) & _PAGE_PSE;
}

-static inline int has_transparent_hugepage(void)
+static inline bool has_transparent_hugepage(void)
{
return cpu_has_pse;
}
@@ -298,12 +298,12 @@ static inline pmd_t pmd_mknotpresent(pmd_t pmd)
}

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
-static inline int pte_soft_dirty(pte_t pte)
+static inline bool pte_soft_dirty(pte_t pte)
{
return pte_flags(pte) & _PAGE_SOFT_DIRTY;
}

-static inline int pmd_soft_dirty(pmd_t pmd)
+static inline bool pmd_soft_dirty(pmd_t pmd)
{
return pmd_flags(pmd) & _PAGE_SOFT_DIRTY;
}
@@ -383,15 +383,15 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)

#define canon_pgprot(p) __pgprot(massage_pgprot(p))

-static inline int is_new_memtype_allowed(u64 paddr, unsigned long size,
- enum page_cache_mode pcm,
- enum page_cache_mode new_pcm)
+static inline bool is_new_memtype_allowed(u64 paddr, unsigned long size,
+ enum page_cache_mode pcm,
+ enum page_cache_mode new_pcm)
{
/*
* PAT type is always WB for untracked ranges, so no need to check.
*/
if (x86_platform.is_untracked_pat_range(paddr, paddr + size))
- return 1;
+ return true;

/*
* Certain new memtypes are not allowed with certain
@@ -403,10 +403,10 @@ static inline int is_new_memtype_allowed(u64 paddr, unsigned long size,
new_pcm == _PAGE_CACHE_MODE_WB) ||
(pcm == _PAGE_CACHE_MODE_WC &&
new_pcm == _PAGE_CACHE_MODE_WB)) {
- return 0;
+ return false;
}

- return 1;
+ return true;
}

pmd_t *populate_extra_pmd(unsigned long vaddr);
@@ -424,18 +424,18 @@ pte_t *populate_extra_pte(unsigned long vaddr);
#include <linux/mmdebug.h>
#include <linux/log2.h>

-static inline int pte_none(pte_t pte)
+static inline bool pte_none(pte_t pte)
{
return !pte.pte;
}

#define __HAVE_ARCH_PTE_SAME
-static inline int pte_same(pte_t a, pte_t b)
+static inline bool pte_same(pte_t a, pte_t b)
{
return a.pte == b.pte;
}

-static inline int pte_present(pte_t a)
+static inline bool pte_present(pte_t a)
{
return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);
}
@@ -453,12 +453,12 @@ static inline bool pte_accessible(struct mm_struct *mm, pte_t a)
return false;
}

-static inline int pte_hidden(pte_t pte)
+static inline bool pte_hidden(pte_t pte)
{
return pte_flags(pte) & _PAGE_HIDDEN;
}

-static inline int pmd_present(pmd_t pmd)
+static inline bool pmd_present(pmd_t pmd)
{
/*
* Checking for _PAGE_PSE is needed too because
@@ -474,20 +474,20 @@ static inline int pmd_present(pmd_t pmd)
* These work without NUMA balancing but the kernel does not care. See the
* comment in include/asm-generic/pgtable.h
*/
-static inline int pte_protnone(pte_t pte)
+static inline bool pte_protnone(pte_t pte)
{
return (pte_flags(pte) & (_PAGE_PROTNONE | _PAGE_PRESENT))
== _PAGE_PROTNONE;
}

-static inline int pmd_protnone(pmd_t pmd)
+static inline bool pmd_protnone(pmd_t pmd)
{
return (pmd_flags(pmd) & (_PAGE_PROTNONE | _PAGE_PRESENT))
== _PAGE_PROTNONE;
}
#endif /* CONFIG_NUMA_BALANCING */

-static inline int pmd_none(pmd_t pmd)
+static inline bool pmd_none(pmd_t pmd)
{
/* Only check low word on 32-bit platforms, since it might be
out of sync with upper half. */
@@ -541,7 +541,7 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
}

-static inline int pmd_bad(pmd_t pmd)
+static inline bool pmd_bad(pmd_t pmd)
{
return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
}
@@ -552,12 +552,12 @@ static inline unsigned long pages_to_mb(unsigned long npg)
}

#if CONFIG_PGTABLE_LEVELS > 2
-static inline int pud_none(pud_t pud)
+static inline bool pud_none(pud_t pud)
{
return native_pud_val(pud) == 0;
}

-static inline int pud_present(pud_t pud)
+static inline bool pud_present(pud_t pud)
{
return pud_flags(pud) & _PAGE_PRESENT;
}
@@ -579,25 +579,25 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
}

-static inline int pud_large(pud_t pud)
+static inline bool pud_large(pud_t pud)
{
return (pud_val(pud) & (_PAGE_PSE | _PAGE_PRESENT)) ==
(_PAGE_PSE | _PAGE_PRESENT);
}

-static inline int pud_bad(pud_t pud)
+static inline bool pud_bad(pud_t pud)
{
return (pud_flags(pud) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
}
#else
-static inline int pud_large(pud_t pud)
+static inline bool pud_large(pud_t pud)
{
- return 0;
+ return false;
}
#endif /* CONFIG_PGTABLE_LEVELS > 2 */

#if CONFIG_PGTABLE_LEVELS > 3
-static inline int pgd_present(pgd_t pgd)
+static inline bool pgd_present(pgd_t pgd)
{
return pgd_flags(pgd) & _PAGE_PRESENT;
}
@@ -624,12 +624,12 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
return (pud_t *)pgd_page_vaddr(*pgd) + pud_index(address);
}

-static inline int pgd_bad(pgd_t pgd)
+static inline bool pgd_bad(pgd_t pgd)
{
return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
}

-static inline int pgd_none(pgd_t pgd)
+static inline bool pgd_none(pgd_t pgd)
{
return !native_pgd_val(pgd);
}
@@ -724,17 +724,17 @@ static inline void native_set_pmd_at(struct mm_struct *mm, unsigned long addr,
struct vm_area_struct;

#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
-extern int ptep_set_access_flags(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep,
- pte_t entry, int dirty);
+extern bool ptep_set_access_flags(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep,
+ pte_t entry, int dirty);

#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep);
+extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep);

#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-extern int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep);
+extern bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep);

#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
@@ -776,17 +776,17 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
#define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))

#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
-extern int pmdp_set_access_flags(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp,
- pmd_t entry, int dirty);
+extern bool pmdp_set_access_flags(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp,
+ pmd_t entry, int dirty);

#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp);
+extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp);

#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
-extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp);
+extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp);


#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
@@ -794,7 +794,7 @@ extern void pmdp_splitting_flush(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp);

#define __HAVE_ARCH_PMD_WRITE
-static inline int pmd_write(pmd_t pmd)
+static inline bool pmd_write(pmd_t pmd)
{
return pmd_flags(pmd) & _PAGE_RW;
}
@@ -864,7 +864,7 @@ static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
return pte_set_flags(pte, _PAGE_SWP_SOFT_DIRTY);
}

-static inline int pte_swp_soft_dirty(pte_t pte)
+static inline bool pte_swp_soft_dirty(pte_t pte)
{
return pte_flags(pte) & _PAGE_SWP_SOFT_DIRTY;
}
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 0b97d2c75df3..c0cb80953fd5 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -406,11 +406,11 @@ void pgd_free(struct mm_struct *mm, pgd_t *pgd)
* to also make the pte writeable at the same time the dirty bit is
* set. In that case we do actually need to write the PTE.
*/
-int ptep_set_access_flags(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep,
- pte_t entry, int dirty)
+bool ptep_set_access_flags(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep,
+ pte_t entry, int dirty)
{
- int changed = !pte_same(*ptep, entry);
+ bool changed = !pte_same(*ptep, entry);

if (changed && dirty) {
*ptep = entry;
@@ -421,11 +421,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-int pmdp_set_access_flags(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp,
- pmd_t entry, int dirty)
+bool pmdp_set_access_flags(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp,
+ pmd_t entry, int dirty)
{
- int changed = !pmd_same(*pmdp, entry);
+ bool changed = !pmd_same(*pmdp, entry);

VM_BUG_ON(address & ~HPAGE_PMD_MASK);

@@ -444,10 +444,10 @@ int pmdp_set_access_flags(struct vm_area_struct *vma,
}
#endif

-int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep)
+bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep)
{
- int ret = 0;
+ bool ret = false;

if (pte_young(*ptep))
ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
@@ -460,10 +460,10 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp)
+bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp)
{
- int ret = 0;
+ bool ret = 0;

if (pmd_young(*pmdp))
ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
@@ -476,8 +476,8 @@ int pmdp_test_and_clear_young(struct vm_area_struct *vma,
}
#endif

-int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
/*
* On x86 CPUs, clearing the accessed bit without a TLB flush
@@ -496,10 +496,10 @@ int ptep_clear_flush_young(struct vm_area_struct *vma,
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp)
+bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
- int young;
+ bool young;

VM_BUG_ON(address & ~HPAGE_PMD_MASK);

@@ -563,7 +563,7 @@ void native_set_fixmap(enum fixed_addresses idx, phys_addr_t phys,
}

#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
-int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
+bool pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
{
u8 mtrr;

@@ -573,7 +573,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
*/
mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE);
if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != 0xFF))
- return 0;
+ return false;

prot = pgprot_4k_2_large(prot);

@@ -581,10 +581,10 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
(u64)addr >> PAGE_SHIFT,
__pgprot(pgprot_val(prot) | _PAGE_PSE)));

- return 1;
+ return true;
}

-int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
+bool pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
{
u8 mtrr;

@@ -594,7 +594,7 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
*/
mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE);
if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != 0xFF))
- return 0;
+ return false;

prot = pgprot_4k_2_large(prot);

@@ -602,26 +602,26 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
(u64)addr >> PAGE_SHIFT,
__pgprot(pgprot_val(prot) | _PAGE_PSE)));

- return 1;
+ return true;
}

-int pud_clear_huge(pud_t *pud)
+bool pud_clear_huge(pud_t *pud)
{
if (pud_large(*pud)) {
pud_clear(pud);
- return 1;
+ return true;
}

- return 0;
+ return false;
}

-int pmd_clear_huge(pmd_t *pmd)
+bool pmd_clear_huge(pmd_t *pmd)
{
if (pmd_large(*pmd)) {
pmd_clear(pmd);
- return 1;
+ return true;
}

- return 0;
+ return false;
}
#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c
index c6c824356464..0e85e9914d1e 100644
--- a/drivers/staging/lustre/lustre/llite/rw26.c
+++ b/drivers/staging/lustre/lustre/llite/rw26.c
@@ -161,7 +161,7 @@ static int ll_releasepage(struct page *vmpage, RELEASEPAGE_ARG_TYPE gfp_mask)
return result;
}

-static int ll_set_page_dirty(struct page *vmpage)
+static bool ll_set_page_dirty(struct page *vmpage)
{
#if 0
struct cl_page *page = vvp_vmpage_page_transient(vmpage);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 71d5982312f3..243730ae48ea 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -736,7 +736,7 @@ extern int afs_volume_release_fileserver(struct afs_vnode *,
/*
* write.c
*/
-extern int afs_set_page_dirty(struct page *);
+extern bool afs_set_page_dirty(struct page *);
extern void afs_put_writeback(struct afs_writeback *);
extern int afs_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 0714abcd7f32..771d13d6bbd0 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -22,7 +22,7 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb,
/*
* mark a page as having been made dirty and thus needing writeback
*/
-int afs_set_page_dirty(struct page *page)
+bool afs_set_page_dirty(struct page *page)
{
_enter("");
return __set_page_dirty_nobuffers(page);
diff --git a/fs/buffer.c b/fs/buffer.c
index c7a5602d01ee..f101beeff0fa 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -665,9 +665,9 @@ static void __set_page_dirty(struct page *page,
* FIXME: may need to call ->reservepage here as well. That's rather up to the
* address_space though.
*/
-int __set_page_dirty_buffers(struct page *page)
+bool __set_page_dirty_buffers(struct page *page)
{
- int newly_dirty;
+ bool newly_dirty;
struct address_space *mapping = page_mapping(page);

if (unlikely(!mapping))
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index e162bcd105ee..b9e81bb01d71 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -66,13 +66,13 @@ static inline struct ceph_snap_context *page_snap_context(struct page *page)
* Dirty a page. Optimistically adjust accounting, on the assumption
* that we won't race with invalidate. If we do, readjust.
*/
-static int ceph_set_page_dirty(struct page *page)
+static bool ceph_set_page_dirty(struct page *page)
{
struct address_space *mapping = page->mapping;
struct inode *inode;
struct ceph_inode_info *ci;
struct ceph_snap_context *snapc;
- int ret;
+ bool ret;

if (unlikely(!mapping))
return !TestSetPageDirty(page);
@@ -81,7 +81,7 @@ static int ceph_set_page_dirty(struct page *page)
dout("%p set_page_dirty %p idx %lu -- already dirty\n",
mapping->host, page, page->index);
BUG_ON(!PagePrivate(page));
- return 0;
+ return false;
}

inode = mapping->host;
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 2ee2dc4351d1..53bc6c04b2fd 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1925,7 +1925,7 @@ out:
* So what we do is to mark the page "pending dirty" and next time writepage
* is called, propagate that into the buffers appropriately.
*/
-static int ext3_journalled_set_page_dirty(struct page *page)
+static bool ext3_journalled_set_page_dirty(struct page *page)
{
SetPageChecked(page);
return __set_page_dirty_nobuffers(page);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cbd0654a2675..3de08847b02f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3237,7 +3237,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
* So what we do is to mark the page "pending dirty" and next time writepage
* is called, propagate that into the buffers appropriately.
*/
-static int ext4_journalled_set_page_dirty(struct page *page)
+static bool ext4_journalled_set_page_dirty(struct page *page)
{
SetPageChecked(page);
return __set_page_dirty_nobuffers(page);
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 5551fea0afd7..9763c94b8164 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -925,10 +925,10 @@ failed:
* gfs2_set_page_dirty - Page dirtying function
* @page: The page to dirty
*
- * Returns: 1 if it dirtyed the page, or 0 otherwise
+ * Returns: true if it dirtied the page, or false otherwise
*/

-static int gfs2_set_page_dirty(struct page *page)
+static bool gfs2_set_page_dirty(struct page *page)
{
SetPageChecked(page);
return __set_page_dirty_buffers(page);
diff --git a/fs/libfs.c b/fs/libfs.c
index cb1fb4b9b637..60b145368d74 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -1037,9 +1037,9 @@ EXPORT_SYMBOL(kfree_put_link);
* nop .set_page_dirty method so that people can use .page_mkwrite on
* anon inodes.
*/
-static int anon_set_page_dirty(struct page *page)
+static bool anon_set_page_dirty(struct page *page)
{
- return 0;
+ return false;
};

/*
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 39f1d6a2b04d..a9891a6bb075 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -624,7 +624,7 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl,
* version above, is also needed when THP is disabled because the page
* fault can populate the pmd from under us).
*/
-static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
+static inline bool pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
{
pmd_t pmdval = pmd_read_atomic(pmd);
/*
@@ -645,12 +645,12 @@ static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
barrier();
#endif
if (pmd_none(pmdval) || pmd_trans_huge(pmdval))
- return 1;
+ return true;
if (unlikely(pmd_bad(pmdval))) {
pmd_clear_bad(pmd);
- return 1;
+ return true;
}
- return 0;
+ return false;
}

/*
@@ -666,12 +666,12 @@ static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
* become null, but then a page fault can map in a THP and not a
* regular page).
*/
-static inline int pmd_trans_unstable(pmd_t *pmd)
+static inline bool pmd_trans_unstable(pmd_t *pmd)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
return pmd_none_or_trans_huge_or_clear_bad(pmd);
#else
- return 0;
+ return false;
#endif
}

@@ -684,12 +684,12 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
* is the responsibility of the caller to distinguish between PROT_NONE
* protections and NUMA hinting fault protections.
*/
-static inline int pte_protnone(pte_t pte)
+static inline bool pte_protnone(pte_t pte)
{
return 0;
}

-static inline int pmd_protnone(pmd_t pmd)
+static inline bool pmd_protnone(pmd_t pmd)
{
return 0;
}
@@ -698,24 +698,24 @@ static inline int pmd_protnone(pmd_t pmd)
#endif /* CONFIG_MMU */

#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
-int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
-int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
-int pud_clear_huge(pud_t *pud);
-int pmd_clear_huge(pmd_t *pmd);
+bool pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
+bool pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
+bool pud_clear_huge(pud_t *pud);
+bool pmd_clear_huge(pmd_t *pmd);
#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */
-static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
+static inline bool pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
{
return 0;
}
-static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
+static inline bool pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
{
return 0;
}
-static inline int pud_clear_huge(pud_t *pud)
+static inline bool pud_clear_huge(pud_t *pud)
{
return 0;
}
-static inline int pmd_clear_huge(pmd_t *pmd)
+static inline bool pmd_clear_huge(pmd_t *pmd)
{
return 0;
}
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 73b45225a7ca..7ef0881ec8ba 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -90,7 +90,7 @@ static inline void clear_buffer_##name(struct buffer_head *bh) \
{ \
clear_bit(BH_##bit, &(bh)->b_state); \
} \
-static inline int buffer_##name(const struct buffer_head *bh) \
+static inline bool buffer_##name(const struct buffer_head *bh) \
{ \
return test_bit(BH_##bit, &(bh)->b_state); \
}
@@ -99,11 +99,11 @@ static inline int buffer_##name(const struct buffer_head *bh) \
* test_set_buffer_foo() and test_clear_buffer_foo()
*/
#define TAS_BUFFER_FNS(bit, name) \
-static inline int test_set_buffer_##name(struct buffer_head *bh) \
+static inline bool test_set_buffer_##name(struct buffer_head *bh) \
{ \
return test_and_set_bit(BH_##bit, &(bh)->b_state); \
} \
-static inline int test_clear_buffer_##name(struct buffer_head *bh) \
+static inline bool test_clear_buffer_##name(struct buffer_head *bh) \
{ \
return test_and_clear_bit(BH_##bit, &(bh)->b_state); \
} \
@@ -381,7 +381,7 @@ __bread(struct block_device *bdev, sector_t block, unsigned size)
return __bread_gfp(bdev, block, size, __GFP_MOVABLE);
}

-extern int __set_page_dirty_buffers(struct page *page);
+extern bool __set_page_dirty_buffers(struct page *page);

#else /* CONFIG_BLOCK */

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 35ec87e490b1..8171af3cffd1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -371,7 +371,7 @@ struct address_space_operations {
int (*writepages)(struct address_space *, struct writeback_control *);

/* Set a page dirty. Return true if this dirtied it */
- int (*set_page_dirty)(struct page *page);
+ bool (*set_page_dirty)(struct page *page);

int (*readpages)(struct file *filp, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages);
@@ -490,7 +490,7 @@ struct block_device {
#define PAGECACHE_TAG_WRITEBACK 1
#define PAGECACHE_TAG_TOWRITE 2

-int mapping_tagged(struct address_space *mapping, int tag);
+bool mapping_tagged(struct address_space *mapping, int tag);

static inline void i_mmap_lock_write(struct address_space *mapping)
{
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 205026175c42..02f7552a343a 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -255,20 +255,20 @@ struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
struct user_struct **user, int creat_flags,
int page_size_log);

-static inline int is_file_hugepages(struct file *file)
+static inline bool is_file_hugepages(struct file *file)
{
if (file->f_op == &hugetlbfs_file_operations)
- return 1;
+ return true;
if (is_file_shm_hugepages(file))
- return 1;
+ return true;

- return 0;
+ return false;
}


#else /* !CONFIG_HUGETLBFS */

-#define is_file_hugepages(file) 0
+#define is_file_hugepages(file) false
static inline struct file *
hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
struct user_struct **user, int creat_flags,
@@ -442,12 +442,12 @@ static inline pgoff_t basepage_index(struct page *page)

extern void dissolve_free_huge_pages(unsigned long start_pfn,
unsigned long end_pfn);
-static inline int hugepage_migration_supported(struct hstate *h)
+static inline bool hugepage_migration_supported(struct hstate *h)
{
#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
return huge_page_shift(h) == PMD_SHIFT;
#else
- return 0;
+ return false;
#endif
}

@@ -498,7 +498,7 @@ static inline pgoff_t basepage_index(struct page *page)
return page->index;
}
#define dissolve_free_huge_pages(s, e) do {} while (0)
-#define hugepage_migration_supported(h) 0
+#define hugepage_migration_supported(h) false

static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
struct mm_struct *mm, pte_t *pte)
diff --git a/include/linux/hugetlb_inline.h b/include/linux/hugetlb_inline.h
index 2bb681fbeb35..4256d9d95f9a 100644
--- a/include/linux/hugetlb_inline.h
+++ b/include/linux/hugetlb_inline.h
@@ -5,14 +5,14 @@

#include <linux/mm.h>

-static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
+static inline bool is_vm_hugetlb_page(struct vm_area_struct *vma)
{
- return !!(vma->vm_flags & VM_HUGETLB);
+ return vma->vm_flags & VM_HUGETLB;
}

#else

-static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
+static inline bool is_vm_hugetlb_page(struct vm_area_struct *vma)
{
return 0;
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 0755b9fd03a7..69daba13f560 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1207,15 +1207,15 @@ extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
extern void do_invalidatepage(struct page *page, unsigned int offset,
unsigned int length);

-int __set_page_dirty_nobuffers(struct page *page);
-int __set_page_dirty_no_writeback(struct page *page);
-int redirty_page_for_writepage(struct writeback_control *wbc,
+bool __set_page_dirty_nobuffers(struct page *page);
+bool __set_page_dirty_no_writeback(struct page *page);
+bool redirty_page_for_writepage(struct writeback_control *wbc,
struct page *page);
void account_page_dirtied(struct page *page, struct address_space *mapping);
void account_page_cleaned(struct page *page, struct address_space *mapping);
-int set_page_dirty(struct page *page);
-int set_page_dirty_lock(struct page *page);
-int clear_page_dirty_for_io(struct page *page);
+bool set_page_dirty(struct page *page);
+bool set_page_dirty_lock(struct page *page);
+bool clear_page_dirty_for_io(struct page *page);

int get_cmdline(struct task_struct *task, char *buffer, int buflen);

@@ -1351,7 +1351,7 @@ static inline void sync_mm_rss(struct mm_struct *mm)
}
#endif

-int vma_wants_writenotify(struct vm_area_struct *vma);
+bool vma_wants_writenotify(struct vm_area_struct *vma);

extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
spinlock_t **ptl);
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index f34e040b34e9..7601ec9ac2b9 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -138,7 +138,7 @@ enum pageflags {
* Macros to create function definitions for page flags
*/
#define TESTPAGEFLAG(uname, lname) \
-static inline int Page##uname(const struct page *page) \
+static inline bool Page##uname(const struct page *page) \
{ return test_bit(PG_##lname, &page->flags); }

#define SETPAGEFLAG(uname, lname) \
@@ -158,15 +158,15 @@ static inline void __ClearPage##uname(struct page *page) \
{ __clear_bit(PG_##lname, &page->flags); }

#define TESTSETFLAG(uname, lname) \
-static inline int TestSetPage##uname(struct page *page) \
+static inline bool TestSetPage##uname(struct page *page) \
{ return test_and_set_bit(PG_##lname, &page->flags); }

#define TESTCLEARFLAG(uname, lname) \
-static inline int TestClearPage##uname(struct page *page) \
+static inline bool TestClearPage##uname(struct page *page) \
{ return test_and_clear_bit(PG_##lname, &page->flags); }

#define __TESTCLEARFLAG(uname, lname) \
-static inline int __TestClearPage##uname(struct page *page) \
+static inline bool __TestClearPage##uname(struct page *page) \
{ return __test_and_clear_bit(PG_##lname, &page->flags); }

#define PAGEFLAG(uname, lname) TESTPAGEFLAG(uname, lname) \
@@ -179,7 +179,7 @@ static inline int __TestClearPage##uname(struct page *page) \
TESTSETFLAG(uname, lname) TESTCLEARFLAG(uname, lname)

#define TESTPAGEFLAG_FALSE(uname) \
-static inline int Page##uname(const struct page *page) { return 0; }
+static inline bool Page##uname(const struct page *page) { return false; }

#define SETPAGEFLAG_NOOP(uname) \
static inline void SetPage##uname(struct page *page) { }
@@ -191,13 +191,13 @@ static inline void ClearPage##uname(struct page *page) { }
static inline void __ClearPage##uname(struct page *page) { }

#define TESTSETFLAG_FALSE(uname) \
-static inline int TestSetPage##uname(struct page *page) { return 0; }
+static inline bool TestSetPage##uname(struct page *page) { return false; }

#define TESTCLEARFLAG_FALSE(uname) \
-static inline int TestClearPage##uname(struct page *page) { return 0; }
+static inline bool TestClearPage##uname(struct page *page) { return false; }

#define __TESTCLEARFLAG_FALSE(uname) \
-static inline int __TestClearPage##uname(struct page *page) { return 0; }
+static inline bool __TestClearPage##uname(struct page *page) { return false; }

#define PAGEFLAG_FALSE(uname) TESTPAGEFLAG_FALSE(uname) \
SETPAGEFLAG_NOOP(uname) CLEARPAGEFLAG_NOOP(uname)
@@ -309,7 +309,7 @@ PAGEFLAG_FALSE(HWPoison)
#define PAGE_MAPPING_KSM 2
#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM)

-static inline int PageAnon(struct page *page)
+static inline bool PageAnon(struct page *page)
{
return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
}
@@ -321,7 +321,7 @@ static inline int PageAnon(struct page *page)
* is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
* anon_vma, but to that page's node of the stable tree.
*/
-static inline int PageKsm(struct page *page)
+static inline bool PageKsm(struct page *page)
{
return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
(PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
@@ -332,9 +332,9 @@ TESTPAGEFLAG_FALSE(Ksm)

u64 stable_page_flags(struct page *page);

-static inline int PageUptodate(struct page *page)
+static inline bool PageUptodate(struct page *page)
{
- int ret = test_bit(PG_uptodate, &(page)->flags);
+ bool ret = test_bit(PG_uptodate, &(page)->flags);

/*
* Must ensure that the data we read out of the page is loaded
@@ -369,8 +369,8 @@ static inline void SetPageUptodate(struct page *page)

CLEARPAGEFLAG(Uptodate, uptodate)

-int test_clear_page_writeback(struct page *page);
-int __test_set_page_writeback(struct page *page, bool keep_write);
+bool test_clear_page_writeback(struct page *page);
+bool __test_set_page_writeback(struct page *page, bool keep_write);

#define test_set_page_writeback(page) \
__test_set_page_writeback(page, false)
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 33170dbd9db4..a525cb56e6b2 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -298,7 +298,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
unsigned long *first_indexp, unsigned long last_index,
unsigned long nr_to_tag,
unsigned int fromtag, unsigned int totag);
-int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
+bool radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item);

static inline void radix_tree_preload_end(void)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 5efe743ce1e8..dc1bc6337303 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -337,7 +337,7 @@ static inline void __init register_nosave_region_late(unsigned long b, unsigned
{
__register_nosave_region(b, e, 1);
}
-extern int swsusp_page_is_forbidden(struct page *);
+extern bool swsusp_page_is_forbidden(struct page *);
extern void swsusp_set_page_free(struct page *);
extern void swsusp_unset_page_free(struct page *);
extern unsigned long get_safe_page(gfp_t gfp_mask);
diff --git a/include/linux/swap.h b/include/linux/swap.h
index cee108cbe2d5..4e40fda37629 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -376,7 +376,7 @@ extern int swap_writepage(struct page *page, struct writeback_control *wbc);
extern void end_swap_bio_write(struct bio *bio, int err);
extern int __swap_writepage(struct page *page, struct writeback_control *wbc,
void (*end_write_func)(struct bio *, int));
-extern int swap_set_page_dirty(struct page *page);
+extern bool swap_set_page_dirty(struct page *page);
extern void end_swap_bio_read(struct bio *bio, int err);

int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 5235dd4e1e2f..24c36faa8b51 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -38,7 +38,7 @@

#include "power.h"

-static int swsusp_page_is_free(struct page *);
+static bool swsusp_page_is_free(struct page *);
static void swsusp_set_page_forbidden(struct page *);
static void swsusp_unset_page_forbidden(struct page *);

@@ -734,7 +734,7 @@ static void memory_bm_clear_current(struct memory_bitmap *bm)
clear_bit(bit, bm->cur.node->data);
}

-static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
+static bool memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
{
void *addr;
unsigned int bit;
@@ -892,7 +892,7 @@ void swsusp_set_page_free(struct page *page)
memory_bm_set_bit(free_pages_map, page_to_pfn(page));
}

-static int swsusp_page_is_free(struct page *page)
+static bool swsusp_page_is_free(struct page *page)
{
return free_pages_map ?
memory_bm_test_bit(free_pages_map, page_to_pfn(page)) : 0;
@@ -910,7 +910,7 @@ static void swsusp_set_page_forbidden(struct page *page)
memory_bm_set_bit(forbidden_pages_map, page_to_pfn(page));
}

-int swsusp_page_is_forbidden(struct page *page)
+bool swsusp_page_is_forbidden(struct page *page)
{
return forbidden_pages_map ?
memory_bm_test_bit(forbidden_pages_map, page_to_pfn(page)) : 0;
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 3d2aa27b845b..f5c45c13d7f1 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1422,9 +1422,9 @@ EXPORT_SYMBOL(radix_tree_delete);
* @root: radix tree root
* @tag: tag to test
*/
-int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag)
+bool radix_tree_tagged(struct radix_tree_root *root, unsigned int tag)
{
- return root_tag_get(root, tag);
+ return root_tag_get(root, tag) != 0;
}
EXPORT_SYMBOL(radix_tree_tagged);

diff --git a/mm/mmap.c b/mm/mmap.c
index bb50cacc3ea5..8c399caf4e4f 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1476,31 +1476,31 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg)
* to the private version (using protection_map[] without the
* VM_SHARED bit).
*/
-int vma_wants_writenotify(struct vm_area_struct *vma)
+bool vma_wants_writenotify(struct vm_area_struct *vma)
{
vm_flags_t vm_flags = vma->vm_flags;

/* If it was private or non-writable, the write bit is already clear */
if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
- return 0;
+ return false;

/* The backer wishes to know when pages are first written to? */
if (vma->vm_ops && vma->vm_ops->page_mkwrite)
- return 1;
+ return true;

/* The open routine did something to the protections that pgprot_modify
* won't preserve? */
if (pgprot_val(vma->vm_page_prot) !=
pgprot_val(vm_pgprot_modify(vma->vm_page_prot, vm_flags)))
- return 0;
+ return false;

/* Do we need to track softdirty? */
if (IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) && !(vm_flags & VM_SOFTDIRTY))
- return 1;
+ return true;

/* Specialty mapping? */
if (vm_flags & VM_PFNMAP)
- return 0;
+ return false;

/* Can the mapping track the dirty pages? */
return vma->vm_file && vma->vm_file->f_mapping &&
@@ -1511,14 +1511,14 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
* We account for memory if it's a private writeable mapping,
* not hugepages and VM_NORESERVE wasn't set.
*/
-static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags)
+static inline bool accountable_mapping(struct file *file, vm_flags_t vm_flags)
{
/*
* hugetlb has its own accounting separate from the core VM
* VM_HUGETLB may not be set yet so we cannot check for that flag.
*/
if (file && is_file_hugepages(file))
- return 0;
+ return false;

return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE;
}
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 5daf5568b9e1..99081a7cdb33 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2081,11 +2081,11 @@ EXPORT_SYMBOL(write_one_page);
/*
* For address_spaces which do not use buffers nor write back.
*/
-int __set_page_dirty_no_writeback(struct page *page)
+bool __set_page_dirty_no_writeback(struct page *page)
{
if (!PageDirty(page))
return !TestSetPageDirty(page);
- return 0;
+ return false;
}

/*
@@ -2141,14 +2141,14 @@ EXPORT_SYMBOL(account_page_cleaned);
* hold the page lock, but e.g. zap_pte_range() calls with the page mapped and
* the pte lock held, which also locks out truncation.
*/
-int __set_page_dirty_nobuffers(struct page *page)
+bool __set_page_dirty_nobuffers(struct page *page)
{
if (!TestSetPageDirty(page)) {
struct address_space *mapping = page_mapping(page);
unsigned long flags;

if (!mapping)
- return 1;
+ return true;

spin_lock_irqsave(&mapping->tree_lock, flags);
BUG_ON(page_mapping(page) != mapping);
@@ -2161,9 +2161,9 @@ int __set_page_dirty_nobuffers(struct page *page)
/* !PageAnon && !swapper_space */
__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
}
- return 1;
+ return true;
}
- return 0;
+ return false;
}
EXPORT_SYMBOL(__set_page_dirty_nobuffers);

@@ -2190,9 +2190,9 @@ EXPORT_SYMBOL(account_page_redirty);
* page for some reason, it should redirty the locked page via
* redirty_page_for_writepage() and it should then unlock the page and return 0
*/
-int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
+bool redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
{
- int ret;
+ bool ret;

wbc->pages_skipped++;
ret = __set_page_dirty_nobuffers(page);
@@ -2212,12 +2212,12 @@ EXPORT_SYMBOL(redirty_page_for_writepage);
* If the mapping doesn't provide a set_page_dirty a_op, then
* just fall through and assume that it wants buffer_heads.
*/
-int set_page_dirty(struct page *page)
+bool set_page_dirty(struct page *page)
{
struct address_space *mapping = page_mapping(page);

if (likely(mapping)) {
- int (*spd)(struct page *) = mapping->a_ops->set_page_dirty;
+ bool (*spd)(struct page *) = mapping->a_ops->set_page_dirty;
/*
* readahead/lru_deactivate_page could remain
* PG_readahead/PG_reclaim due to race with end_page_writeback
@@ -2238,9 +2238,9 @@ int set_page_dirty(struct page *page)
}
if (!PageDirty(page)) {
if (!TestSetPageDirty(page))
- return 1;
+ return true;
}
- return 0;
+ return false;
}
EXPORT_SYMBOL(set_page_dirty);

@@ -2254,9 +2254,9 @@ EXPORT_SYMBOL(set_page_dirty);
*
* In other cases, the page should be locked before running set_page_dirty().
*/
-int set_page_dirty_lock(struct page *page)
+bool set_page_dirty_lock(struct page *page)
{
- int ret;
+ bool ret;

lock_page(page);
ret = set_page_dirty(page);
@@ -2279,7 +2279,7 @@ EXPORT_SYMBOL(set_page_dirty_lock);
* This incoherency between the page's dirty flag and radix-tree tag is
* unfortunate, but it only exists while the page is locked.
*/
-int clear_page_dirty_for_io(struct page *page)
+bool clear_page_dirty_for_io(struct page *page)
{
struct address_space *mapping = page_mapping(page);

@@ -2325,19 +2325,19 @@ int clear_page_dirty_for_io(struct page *page)
dec_zone_page_state(page, NR_FILE_DIRTY);
dec_bdi_stat(inode_to_bdi(mapping->host),
BDI_RECLAIMABLE);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
return TestClearPageDirty(page);
}
EXPORT_SYMBOL(clear_page_dirty_for_io);

-int test_clear_page_writeback(struct page *page)
+bool test_clear_page_writeback(struct page *page)
{
struct address_space *mapping = page_mapping(page);
struct mem_cgroup *memcg;
- int ret;
+ bool ret;

memcg = mem_cgroup_begin_page_stat(page);
if (mapping) {
@@ -2368,11 +2368,11 @@ int test_clear_page_writeback(struct page *page)
return ret;
}

-int __test_set_page_writeback(struct page *page, bool keep_write)
+bool __test_set_page_writeback(struct page *page, bool keep_write)
{
struct address_space *mapping = page_mapping(page);
struct mem_cgroup *memcg;
- int ret;
+ bool ret;

memcg = mem_cgroup_begin_page_stat(page);
if (mapping) {
@@ -2414,7 +2414,7 @@ EXPORT_SYMBOL(__test_set_page_writeback);
* Return true if any of the pages in the mapping are marked with the
* passed tag.
*/
-int mapping_tagged(struct address_space *mapping, int tag)
+bool mapping_tagged(struct address_space *mapping, int tag)
{
return radix_tree_tagged(&mapping->page_tree, tag);
}
diff --git a/mm/page_io.c b/mm/page_io.c
index 6424869e275e..73034fb7c51b 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -368,7 +368,7 @@ out:
return ret;
}

-int swap_set_page_dirty(struct page *page)
+bool swap_set_page_dirty(struct page *page)
{
struct swap_info_struct *sis = page_swap_info(page);

2015-04-29 19:22:24

by David Howells

[permalink] [raw]
Subject: [PATCH 07/13] Make some apic functions return bool when returning a boolean value

Make some apic functions return bool when returning a boolean value as it
better informs gcc and allows the compiler to make better choices.

Signed-off-by: David Howells <[email protected]>
---

arch/x86/include/asm/apic.h | 22 +++++++++++-----------
arch/x86/kernel/apic/apic_flat_64.c | 2 +-
arch/x86/kernel/apic/apic_noop.c | 2 +-
arch/x86/kernel/setup.c | 2 +-
4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 976b86a325e5..49f99f236784 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -269,8 +269,8 @@ struct apic {

int (*probe)(void);
int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
- int (*apic_id_valid)(int apicid);
- int (*apic_id_registered)(void);
+ bool (*apic_id_valid)(int apicid);
+ bool (*apic_id_registered)(void);

u32 irq_delivery_mode;
u32 irq_dest_mode;
@@ -280,7 +280,7 @@ struct apic {
int disable_esr;

int dest_logical;
- unsigned long (*check_apicid_used)(physid_mask_t *map, int apicid);
+ bool (*check_apicid_used)(physid_mask_t *map, int apicid);

void (*vector_allocation_domain)(int cpu, struct cpumask *retmask,
const struct cpumask *mask);
@@ -291,7 +291,7 @@ struct apic {
void (*setup_apic_routing)(void);
int (*cpu_present_to_apicid)(int mps_cpu);
void (*apicid_to_cpu_present)(int phys_apicid, physid_mask_t *retmap);
- int (*check_phys_apicid_present)(int phys_apicid);
+ bool (*check_phys_apicid_present)(int phys_apicid);
int (*phys_pkg_id)(int cpuid_apic, int index_msb);

unsigned int (*get_apic_id)(unsigned long x);
@@ -465,7 +465,7 @@ extern void apic_send_IPI_self(int vector);
DECLARE_PER_CPU(int, x2apic_extra_bits);

extern int default_cpu_present_to_apicid(int mps_cpu);
-extern int default_check_phys_apicid_present(int phys_apicid);
+extern bool default_check_phys_apicid_present(int phys_apicid);
#endif

extern void generic_bigsmp_probe(void);
@@ -503,7 +503,7 @@ static inline unsigned int read_apic_id(void)
return apic->get_apic_id(reg);
}

-static inline int default_apic_id_valid(int apicid)
+static inline bool default_apic_id_valid(int apicid)
{
return (apicid < 255);
}
@@ -530,7 +530,7 @@ static inline int noop_x86_32_early_logical_apicid(int cpu)
*/
extern void default_init_apic_ldr(void);

-static inline int default_apic_id_registered(void)
+static inline bool default_apic_id_registered(void)
{
return physid_isset(read_apic_id(), phys_cpu_present_map);
}
@@ -588,7 +588,7 @@ default_vector_allocation_domain(int cpu, struct cpumask *retmask,
cpumask_copy(retmask, cpumask_of(cpu));
}

-static inline unsigned long default_check_apicid_used(physid_mask_t *map, int apicid)
+static inline bool default_check_apicid_used(physid_mask_t *map, int apicid)
{
return physid_isset(apicid, *map);
}
@@ -606,7 +606,7 @@ static inline int __default_cpu_present_to_apicid(int mps_cpu)
return BAD_APICID;
}

-static inline int
+static inline bool
__default_check_phys_apicid_present(int phys_apicid)
{
return physid_isset(phys_apicid, phys_cpu_present_map);
@@ -618,14 +618,14 @@ static inline int default_cpu_present_to_apicid(int mps_cpu)
return __default_cpu_present_to_apicid(mps_cpu);
}

-static inline int
+static inline bool
default_check_phys_apicid_present(int phys_apicid)
{
return __default_check_phys_apicid_present(phys_apicid);
}
#else
extern int default_cpu_present_to_apicid(int mps_cpu);
-extern int default_check_phys_apicid_present(int phys_apicid);
+extern bool default_check_phys_apicid_present(int phys_apicid);
#endif

#endif /* CONFIG_X86_LOCAL_APIC */
diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
index de918c410eae..4853d71be324 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -139,7 +139,7 @@ static unsigned int read_xapic_id(void)
return id;
}

-static int flat_apic_id_registered(void)
+static bool flat_apic_id_registered(void)
{
return physid_isset(read_xapic_id(), phys_cpu_present_map);
}
diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
index b205cdbdbe6a..acba7847612a 100644
--- a/arch/x86/kernel/apic/apic_noop.c
+++ b/arch/x86/kernel/apic/apic_noop.c
@@ -72,7 +72,7 @@ static int noop_probe(void)
return 0;
}

-static int noop_apic_id_registered(void)
+static bool noop_apic_id_registered(void)
{
/*
* if we would be really "pedantic"
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d74ac33290ae..c38fdd234716 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -136,7 +136,7 @@ int default_cpu_present_to_apicid(int mps_cpu)
return __default_cpu_present_to_apicid(mps_cpu);
}

-int default_check_phys_apicid_present(int phys_apicid)
+bool default_check_phys_apicid_present(int phys_apicid)
{
return __default_check_phys_apicid_present(phys_apicid);
}

2015-04-29 19:22:31

by David Howells

[permalink] [raw]
Subject: [PATCH 08/13] Make tick functions that return a boolean value return bool

Make tick functions that return a boolean value return bool so that gcc can
make better decisions.

Signed-off-by: David Howells <[email protected]>
---

include/linux/clockchips.h | 6 +++---
kernel/time/tick-broadcast.c | 16 ++++++++--------
kernel/time/tick-internal.h | 6 +++---
3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h
index 96c280b2c263..c98f07b352cc 100644
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -197,9 +197,9 @@ extern int tick_receive_broadcast(void);

# if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
extern void tick_setup_hrtimer_broadcast(void);
-extern int tick_check_broadcast_expired(void);
+extern bool tick_check_broadcast_expired(void);
# else
-static inline int tick_check_broadcast_expired(void) { return 0; }
+static inline bool tick_check_broadcast_expired(void) { return false; }
static inline void tick_setup_hrtimer_broadcast(void) { }
# endif

@@ -210,7 +210,7 @@ extern int clockevents_notify(unsigned long reason, void *arg);
static inline void clockevents_suspend(void) { }
static inline void clockevents_resume(void) { }
static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
-static inline int tick_check_broadcast_expired(void) { return 0; }
+static inline bool tick_check_broadcast_expired(void) { return 0; }
static inline void tick_setup_hrtimer_broadcast(void) { }

#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
index 7e8ca4f448a8..8effac895974 100644
--- a/kernel/time/tick-broadcast.c
+++ b/kernel/time/tick-broadcast.c
@@ -117,7 +117,7 @@ void tick_install_broadcast_device(struct clock_event_device *dev)
/*
* Check, if the device is the broadcast device
*/
-int tick_is_broadcast_device(struct clock_event_device *dev)
+bool tick_is_broadcast_device(struct clock_event_device *dev)
{
return (dev && tick_broadcast_device.evtdev == dev);
}
@@ -155,11 +155,11 @@ static void tick_device_setup_broadcast_func(struct clock_event_device *dev)
* Check, if the device is disfunctional and a place holder, which
* needs to be handled by the broadcast device.
*/
-int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
+bool tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
{
struct clock_event_device *bc = tick_broadcast_device.evtdev;
unsigned long flags;
- int ret;
+ bool ret;

raw_spin_lock_irqsave(&tick_broadcast_lock, flags);

@@ -177,7 +177,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
tick_broadcast_start_periodic(bc);
else
tick_broadcast_setup_oneshot(bc);
- ret = 1;
+ ret = true;
} else {
/*
* Clear the broadcast bit for this cpu if the
@@ -206,7 +206,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
* caller initialize the device.
*/
tick_broadcast_clear_oneshot(cpu);
- ret = 0;
+ ret = false;
break;

case TICKDEV_MODE_PERIODIC:
@@ -227,7 +227,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
break;
default:
/* Nothing to do */
- ret = 0;
+ ret = false;
break;
}
}
@@ -511,7 +511,7 @@ struct cpumask *tick_get_broadcast_oneshot_mask(void)
* to avoid a deep idle transition as we are about to get the
* broadcast IPI right away.
*/
-int tick_check_broadcast_expired(void)
+bool tick_check_broadcast_expired(void)
{
return cpumask_test_cpu(smp_processor_id(), tick_broadcast_force_mask);
}
@@ -934,7 +934,7 @@ void tick_shutdown_broadcast_oneshot(unsigned int cpu)
/*
* Check, whether the broadcast device is in one shot mode
*/
-int tick_broadcast_oneshot_active(void)
+bool tick_broadcast_oneshot_active(void)
{
return tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT;
}
diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h
index b64fdd8054c5..c41e267ae772 100644
--- a/kernel/time/tick-internal.h
+++ b/kernel/time/tick-internal.h
@@ -49,9 +49,9 @@ extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);

/* Broadcasting support */
# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
+extern bool tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
extern void tick_install_broadcast_device(struct clock_event_device *dev);
-extern int tick_is_broadcast_device(struct clock_event_device *dev);
+extern bool tick_is_broadcast_device(struct clock_event_device *dev);
extern void tick_shutdown_broadcast(unsigned int cpu);
extern void tick_suspend_broadcast(void);
extern void tick_resume_broadcast(void);
@@ -118,7 +118,7 @@ static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
extern void tick_broadcast_switch_to_oneshot(void);
extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
-extern int tick_broadcast_oneshot_active(void);
+extern bool tick_broadcast_oneshot_active(void);
extern void tick_check_oneshot_broadcast_this_cpu(void);
bool tick_broadcast_oneshot_available(void);
extern struct cpumask *tick_get_broadcast_oneshot_mask(void);

2015-04-29 19:22:36

by David Howells

[permalink] [raw]
Subject: [PATCH 09/13] input: Use bool and don't use !! on test_bit

Make is_event_supported() return a bool as it returns a boolean value. This
will allow gcc to make better decisions.

Don't use '!!' on test_bit() as test_bit() now returns a bool. This avoids
gcc-5 warnings about using '!' operators on the LHS of a comparison.

Signed-off-by: David Howells <[email protected]>
---

drivers/hid/hid-input.c | 4 ++--
drivers/input/input.c | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 008e89bf6f3c..b470913fdedb 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1157,7 +1157,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
return;

/* report the usage code as scancode if the key status has changed */
- if (usage->type == EV_KEY && !!test_bit(usage->code, input->key) != value)
+ if (usage->type == EV_KEY && test_bit(usage->code, input->key) != value)
input_event(input, EV_MSC, MSC_SCAN, usage->hid);

input_event(input, usage->type, usage->code, value);
@@ -1411,7 +1411,7 @@ static bool hidinput_has_been_populated(struct hid_input *hidinput)
for (i = 0; i < BITS_TO_LONGS(SW_CNT); i++)
r |= hidinput->input->swbit[i];

- return !!r;
+ return r != 0;
}

static void hidinput_cleanup_hidinput(struct hid_device *hid,
diff --git a/drivers/input/input.c b/drivers/input/input.c
index cc357f1516a7..49bf0cadcc6b 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -50,8 +50,8 @@ static DEFINE_MUTEX(input_mutex);

static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };

-static inline int is_event_supported(unsigned int code,
- unsigned long *bm, unsigned int max)
+static inline bool is_event_supported(unsigned int code,
+ unsigned long *bm, unsigned int max)
{
return code <= max && test_bit(code, bm);
}
@@ -294,7 +294,7 @@ static int input_get_disposition(struct input_dev *dev,
break;
}

- if (!!test_bit(code, dev->key) != !!value) {
+ if (test_bit(code, dev->key) != !!value) {

__change_bit(code, dev->key);
disposition = INPUT_PASS_TO_HANDLERS;
@@ -304,7 +304,7 @@ static int input_get_disposition(struct input_dev *dev,

case EV_SW:
if (is_event_supported(code, dev->swbit, SW_MAX) &&
- !!test_bit(code, dev->sw) != !!value) {
+ test_bit(code, dev->sw) != !!value) {

__change_bit(code, dev->sw);
disposition = INPUT_PASS_TO_HANDLERS;
@@ -331,7 +331,7 @@ static int input_get_disposition(struct input_dev *dev,

case EV_LED:
if (is_event_supported(code, dev->ledbit, LED_MAX) &&
- !!test_bit(code, dev->led) != !!value) {
+ test_bit(code, dev->led) != !!value) {

__change_bit(code, dev->led);
disposition = INPUT_PASS_TO_ALL;
@@ -341,7 +341,7 @@ static int input_get_disposition(struct input_dev *dev,
case EV_SND:
if (is_event_supported(code, dev->sndbit, SND_MAX)) {

- if (!!test_bit(code, dev->snd) != !!value)
+ if (test_bit(code, dev->snd) != !!value)
__change_bit(code, dev->snd);
disposition = INPUT_PASS_TO_ALL;
}

2015-04-29 19:22:41

by David Howells

[permalink] [raw]
Subject: [PATCH 10/13] Use bool with jbd2_journal_cancel_revoke()

jbd2_journal_cancel_revoke() should return a bool as it returns a boolean
value only, and should use bool type for a couple of internal variables. This
allows gcc to make better decisions.

Signed-off-by: David Howells <[email protected]>
---

fs/jbd2/revoke.c | 10 +++++-----
include/linux/jbd2.h | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index c6cbaef2bda1..587b4947f0d0 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -417,12 +417,12 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
* do not trust the Revoked bit on buffers unless RevokeValid is also
* set.
*/
-int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
+bool jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
{
struct jbd2_revoke_record_s *record;
journal_t *journal = handle->h_transaction->t_journal;
- int need_cancel;
- int did_revoke = 0; /* akpm: debug */
+ bool need_cancel;
+ int did_revoke = false; /* akpm: debug */
struct buffer_head *bh = jh2bh(jh);

jbd_debug(4, "journal_head %p, cancelling revoke\n", jh);
@@ -434,7 +434,7 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
if (test_set_buffer_revokevalid(bh)) {
need_cancel = test_clear_buffer_revoked(bh);
} else {
- need_cancel = 1;
+ need_cancel = true;
clear_buffer_revoked(bh);
}

@@ -447,7 +447,7 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
list_del(&record->hash);
spin_unlock(&journal->j_revoke_lock);
kmem_cache_free(jbd2_revoke_record_cache, record);
- did_revoke = 1;
+ did_revoke = true;
}
}

diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 20e7f78041c8..716f1d15e83d 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1219,7 +1219,7 @@ extern int jbd2_journal_init_revoke_caches(void);

extern void jbd2_journal_destroy_revoke(journal_t *);
extern int jbd2_journal_revoke (handle_t *, unsigned long long, struct buffer_head *);
-extern int jbd2_journal_cancel_revoke(handle_t *, struct journal_head *);
+extern bool jbd2_journal_cancel_revoke(handle_t *, struct journal_head *);
extern void jbd2_journal_write_revoke_records(journal_t *journal,
transaction_t *transaction,
struct list_head *log_bufs,

2015-04-29 19:22:49

by David Howells

[permalink] [raw]
Subject: [PATCH 11/13] test_taint() should return bool

test_taint() should return bool as it returns a boolean value. This allows
gcc to make better decisions about using the return value, though it might
make test_taint() itself slightly bigger.

Signed-off-by: David Howells <[email protected]>
---

include/linux/kernel.h | 2 +-
kernel/panic.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3a5b48e52a9e..77670ddcd686 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -453,7 +453,7 @@ enum lockdep_ok {
LOCKDEP_NOW_UNRELIABLE
};
extern void add_taint(unsigned flag, enum lockdep_ok);
-extern int test_taint(unsigned flag);
+extern bool test_taint(unsigned flag);
extern unsigned long get_taint(void);
extern int root_mountflags;

diff --git a/kernel/panic.c b/kernel/panic.c
index 8136ad76e5fd..17f056eab21a 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -272,7 +272,7 @@ const char *print_tainted(void)
return buf;
}

-int test_taint(unsigned flag)
+bool test_taint(unsigned flag)
{
return test_bit(flag, &tainted_mask);
}

2015-04-29 19:22:54

by David Howells

[permalink] [raw]
Subject: [PATCH 12/13] netlink: Use bool when returning boolean values

Return bool from netlink functions that return boolean values. This allows
gcc to make better choices.

Note that !! on a bool value is not required and that when adding/subtracting
a bool, it is converted to 0 or 1 as appropriate.

Signed-off-by: David Howells <[email protected]>
---

include/linux/netfilter/nfnetlink.h | 2 +-
include/linux/netlink.h | 2 +-
net/netfilter/nfnetlink.c | 2 +-
net/netlink/af_netlink.c | 21 +++++++++++----------
4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
index e955d4730625..53f7def6b568 100644
--- a/include/linux/netfilter/nfnetlink.h
+++ b/include/linux/netfilter/nfnetlink.h
@@ -33,7 +33,7 @@ struct nfnetlink_subsystem {
int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);

-int nfnetlink_has_listeners(struct net *net, unsigned int group);
+bool nfnetlink_has_listeners(struct net *net, unsigned int group);
struct sk_buff *nfnetlink_alloc_skb(struct net *net, unsigned int size,
u32 dst_portid, gfp_t gfp_mask);
int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 6835c1279df7..ccb535afb707 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -65,7 +65,7 @@ extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);
extern void __netlink_clear_multicast_users(struct sock *sk, unsigned int group);
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
-extern int netlink_has_listeners(struct sock *sk, unsigned int group);
+extern bool netlink_has_listeners(struct sock *sk, unsigned int group);
extern struct sk_buff *netlink_alloc_skb(struct sock *ssk, unsigned int size,
u32 dst_portid, gfp_t gfp_mask);
extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int nonblock);
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 8b117c90ecd7..503a5561ea96 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -116,7 +116,7 @@ nfnetlink_find_client(u_int16_t type, const struct nfnetlink_subsystem *ss)
return &ss->cb[cb_id];
}

-int nfnetlink_has_listeners(struct net *net, unsigned int group)
+bool nfnetlink_has_listeners(struct net *net, unsigned int group)
{
return netlink_has_listeners(net->nfnl, group);
}
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index ec4adbdcb9b4..06d6c91e4d1c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1871,9 +1871,9 @@ out:
}
EXPORT_SYMBOL_GPL(netlink_alloc_skb);

-int netlink_has_listeners(struct sock *sk, unsigned int group)
+bool netlink_has_listeners(struct sock *sk, unsigned int group)
{
- int res = 0;
+ bool res = false;
struct listeners *listeners;

BUG_ON(!netlink_is_kernel(sk));
@@ -2042,10 +2042,10 @@ struct netlink_set_err_data {
int code;
};

-static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
+static bool do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
{
struct netlink_sock *nlk = nlk_sk(sk);
- int ret = 0;
+ bool ret = false;

if (sk == p->exclude_sk)
goto out;
@@ -2058,7 +2058,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
goto out;

if (p->code == ENOBUFS && nlk->flags & NETLINK_RECV_NO_ENOBUFS) {
- ret = 1;
+ ret = true;
goto out;
}

@@ -2103,13 +2103,14 @@ EXPORT_SYMBOL(netlink_set_err);
/* must be called with netlink table grabbed */
static void netlink_update_socket_mc(struct netlink_sock *nlk,
unsigned int group,
- int is_new)
+ bool is_new)
{
- int old, new = !!is_new, subscriptions;
+ bool old;
+ int subscriptions;

old = test_bit(group - 1, nlk->groups);
- subscriptions = nlk->subscriptions - old + new;
- if (new)
+ subscriptions = nlk->subscriptions - old + is_new;
+ if (is_new)
__set_bit(group - 1, nlk->groups);
else
__clear_bit(group - 1, nlk->groups);
@@ -2595,7 +2596,7 @@ void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
struct netlink_table *tbl = &nl_table[ksk->sk_protocol];

sk_for_each_bound(sk, &tbl->mc_list)
- netlink_update_socket_mc(nlk_sk(sk), group, 0);
+ netlink_update_socket_mc(nlk_sk(sk), group, false);
}

struct nlmsghdr *

2015-04-29 19:23:01

by David Howells

[permalink] [raw]
Subject: [PATCH 13/13] Make xfrm functions that return a boolean value return bool

Make xfrm functions that return a boolean value return bool to allow gcc to
make better decisions.

Signed-off-by: David Howells <[email protected]>
---

include/net/xfrm.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 36ac102c97c7..8b2d3683d4e1 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1658,10 +1658,10 @@ static inline int xfrm_policy_id2dir(u32 index)
}

#ifdef CONFIG_XFRM
-static inline int xfrm_aevent_is_on(struct net *net)
+static inline bool xfrm_aevent_is_on(struct net *net)
{
struct sock *nlsk;
- int ret = 0;
+ bool ret = false;

rcu_read_lock();
nlsk = rcu_dereference(net->xfrm.nlsk);
@@ -1671,10 +1671,10 @@ static inline int xfrm_aevent_is_on(struct net *net)
return ret;
}

-static inline int xfrm_acquire_is_on(struct net *net)
+static inline bool xfrm_acquire_is_on(struct net *net)
{
struct sock *nlsk;
- int ret = 0;
+ int ret = false;

rcu_read_lock();
nlsk = rcu_dereference(net->xfrm.nlsk);

2015-12-17 20:38:26

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 01/13] Make the x86 bitops like test_bit() return bool

On Wed, Apr 29, 2015 at 12:21 PM, David Howells <[email protected]> wrote:
> Make the x86 bitop functions like test_bit() return bool rather than an
> integer. This permits gcc-5 to make better choices and can reduce the code
> size overall and allows some warnings to be evaded.

This also would have prevented this regression in -next:

https://lists.01.org/pipermail/linux-nvdimm/2015-December/003557.html