2008-10-04 20:05:33

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/2] drivers/i2c/busses/i2c-s3c2410.c: Correct use of ! and &

From: Julia Lawall <[email protected]>

In commit e6bafba5b4765a5a252f1b8d31cbf6d2459da337, a bug was fixed that
involved converting !x & y to !(x & y). The code below shows the same
pattern, and thus should perhaps be fixed in the same way. In particular,
the result of !readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN is
always 0.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@ expression E; constant C; @@
(
!E & !C
|
- !E & C
+ !(E & C)
)
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/i2c/busses/i2c-s3c2410.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -507,7 +507,7 @@ static int s3c24xx_i2c_doxfer(struct s3c
unsigned long timeout;
int ret;

- if (!readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN)
+ if (!(readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN))
return -EIO;

ret = s3c24xx_i2c_set_master(i2c);


2008-10-06 01:20:58

by M. Asselstine

[permalink] [raw]
Subject: Re: [PATCH 1/2] drivers/i2c/busses/i2c-s3c2410.c: Correct use of ! and &

On Sat, Oct 4, 2008 at 4:05 PM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> In commit e6bafba5b4765a5a252f1b8d31cbf6d2459da337, a bug was fixed that
> involved converting !x & y to !(x & y). The code below shows the same
> pattern, and thus should perhaps be fixed in the same way. In particular,
> the result of !readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN is
> always 0.
>
> The semantic patch that makes this change is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @@ expression E; constant C; @@
> (
> !E & !C
> |
> - !E & C
> + !(E & C)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
Reviewed-by: Mark Asselstine <[email protected]>

Good catch Julia.


>
> ---
> drivers/i2c/busses/i2c-s3c2410.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
> --- a/drivers/i2c/busses/i2c-s3c2410.c
> +++ b/drivers/i2c/busses/i2c-s3c2410.c
> @@ -507,7 +507,7 @@ static int s3c24xx_i2c_doxfer(struct s3c
> unsigned long timeout;
> int ret;
>
> - if (!readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN)
> + if (!(readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN))
> return -EIO;
>
> ret = s3c24xx_i2c_set_master(i2c);
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>