All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Converting int usage to bool
@ 2014-11-27 10:41 ` Quentin Lambert
  0 siblings, 0 replies; 4+ messages in thread
From: Quentin Lambert @ 2014-11-27 10:41 UTC (permalink / raw)
  To: Thomas Winischhofer
  Cc: Jean-Christophe Plagniol-Villard, Tomi Valkeinen, linux-fbdev,
	linux-kernel

The following semantic patch was used to find
functions and variables declared as int but
used as boolean. The patch resulted in a
significant number of false positive that I
have ignored.

I am not hyper confident about the modification
I made to the functions. Some of them seem to
have quite significant side effects, which is not
necesserarily intended from a boolean function.
In particular both *_rwtest functions write data.
Moreover sisfb_find_host_bridge name may suggest
more than a boolean return.

/* 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;
local idexpression int x;
identifier xname;
expression e;
position p;
@@

f@p(...) {
...when any
(
  x@xname = 1;
|
  x@xname = 0;
|
  x@xname = (e) ? 0 : 1;
|
  x@xname = (e) ? 1 : 0;
|
  x@xname = fbool(...);
)
...when any
}

/* match all acceptable complex assignement */
@valid_assign exists@
identifier eligible_var.f, boolean_function.fbool;
local idexpression int eligible_var.x;
expression e;
position p;
@@

f(...) {
...when any
(
  x@p = (e) ? 0 : 1;
|
  x@p = (e) ? 1 : 0;
|
  x@p = fbool(...);
)
...when any
}

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

f(...) {
...when any
(
  x@p = e1;
|
  x++
|
  ++x
|
  x--
|
  --x
|
  x + e2
|
  x - e2
|
  e2 - x
|
  x & e2
|
  x * e2
|
  x / e2
|
  e2 / x
)
...when any
}

/* match all return statement involving an eligible variable */
@valid_var_return depends on !badvar1 exists@
identifier eligible_var.f;
local idexpression int eligible_var.x;
position p;
@@

f(...) {
...when any
  return x@p;
}

/* match all function eligible for boolean conversion */
/* do not match function returning only boolean variable different from the one considered */
@eligible_func exists@
identifier f;
local idexpression int x;
position valid_var_return.p;
@@

int f(...) {
...when any
(
  return 1;
|
  return 0;
|
  return x@p;
)
}

/* match functions returning something else than a bool */
@badfunc1 exists@
identifier eligible_func.f;
expression e != {0, 1};
position p != valid_var_return.p;
@@

int
f(...) {
...when any
  return e@p;
}

/* satisfied when eligible_var is variable of eligible_func */
@same_function depends on eligible_var exists@
identifier eligible_func.f;
position eligible_var.p;
@@

int
f@p(...) {
...
}

/* match variable being returned as well as other non boolean variable */
@badvar2 depends on badfunc1 && same_function exists@
local idexpression int eligible_var.x;
identifier eligible_func.f;
@@

int
f(...) {
...when any
  return x;
}

@depends on (!eligible_func || eligible_func && !same_function) && !badvar1@
identifier eligible_var.f;
local idexpression int eligible_var.x;
identifier eligible_var.xname;
expression e;
@@


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

}

@depends on eligible_func && same_function && !badvar1 && !badvar2@
identifier eligible_func.f;
local idexpression int eligible_var.x;
identifier eligible_var.xname;
expression e;
@@


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

}

@depends on !badfunc1@
identifier eligible_func.f;
@@

- int
+ bool
f(...) {
<...
(
- return 1;
+ return true;
|
- return 0;
+ return false;
)
...>
}

Quentin Lambert (1):
  video: fbdev: sis: sis_main.c: converting relevant int to bool

 drivers/video/fbdev/sis/sis_main.c | 64 ++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

-- 
1.9.1


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

* [PATCH] Converting int usage to bool
@ 2014-11-27 10:41 ` Quentin Lambert
  0 siblings, 0 replies; 4+ messages in thread
From: Quentin Lambert @ 2014-11-27 10:41 UTC (permalink / raw)
  To: Thomas Winischhofer
  Cc: Jean-Christophe Plagniol-Villard, Tomi Valkeinen, linux-fbdev,
	linux-kernel

The following semantic patch was used to find
functions and variables declared as int but
used as boolean. The patch resulted in a
significant number of false positive that I
have ignored.

I am not hyper confident about the modification
I made to the functions. Some of them seem to
have quite significant side effects, which is not
necesserarily intended from a boolean function.
In particular both *_rwtest functions write data.
Moreover sisfb_find_host_bridge name may suggest
more than a boolean return.

/* 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;
local idexpression int x;
identifier xname;
expression e;
position p;
@@

f@p(...) {
...when any
(
  x@xname = 1;
|
  x@xname = 0;
|
  x@xname = (e) ? 0 : 1;
|
  x@xname = (e) ? 1 : 0;
|
  x@xname = fbool(...);
)
...when any
}

/* match all acceptable complex assignement */
@valid_assign exists@
identifier eligible_var.f, boolean_function.fbool;
local idexpression int eligible_var.x;
expression e;
position p;
@@

