diff options
author | Mike Maslenkin <mike.maslenkin@gmail.com> | 2023-08-26 04:57:59 +0300 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-10-16 22:49:33 +0000 |
commit | e07948255cfafb75fa9cbe4555bfe3421488dd9a (patch) | |
tree | 0d99fec699fdc184399453839f4de0514f6307f6 /MdeModulePkg | |
parent | 326b9e1d815c4ae4b0b207fcb0bfa16864af5400 (diff) | |
download | edk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.zip edk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.tar.gz edk2-e07948255cfafb75fa9cbe4555bfe3421488dd9a.tar.bz2 |
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')
5 files changed, 7 insertions, 5 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c index daa30f0..62df4e9 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 63003e0..29f4508 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 2a2454f..baa2225 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 b363223..2c0dcae 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);
diff --git a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h b/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h index 800945d..7b9896a 100644 --- a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h +++ b/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h @@ -42,6 +42,8 @@ typedef struct _EDKII_USB_ETHERNET_PROTOCOL EDKII_USB_ETHERNET_PROTOCOL; #define NETWORK_CONNECTED 0x01
#define NETWORK_DISCONNECT 0x00
+#define MAC_FILTERS_MASK 0x7FFF
+
// USB Header functional Descriptor
typedef struct {
UINT8 FunctionLength;
|