From 8c45e9db6f5425f66aa57fc3ac33b6803fdf307c Mon Sep 17 00:00:00 2001 From: leonidk Date: Mon, 10 Apr 2006 09:33:56 +0000 Subject: [PATCH] [MTHCA] 1. Fixed an error in sanity check. 2. Fixed an error in event logging git-svn-id: svn://openib.tc.cornell.edu/gen1@298 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/hw/mthca/kernel/mthca_log.c | 26 +++++++++++++++----------- trunk/hw/mthca/kernel/mthca_main.c | 7 ++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/trunk/hw/mthca/kernel/mthca_log.c b/trunk/hw/mthca/kernel/mthca_log.c index 46825ff5..52024600 100644 --- a/trunk/hw/mthca/kernel/mthca_log.c +++ b/trunk/hw/mthca/kernel/mthca_log.c @@ -162,18 +162,20 @@ Return Value: PIO_ERROR_LOG_PACKET l_pErrorLogEntry; /* sizeof insertion string */ int l_Size = (int)((pi_InsertionStr) ? ((wcslen(pi_InsertionStr) + 1) * sizeof( WCHAR )) : 0); - + int l_PktSize =sizeof(IO_ERROR_LOG_PACKET)+pi_nDataItems*sizeof(ULONG); + int l_TotalSize =l_PktSize +l_Size; + /* Init the variable argument list */ va_start(l_Argptr, pi_nDataItems); - /* Allocate an error log entry */ - l_pErrorLogEntry = - (PIO_ERROR_LOG_PACKET)IoAllocateErrorLogEntry( - pi_pIoObject, - (UCHAR)(sizeof(IO_ERROR_LOG_PACKET)+pi_nDataItems*sizeof(ULONG)+l_Size) - ); - /* Check allocation */ - if ( l_pErrorLogEntry != NULL) + /* Allocate an error log entry */ + if (l_TotalSize >= ERROR_LOG_MAXIMUM_SIZE - 2) + l_TotalSize = ERROR_LOG_MAXIMUM_SIZE - 2; + l_pErrorLogEntry = (PIO_ERROR_LOG_PACKET)IoAllocateErrorLogEntry( + pi_pIoObject, (UCHAR)l_TotalSize ); + + /* Check allocation */ + if ( l_pErrorLogEntry != NULL) { /* OK */ /* Data item index */ @@ -206,11 +208,13 @@ Return Value: /* add insertion string */ if (pi_InsertionStr) { - char *ptr; + char *ptr; + int sz = min( l_TotalSize - l_PktSize, l_Size ); l_pErrorLogEntry->NumberOfStrings = 1; l_pErrorLogEntry->StringOffset = sizeof(IO_ERROR_LOG_PACKET) + l_pErrorLogEntry->DumpDataSize; ptr = (char*)l_pErrorLogEntry + l_pErrorLogEntry->StringOffset; - memcpy( ptr, pi_InsertionStr, l_Size ); + memcpy( ptr, pi_InsertionStr, sz ); + *(WCHAR*)&ptr[sz - 2] = (WCHAR)0; } /* Write the packet */ diff --git a/trunk/hw/mthca/kernel/mthca_main.c b/trunk/hw/mthca/kernel/mthca_main.c index 936d14ba..9ee75845 100644 --- a/trunk/hw/mthca/kernel/mthca_main.c +++ b/trunk/hw/mthca/kernel/mthca_main.c @@ -175,10 +175,11 @@ static int mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim) return -ENODEV; } - if (dev_lim->uar_size > (int)pci_resource_len(mdev, 2)) { + if (dev_lim->uar_size > (int)pci_resource_len(mdev, HCA_BAR_TYPE_UAR)) { HCA_PRINT_EV(TRACE_LEVEL_ERROR ,HCA_DBG_LOW , ("HCA reported UAR size of 0x%x bigger than " - "PCI resource 2 size of 0x%lx, aborting.\n", - dev_lim->uar_size, (unsigned long)pci_resource_len(mdev, 2))); + "Bar%d size of 0x%lx, aborting.\n", + dev_lim->uar_size, HCA_BAR_TYPE_UAR, + (unsigned long)pci_resource_len(mdev, HCA_BAR_TYPE_UAR))); return -ENODEV; } -- 2.41.0