From f44de78e76db84be52ca3e77b903be159ddd3ac5 Mon Sep 17 00:00:00 2001 From: jianzhou Date: Wed, 20 Mar 2019 17:35:26 +0800 Subject: QcomModulePkg: Return pointer instead of structure in GetFastbootDeviceData There is stack smashing issue when return the whole structure in GetFastbootDeviceData. Return pointer instead of the whole structure to make compiler easy refer to stack usage. Change-Id: Ia4893e8b2a712fa340afdc85772876a390f2e3dd --- QcomModulePkg/Library/FastbootLib/FastbootCmds.c | 32 ++++++++++++------------ QcomModulePkg/Library/FastbootLib/FastbootMain.c | 6 ++--- QcomModulePkg/Library/FastbootLib/FastbootMain.h | 4 +-- 3 files changed, 21 insertions(+), 21 deletions(-) mode change 100644 => 100755 QcomModulePkg/Library/FastbootLib/FastbootCmds.c mode change 100644 => 100755 QcomModulePkg/Library/FastbootLib/FastbootMain.c mode change 100644 => 100755 QcomModulePkg/Library/FastbootLib/FastbootMain.h diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c old mode 100644 new mode 100755 index 04b8fae2a4..07bcb85327 --- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c +++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c @@ -272,14 +272,14 @@ FastbootAck (IN CONST CHAR8 *code, CONST CHAR8 *Reason) if (Reason == NULL) Reason = ""; - AsciiSPrint (GetFastbootDeviceData ().gTxBuffer, MAX_RSP_SIZE, "%a%a", code, + AsciiSPrint (GetFastbootDeviceData ()->gTxBuffer, MAX_RSP_SIZE, "%a%a", code, Reason); - GetFastbootDeviceData ().UsbDeviceProtocol->Send ( - ENDPOINT_OUT, AsciiStrLen (GetFastbootDeviceData ().gTxBuffer), - GetFastbootDeviceData ().gTxBuffer); + GetFastbootDeviceData ()->UsbDeviceProtocol->Send ( + ENDPOINT_OUT, AsciiStrLen (GetFastbootDeviceData ()->gTxBuffer), + GetFastbootDeviceData ()->gTxBuffer); DEBUG ((EFI_D_VERBOSE, "Sending %d:%a\n", - AsciiStrLen (GetFastbootDeviceData ().gTxBuffer), - GetFastbootDeviceData ().gTxBuffer)); + AsciiStrLen (GetFastbootDeviceData ()->gTxBuffer), + GetFastbootDeviceData ()->gTxBuffer)); } VOID @@ -1315,14 +1315,14 @@ CmdDownload (IN CONST CHAR8 *arg, IN VOID *data, IN UINT32 sz) AsciiStrnCpyS (Response + InitStrLen, sizeof (Response) - InitStrLen, NumBytesString, AsciiStrLen (NumBytesString)); - gBS->CopyMem (GetFastbootDeviceData ().gTxBuffer, Response, + gBS->CopyMem (GetFastbootDeviceData ()->gTxBuffer, Response, sizeof (Response)); mState = ExpectDataState; mBytesReceivedSoFar = 0; - GetFastbootDeviceData ().UsbDeviceProtocol->Send ( - ENDPOINT_OUT, sizeof (Response), GetFastbootDeviceData ().gTxBuffer); + GetFastbootDeviceData ()->UsbDeviceProtocol->Send ( + ENDPOINT_OUT, sizeof (Response), GetFastbootDeviceData ()->gTxBuffer); DEBUG ((EFI_D_VERBOSE, "CmdDownload: Send 12 %a\n", - GetFastbootDeviceData ().gTxBuffer)); + GetFastbootDeviceData ()->gTxBuffer)); } #ifdef ENABLE_UPDATE_PARTITIONS_CMDS @@ -2009,7 +2009,7 @@ AcceptData (IN UINT64 Size, IN VOID *Data) FastbootOkayDelay (); mState = ExpectCmdState; } else { - GetFastbootDeviceData ().UsbDeviceProtocol->Send ( + GetFastbootDeviceData ()->UsbDeviceProtocol->Send ( ENDPOINT_IN, GetXfrSize (), (Data + mBytesReceivedSoFar)); DEBUG ((EFI_D_VERBOSE, "AcceptData: Send %d\n", GetXfrSize ())); } @@ -2053,7 +2053,7 @@ FastbootCmdsUnInit (VOID) EFI_STATUS Status; if (mDataBuffer) { - Status = GetFastbootDeviceData ().UsbDeviceProtocol->FreeTransferBuffer ( + Status = GetFastbootDeviceData ()->UsbDeviceProtocol->FreeTransferBuffer ( (VOID *)mDataBuffer); if (Status != EFI_SUCCESS) { DEBUG ((EFI_D_ERROR, "Failed to free up fastboot buffer\n")); @@ -2061,7 +2061,7 @@ FastbootCmdsUnInit (VOID) } } FastbootUnInit (); - GetFastbootDeviceData ().UsbDeviceProtocol->Stop (); + GetFastbootDeviceData ()->UsbDeviceProtocol->Stop (); return EFI_SUCCESS; } @@ -2199,7 +2199,7 @@ FastbootCmdsInit (VOID) } Status = - GetFastbootDeviceData ().UsbDeviceProtocol->AllocateTransferBuffer ( + GetFastbootDeviceData ()->UsbDeviceProtocol->AllocateTransferBuffer ( MaxDownLoadSize, (VOID **)&FastBootBuffer); }while (EFI_ERROR (Status)); @@ -2342,8 +2342,8 @@ STATIC VOID WaitForTransferComplete (VOID) /* Wait for the transfer to complete */ while (1) { - GetFastbootDeviceData ().UsbDeviceProtocol->HandleEvent (&Msg, &PayloadSize, - &Payload); + GetFastbootDeviceData ()->UsbDeviceProtocol->HandleEvent (&Msg, + &PayloadSize, &Payload); if (UsbDeviceEventTransferNotification == Msg) { if (1 == USB_INDEX_TO_EP (Payload.TransferOutcome.EndpointIndex)) { if (USB_ENDPOINT_DIRECTION_IN == diff --git a/QcomModulePkg/Library/FastbootLib/FastbootMain.c b/QcomModulePkg/Library/FastbootLib/FastbootMain.c old mode 100644 new mode 100755 index edb583fa01..4ba53545d0 --- a/QcomModulePkg/Library/FastbootLib/FastbootMain.c +++ b/QcomModulePkg/Library/FastbootLib/FastbootMain.c @@ -14,7 +14,7 @@ found at **/ -/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. +/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -112,9 +112,9 @@ struct { } }; -FastbootDeviceData GetFastbootDeviceData (VOID) +FastbootDeviceData *GetFastbootDeviceData (VOID) { - return Fbd; + return &Fbd; } /* Dummy function needed for event notification callback */ diff --git a/QcomModulePkg/Library/FastbootLib/FastbootMain.h b/QcomModulePkg/Library/FastbootLib/FastbootMain.h old mode 100644 new mode 100755 index e6085413ce..c528a50505 --- a/QcomModulePkg/Library/FastbootLib/FastbootMain.h +++ b/QcomModulePkg/Library/FastbootLib/FastbootMain.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015,2017 The Linux Foundation. All rights reserved. + * Copyright (c) 2015,2017,2019 The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -52,7 +52,7 @@ typedef struct FasbootDevice { VOID *gTxBuffer; } FastbootDeviceData; -FastbootDeviceData GetFastbootDeviceData (VOID); +FastbootDeviceData *GetFastbootDeviceData (VOID); EFI_STATUS HandleUsbEvents (VOID); EFI_STATUS FastbootUsbDeviceStop (VOID); EFI_STATUS FastbootInitialize (VOID); -- cgit v1.2.3