Re: [PATCH 2/2] serial: cascade needless conditionals

From: André Goddard Rosa
Date: Sun Oct 25 2009 - 12:38:03 EST


Hi, Henrique!

On 10/25/09, Henrique de Moraes Holschuh <hmh@xxxxxxxxxx> wrote:
> On Sun, 25 Oct 2009, André Goddard Rosa wrote:
>> if (flags == UPF_SPD_HI)
>> altbaud = 57600;
>> - if (flags == UPF_SPD_VHI)
>> + else if (flags == UPF_SPD_VHI)
>> altbaud = 115200;
>> - if (flags == UPF_SPD_SHI)
>> + else if (flags == UPF_SPD_SHI)
>> altbaud = 230400;
>> - if (flags == UPF_SPD_WARP)
>> + else if (flags == UPF_SPD_WARP)
>> altbaud = 460800;
>
> This changes code behaviour if more than one bit is set (which might never
> happen for all I know...). You should invert the order of the tests if you
> want to make sure it is side-effect-free.
>

Do you mind explaining why? Notice that it's not (var & flag), it's =='.
Can flags be equal more than one flag at the same time?

Thanks,
André
--
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/