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

From: Henrique de Moraes Holschuh
Date: Sun Oct 25 2009 - 12:20:39 EST


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.

--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh
--
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/