f(...) {
...when any
(
  x@p = (e) ? 0 : 1;
|
  x@p = (e) ? 1 : 0;
|
  x@p = fbool(...);
)
...when any
}

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

f(...) {
...when any
(
  x@p = e1;
|
  x++
|
  ++x
|
  x--
|
  --x
|
  x + e2
|
  x - e2
|
  e2 - x
|
  x & e2
|
  x * e2
|
  x / e2
|
  e2 / x
)
...when any
}

/* match all return statement involving an eligible variable */
@valid_var_return depends on !badvar1 exists@
identifier eligible_var.f;
local idexpression int eligible_var.x;
position p;
@@

f(...) {
...when any
  return x@p;
}

/* match all function eligible for boolean conversion */
/* do not match function returning only boolean variable different from the one considered */
@eligible_func exists@
identifier f;
local idexpression int x;
position valid_var_return.p;
@@

int f(...) {
...when any
(
  return 1;
|
  return 0;
|
  return x@p;
)
}

/* match functions returning something else than a bool */
@badfunc1 exists@
identifier eligible_func.f;
expression e != {0, 1};
position p != valid_var_return.p;
@@

int
f(...) {
...when any
  return e@p;
}

/* satisfied when eligible_var is variable of eligible_func */
@same_function depends on eligible_var exists@
identifier eligible_func.f;
position eligible_var.p;
@@

int
f@p(...) {
...
}

/* match variable being returned as well as other non boolean variable */
@badvar2 depends on badfunc1 && same_function exists@
local idexpression int eligible_var.x;
identifier eligible_func.f;
@@

int
f(...) {
...when any
  return x;
}

@depends on (!eligible_func || eligible_func && !same_function) && !badvar1@
identifier eligible_var.f;
local idexpression int eligible_var.x;
identifier eligible_var.xname;
expression e;
@@


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

}

@depends on eligible_func && same_function && !badvar1 && !badvar2@
identifier eligible_func.f;
local idexpression int eligible_var.x;
identifier eligible_var.xname;
expression e;
@@


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

}

@depends on !badfunc1@
identifier eligible_func.f;
@@

- int
+ bool
f(...) {
<...
(
- return 1;
+ return true;
|
- return 0;
+ return false;
)
...>
}

Quentin Lambert (1):
  video: fbdev: sis: sis_main.c: converting relevant int to bool

 drivers/video/fbdev/sis/sis_main.c | 64 ++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

-- 
1.9.1


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

* Re: [PATCH] Converting int usage to bool
  2014-11-27 10:41 ` Quentin Lambert
@ 2014-12-03 11:53   ` Tomi Valkeinen
  -1 siblings, 0 replies; 4+ messages in thread
From: Tomi Valkeinen @ 2014-12-03 11:53 UTC (permalink / raw)
  To: Quentin Lambert, Thomas Winischhofer
  Cc: Jean-Christophe Plagniol-Villard, linux-fbdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

On 27/11/14 12:41, Quentin Lambert wrote:
> The following semantic patch was used to find
> functions and variables declared as int but
> used as boolean. The patch resulted in a
> significant number of false positive that I
> have ignored.
> 
> I am not hyper confident about the modification
> I made to the functions. Some of them seem to
> have quite significant side effects, which is not
> necesserarily intended from a boolean function.
> In particular both *_rwtest functions write data.
> Moreover sisfb_find_host_bridge name may suggest
> more than a boolean return.

I don't think I'm going to apply based on the above. I do like bools
where a boolean value is used, but changing it like this to a single
fbdev driver.. Well, I don't really see much benefit in this patch, and
there's a possibility for regressions.

 Tomi



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] Converting int usage to bool
@ 2014-12-03 11:53   ` Tomi Valkeinen
  0 siblings, 0 replies; 4+ messages in thread
From: Tomi Valkeinen @ 2014-12-03 11:53 UTC (permalink / raw)
  To: Quentin Lambert, Thomas Winischhofer
  Cc: Jean-Christophe Plagniol-Villard, linux-fbdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

On 27/11/14 12:41, Quentin Lambert wrote:
> The following semantic patch was used to find
> functions and variables declared as int but
> used as boolean. The patch resulted in a
> significant number of false positive that I
> have ignored.
> 
> I am not hyper confident about the modification
> I made to the functions. Some of them seem to
> have quite significant side effects, which is not
> necesserarily intended from a boolean function.
> In particular both *_rwtest functions write data.
> Moreover sisfb_find_host_bridge name may suggest
> more than a boolean return.

I don't think I'm going to apply based on the above. I do like bools
where a boolean value is used, but changing it like this to a single
fbdev driver.. Well, I don't really see much benefit in this patch, and
there's a possibility for regressions.

 Tomi



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2014-12-03 11:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-27 10:41 [PATCH] Converting int usage to bool Quentin Lambert
2014-11-27 10:41 ` Quentin Lambert
2014-12-03 11:53 ` Tomi Valkeinen
2014-12-03 11:53   ` Tomi Valkeinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.