Re: [PATCH 2/9] drivers/acpi/asus_acpi.c: Correct use of ! and &
From: Julia Lawall
Date: Wed Feb 27 2008 - 12:41:45 EST
On Wed, 27 Feb 2008, Karol Kozimor wrote:
> On 26-02-2008, at 21:42, Julia Lawall wrote:
> > if (invert) /* invert target value */
> > - led_out = !led_out & 0x1;
> > + led_out = !(led_out & 0x1);
> >
> > if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
> > printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
>
>
> IIRC we're just supposed to flip the last bit here, so the original
> code is correct.
I spent some time thinking about this one. The original code is ok if
led_out is always either 0x01 or 0x00. But what if it is eg 0xc0? Then
the negation amounts to the negation of a nonzero number, so the result is
0. So the result of the bit and is 0. So the last bit is not flipped.
But I don't know what is the range of led_out. If it is always 1 or 0,
then why bother with the bit and?
julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/