From e07948255cfafb75fa9cbe4555bfe3421488dd9a Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sat, 26 Aug 2023 04:57:59 +0300 Subject: 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 Cc: Rebecca Cran Signed-off-by: Mike Maslenkin --- MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'MdeModulePkg/Include/Protocol') 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; -- cgit v1.1