[PATCH 0/1] int to bool conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch converts local variable declared as integer and used as
boolean into actual booleans. It only patches variables that are not
returned to limit the scope of the changes.

This patch was generated with Coccinelle using the semantic patch below.


Quentin Lambert (1):
  [SCSI] mpt2sas: Convert non-returned local variable to boolean when
    relevant

 drivers/scsi/mpt2sas/mpt2sas_base.c      | 24 ++++++++++++------------
 drivers/scsi/mpt2sas/mpt2sas_config.c    |  5 +++--
 drivers/scsi/mpt2sas/mpt2sas_ctl.c       | 22 +++++++++++-----------
 drivers/scsi/mpt2sas/mpt2sas_scsih.c     | 17 ++++++++---------
 drivers/scsi/mpt2sas/mpt2sas_transport.c | 27 ++++++++++++++-------------
 5 files changed, 48 insertions(+), 47 deletions(-)

-- 


/* match all explicit boolean functions */
@boolean_function@
identifier fbool;
typedef bool;
@@

bool fbool(...) {
...
}

/* match variables eligible for boolean conversion */
@eligible_var exists@
identifier f, boolean_function.fbool;
typedef u1, u2, u4, u8, u16, u32;
local idexpression {int, u8, u1, u2, u4, u16, u32, char} x;
identifier xname;
expression e1, e2;
position p;
@@


f@p(...) {
...when any
(
  x@xname = 1;
|
  x@xname = 0;
|
  x@xname = (e1) ? 0 : 1;
|
  x@xname = (e2) ? 1 : 0;
|
  x@xname = fbool(...);
|
  x@xname = fbool(...);
|
  x@xname = e1 && ...
|
  x@xname = e1 || ...
|
  x@xname = e1 == e2
|
  x@xname = e1 != e2
|
  x@xname = e1 < e2
|
  x@xname = e1 <= e2
|
  x@xname = e1 > e2
|
  x@xname = e1 >= e2
)
...when any
}

/* match all acceptable complex assignement */
@valid_assign exists@
identifier eligible_var.f, boolean_function.fbool;
local idexpression {int, u8, u1, u2, u4, u16, u32, char} eligible_var.x;
expression e1, e2;
position p;
@@

f(...) {
...when any
(
  x@p = (e1) ? 0 : 1;
|
  x@p = (e1) ? 1 : 0;
|
  x@p = fbool(...);
|
  x@p = e1 && ...
|
  x@p = e1 || ...
|
  x@p = e1 == e2
|
  x@p = e1 != e2
|
  x@p = e1 < e2
|
  x@p = e1 <= e2
|
  x@p = e1 > e2
|
  x@p = e1 >= e2
)
...when any
}

/* match any expression where x is used as an int */
@badvar1 exists@
identifier eligible_var.f;
local idexpression {int, u8, u1, u2, u4, u16, u32, char} eligible_var.x;
expression e1 != {0, 1}, e2;
position p != {valid_assign.p};
@@

f(...) {
...when any
(
  x@p = e1;
|
  x += e2
|
  e2 += x
|
  x *= e2
|
  e2 *= x
|
  x -= e2
|
  e2 -= x
|
  x /= e2
|
  e2 /= x
|
  e2 %= x
|
  x %= e2
|
  x &= e2
|
  e2 &= x
|
  x |= e2
|
  e2 |= x
|
  x ^= e2
|
  e2 ^= x
|
  x <<= e2
|
  e2 <<= x  
|
  x >>= e2
|
  e2 >>= x  
|
  x++
|
  ++x
|
  x--
|
  --x
|
  x + e2
|
  x - e2
|
  e2 - x
|
  x & e2
|
  x | e2
|
  x * e2
|
  x / e2
|
  e2 / x
|
  x % e2
|
  e2 % x
|
  ~x
|
  e2 ^ x
|
  x ^ e2
|
  x << e2
|
  e2 << x
|
  x >> e2
|
  e2 >> x
|
  return x;
)
...when any
}



@depends on !badvar1@
identifier eligible_var.f;
local idexpression {int, u8, u1, u2, u4, u16, u32, char} eligible_var.x;
identifier eligible_var.xname;
type t;
expression e;
@@


f(...) {
...
(
++ bool xname = false;
- t xname = 0;
|
++ bool xname = true;
- t xname = 1;
|
++ bool xname;
- t xname;
)
<...
(
  x =
- 1
+ true
|
  x =
- 0
+ false
|
- x = (e) ? 1 : 0
+ x = (e) ? true : false
|
- x = (e) ? 0 : 1
+ x = (e) ? false : true
)
...>

}
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux