Re: [edk2] [patch] MdeModulePkg/UsbKbDxe: don't assert when the key read is invalid
On 2016/4/13 15:13, Feng Tian wrote: The GetKeyDescriptor() may return NULL when the KeyData is invalid. For such case, we should go to error handling path rather than assert Cc: Star ZengContributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Feng Tian Reviewed-by: Star Zeng --- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index 86dd99d..fef1449 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -1,7 +1,7 @@ /** @file Helper functions for USB Keyboard Driver. -Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved. +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1195,7 +1195,9 @@ KeyboardHandler ( // Handle repeat key // KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]); - ASSERT (KeyDescriptor != NULL); + if (KeyDescriptor == NULL) { +continue; + } if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) { // @@ -1272,8 +1274,9 @@ USBParseKey ( Dequeue (>UsbKeyQueue, , sizeof (UsbKey)); KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode); -ASSERT (KeyDescriptor != NULL); - +if (KeyDescriptor == NULL) { + continue; +} if (!UsbKey.Down) { // // Key is released. @@ -1513,7 +1516,9 @@ UsbKeyCodeToEfiInputKey ( // KeyCode must in the range of [0x4, 0x65] or [0xe0, 0xe7]. // KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode); - ASSERT (KeyDescriptor != NULL); + if (KeyDescriptor == NULL) { +return EFI_DEVICE_ERROR; + } if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) { // ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [patch] MdeModulePkg/UsbKbDxe: don't assert when the key read is invalid
The GetKeyDescriptor() may return NULL when the KeyData is invalid. For such case, we should go to error handling path rather than assert Cc: Star ZengContributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Feng Tian --- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index 86dd99d..fef1449 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -1,7 +1,7 @@ /** @file Helper functions for USB Keyboard Driver. -Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved. +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1195,7 +1195,9 @@ KeyboardHandler ( // Handle repeat key // KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]); - ASSERT (KeyDescriptor != NULL); + if (KeyDescriptor == NULL) { +continue; + } if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) { // @@ -1272,8 +1274,9 @@ USBParseKey ( Dequeue (>UsbKeyQueue, , sizeof (UsbKey)); KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode); -ASSERT (KeyDescriptor != NULL); - +if (KeyDescriptor == NULL) { + continue; +} if (!UsbKey.Down) { // // Key is released. @@ -1513,7 +1516,9 @@ UsbKeyCodeToEfiInputKey ( // KeyCode must in the range of [0x4, 0x65] or [0xe0, 0xe7]. // KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode); - ASSERT (KeyDescriptor != NULL); + if (KeyDescriptor == NULL) { +return EFI_DEVICE_ERROR; + } if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) { // -- 2.7.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel