summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Bus
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
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')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c4
4 files changed, 5 insertions, 5 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c
index daa30f0815..62df4e92ea 100644
--- a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c
+++ b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c
@@ -829,7 +829,7 @@ SetFilter (
}
Nic->UsbEth->UsbEthFunDescriptor (Nic->UsbEth, &UsbEthFunDescriptor);
- if ((UsbEthFunDescriptor.NumberMcFilters << 1) == 0) {
+ if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
Nic->RxFilter |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST;
Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);
} else {
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;
}
diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c
index 2a2454f466..baa2225bf8 100644
--- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c
+++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c
@@ -714,7 +714,7 @@ SetUsbEthMcastFilter (
return Status;
}
- if ((UsbEthFunDescriptor.NumberMcFilters << 1) == 0) {
+ if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
return EFI_UNSUPPORTED;
}
diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c
index b3632233ad..2c0dcae4cf 100644
--- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c
+++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c
@@ -661,7 +661,7 @@ SetUsbRndisMcastFilter (
return Status;
}
- if ((UsbEthFunDescriptor.NumberMcFilters << 1) == 0) {
+ if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
return EFI_UNSUPPORTED;
}
@@ -856,7 +856,7 @@ RndisUndiReceiveFilter (
}
Nic->UsbEth->UsbEthFunDescriptor (Nic->UsbEth, &UsbEthFunDescriptor);
- if ((UsbEthFunDescriptor.NumberMcFilters << 1) == 0) {
+ if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
Nic->RxFilter |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST;
DEBUG ((DEBUG_INFO, "SetUsbEthPacketFilter Nic %lx Nic->UsbEth %lx ", Nic, Nic->UsbEth));
Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);