]> git.baikalelectronics.ru Git - kernel.git/commit
wifi: rtw89: use u32_encode_bits() to fill MAC quota value
authorPing-Ke Shih <pkshih@realtek.com>
Tue, 8 Nov 2022 01:38:58 +0000 (09:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:09 +0000 (13:32 +0100)
commit572e44c64eb845263fecf2cd7f39dffb69586865
treed443e7d76d1702a0f9ce41c18ca25f79ff9f7dc6
parent51a41bef24ba011e418beb07a1cc1cc60eb63463
wifi: rtw89: use u32_encode_bits() to fill MAC quota value

[ Upstream commit 20c9c8a1af95324e14b09719152d6bd2428ff9bc ]

Coverity reported shift 16 bits could cause sign extension and might get
an unexpected value. Since the input values are predefined and no this
kind of case, original code is safe so far. But, still changing them to
use u32_encode_bits() will be more clear and prevent mistakes in the
future.

The original message of Coverity is:
  Suspicious implicit sign extension: "max_cfg->cma0_dma" with type "u16"
  (16 bits, unsigned) is promoted in "max_cfg->cma0_dma << 16" to type
  "int" (32 bits, signed), then sign-extended to type "unsigned long"
  (64 bits, unsigned).  If "max_cfg->cma0_dma << 16" is greater than
  0x7FFFFFFF, the upper bits of the result will all be 1."

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527095 ("Integer handling issues")
Fixes: 9c5adf19c17c ("rtw89: add Realtek 802.11ax driver")
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20221108013858.10806-1-pkshih@realtek.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireless/realtek/rtw89/mac.c