net: stmmac: do not use a bitwise AND operator with a bool operand
Subsystems (4)
PATCH 1/1 net: stmmac: do not use a bitwise AND operator with a bool operand
Doing a bitwise AND between a bool and an int is generally not a good idea. The bool will be promoted to an int with value 0 or 1,
the int is generally regarded as true with a non-zero value, thus ANDing them has the potential to yield an undesired result.
This commit fixes the following smatch warnings:
drivers/net/ethernet/stmicro/stmmac/enh_desc.c:344 enh_desc_prepare_tx_desc() warn: maybe use && instead of & drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c:337 dwmac4_rd_prepare_tx_desc() warn: maybe use && instead of & drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c:380 dwmac4_rd_prepare_tso_tx_desc() warn: maybe use && instead of &
--- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/enh_desc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +2 -2
@@ -334,7 +334,7 @@ static void dwmac4_rd_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,if (tx_own) tdes3 |=TDES3_OWN ; -if (is_fs & tx_own) +if (is_fs && tx_own)/* When the own bit, for the first frame, has to be set, all * descriptors for the same frame has to be set before, to * avoid race condition.
@@ -377,7 +377,7 @@ static void dwmac4_rd_prepare_tso_tx_desc(struct dma_desc *p, int is_fs,if (tx_own) tdes3 |=TDES3_OWN ; -if (is_fs & tx_own) +if (is_fs && tx_own)/* When the own bit, for the first frame, has to be set, all * descriptors for the same frame has to be set before, to * avoid race condition.
drivers/net/ethernet/stmicro/stmmac/enh_desc.c +1 -1
@@ -341,7 +341,7 @@ static void enh_desc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,if (tx_own) tdes0 |=ETDES0_OWN ; -if (is_fs & tx_own) +if (is_fs && tx_own)/* When the own bit, for the first frame, has to be set, all * descriptors for the same frame has to be set before, to * avoid race condition.
Signature · 1 line
2.14.2
From: Niklas Cassel <[email protected]>
Date: Mon, 22 Jan 2018 16:59:50 +0100
Quoted 5 lines
Doing a bitwise AND between a bool and an int is generally not a good idea. The bool will be promoted to an int with value 0 or 1,
the int is generally regarded as true with a non-zero value, thus ANDing them has the potential to yield an undesired result.
Quoted 7 lines
This commit fixes the following smatch warnings:
drivers/net/ethernet/stmicro/stmmac/enh_desc.c:344enh_desc_prepare_tx_desc()warn: maybe use && instead of &drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c:337dwmac4_rd_prepare_tx_desc()warn: maybe use && instead of &drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c:380dwmac4_rd_prepare_tso_tx_desc()warn: maybe use && instead of &Signed-off-by Niklas Cassel <[email protected]>
Applied.