summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c
diff options
context:
space:
mode:
authorMike Maslenkin <mike.maslenkin@gmail.com>2023-08-26 04:57:59 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-16 22:49:33 +0000
commite07948255cfafb75fa9cbe4555bfe3421488dd9a (patch)
tree0d99fec699fdc184399453839f4de0514f6307f6 /MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c
parent326b9e1d815c4ae4b0b207fcb0bfa16864af5400 (diff)
downloadedk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.tar.gz
edk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.tar.bz2
edk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.zip
MdeModulePkg: UsbNetwork: fix Ethernet functional descriptor processing
This patch fixes wrong condition because of UINT16 value to integer promotion. NumberMcFilters is UINT16 value, so when bitwise shift operator applied to small integer type, the operation is preceded by integral promotion. This is described in MISRA-C:2004 guideline as Rule 10.5: "If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand." A simple fix for this issue would be the following: if ((UINT16)(UsbEthFunDescriptor.NumberMcFilters << 1) == 0) But this patch proposes to use bitwise AND operation with a proper bit mask rather than shifting to prevent similar mistakes in future. Cc: Richard Ho <richardho@ami.com> Cc: Rebecca Cran <rebecca@bsdio.com> Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
Diffstat (limited to 'MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c
index 63003e07ff..29f4508a38 100644
--- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c
+++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c
@@ -628,7 +628,7 @@ SetUsbEthMcastFilter (
return Status;
}
- if ((UsbEthFunDescriptor.NumberMcFilters << 1) == 0) {
+ if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
return EFI_UNSUPPORTED;
}