> On 17 Feb 2019, at 08:57, Mathias Kresin <d...@kresin.me> wrote: > > 08/02/2019 09:23, Petr Cvek: >> Hello, >> There is a wrong code in 0025-NET-MIPS-lantiq-adds-xrx200-net.patch [1], the >> original code: >> + link->rx_flow = !!(xrx200sw_read_x(XRX200_MAC_CTRL_0_FCON, port) && >> 0x0010); >> + link->tx_flow = !!(xrx200sw_read_x(XRX200_MAC_CTRL_0_FCON, port) && >> 0x0020); >> wants to mask the register value and is using a logical AND and not a >> bitwise AND. >> The fix should be: >> + link->rx_flow = !!(xrx200sw_read_x(XRX200_MAC_CTRL_0_FCON, port) & >> 0x0010); >> + link->tx_flow = !!(xrx200sw_read_x(XRX200_MAC_CTRL_0_FCON, port) & >> 0x0020); >> References: >> [1] >> https://github.com/openwrt/openwrt/blob/master/target/linux/lantiq/patches-4.14/0025-NET-MIPS-lantiq-adds-xrx200-net.patch#L937 >> > > Hey Petr, > > it looks indeed wrong. And looking more closer at the lines, I don't get why > we need the double negation.
Having seen this code structure before, it’s a non-obvious way of turning a masked and hence value based true/false into a binary 0 or 1 result: Exhibit A moronic demo c programme: #include <stdio.h> int main() { printf("%d\n", 5 & 4); printf("%d\n", (5 & 4)); printf("%d\n", !(5 & 4)); printf("%d\n", !!(5 & 4)); } Results in: 4 4 0 1 Cheers, Kevin D-B 012C ACB2 28C6 C53E 9775 9123 B3A2 389B 9DE2 334A _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel