]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
fix k8 warning.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiMisc.c
index 3a727099e4502099cfb14f93d3209f6c14d3f0f4..9eff1850bee6cab19d582cbed068fc7772b78548 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -94,7 +94,7 @@ IScsiGetSubnetMaskPrefixLength (
   //\r
   ReverseMask = ~ReverseMask;\r
 \r
-  if ((ReverseMask != 0) & ((ReverseMask + 1) != 0)) {\r
+  if ((ReverseMask & (ReverseMask + 1)) != 0) {\r
     return 0;\r
   }\r
 \r
@@ -123,55 +123,64 @@ IScsiAsciiStrToLun (
   OUT UINT8  *Lun\r
   )\r
 {\r
-  UINT32  Index;\r
-  CHAR8   *LunUnitStr[4];\r
-  CHAR8   Digit;\r
-  UINTN   Temp;\r
-\r
+  UINTN   Index, IndexValue, IndexNum, SizeStr;\r
+  CHAR8   TemStr[2];\r
+  UINT8   TemValue;\r
+  UINT16  Value [4];\r
+  \r
   ZeroMem (Lun, 8);\r
-  ZeroMem (LunUnitStr, sizeof (LunUnitStr));\r
-\r
-  Index         = 0;\r
-  LunUnitStr[0] = Str;\r
-\r
-  if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  while (*Str != '\0') {\r
-    //\r
-    // Legal representations of LUN:\r
-    //   4752-3A4F-6b7e-2F99,\r
-    //   6734-9-156f-127,\r
-    //   4186-9\r
-    //\r
-    if (*Str == '-') {\r
-      *Str = '\0';\r
-      Index++;\r
-\r
-      if (*(Str + 1) != '\0') {\r
-        if (!IsHexDigit ((UINT8 *) &Digit, *(Str + 1))) {\r
-          return EFI_INVALID_PARAMETER;\r
-        }\r
-\r
-        LunUnitStr[Index] = Str + 1;\r
+  ZeroMem (TemStr, 2);\r
+  ZeroMem ((UINT8 *) Value, sizeof (Value));\r
+  SizeStr    = AsciiStrLen (Str);  \r
+  IndexValue = 0;\r
+  IndexNum   = 0;\r
+\r
+  for (Index = 0; Index < SizeStr; Index ++) {\r
+    TemStr[0] = Str[Index];\r
+    TemValue = (UINT8) AsciiStrHexToUint64 (TemStr);\r
+    if (TemValue == 0 && TemStr[0] != '0') {\r
+      if ((TemStr[0] != '-') || (IndexNum == 0)) {\r
+        //\r
+        // Invalid Lun Char\r
+        //\r
+        return EFI_INVALID_PARAMETER;\r
       }\r
-    } else if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {\r
-      return EFI_INVALID_PARAMETER;\r
     }\r
-\r
-    Str++;\r
-  }\r
-\r
-  for (Index = 0; (Index < 4) && (LunUnitStr[Index] != NULL); Index++) {\r
-    if (AsciiStrLen (LunUnitStr[Index]) > 4) {\r
+    \r
+    if ((TemValue == 0) && (TemStr[0] == '-')) {\r
+      //\r
+      // Next Lun value\r
+      //\r
+      if (++IndexValue >= 4) {\r
+        //\r
+        // Max 4 Lun value\r
+        //\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      //\r
+      // Restart str index for the next lun value\r
+      //\r
+      IndexNum = 0;\r
+      continue;\r
+    }\r
+    \r
+    if (++IndexNum > 4) {\r
+      //     \r
+      // Each Lun Str can't exceed size 4, because it will be as UINT16 value\r
+      //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-\r
-    Temp = AsciiStrHexToUintn (LunUnitStr[Index]);\r
-    *((UINT16 *) &Lun[Index * 2]) = HTONS (Temp);\r
+    \r
+    //\r
+    // Combine UINT16 value\r
+    //\r
+    Value[IndexValue] = (UINT16) ((Value[IndexValue] << 4) + TemValue);\r
   }\r
-\r
\r
+  for (Index = 0; Index <= IndexValue; Index ++) {\r
+    *((UINT16 *) &Lun[Index * 2]) =  HTONS (Value[Index]);\r
+  }\r
+  \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -434,52 +443,38 @@ IScsiHexToBin (
   )\r
 {\r
   UINTN   Index;\r
-  UINT32  HexCount;\r
-  CHAR8   *HexBuf;\r
+  UINTN   Length;\r
   UINT8   Digit;\r
-  UINT8   Byte;\r
-\r
-  Digit = 0;\r
+  CHAR8   TemStr[2];\r
+  \r
+  ZeroMem (TemStr, sizeof (TemStr));\r
 \r
   //\r
   // Find out how many hex characters the string has.\r
   //\r
-  HexBuf = HexStr;\r
-  if ((HexBuf[0] == '0') && ((HexBuf[1] == 'x') || (HexBuf[1] == 'X'))) {\r
-    HexBuf += 2;\r
-  }\r
-\r
-  for (Index = 0, HexCount = 0; IsHexDigit (&Digit, HexBuf[Index]); Index++, HexCount++)\r
-    ;\r
-\r
-  if (HexCount == 0) {\r
-    *BinLength = 0;\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Test if buffer is passed enough.\r
-  //\r
-  if (((HexCount + 1) / 2) > *BinLength) {\r
-    *BinLength = (HexCount + 1) / 2;\r
-    return EFI_BUFFER_TOO_SMALL;\r
+  if ((HexStr[0] == '0') && ((HexStr[1] == 'x') || (HexStr[1] == 'X'))) {\r
+    HexStr += 2;\r
   }\r
+  \r
+  Length = AsciiStrLen (HexStr);\r
 \r
-  *BinLength = (HexCount + 1) / 2;\r
-\r
-  for (Index = 0; Index < HexCount; Index++) {\r
-\r
-    IsHexDigit (&Digit, HexBuf[HexCount - 1 - Index]);\r
-\r
+  for (Index = 0; Index < Length; Index ++) {\r
+    TemStr[0] = HexStr[Index];\r
+    Digit = (UINT8) AsciiStrHexToUint64 (TemStr);\r
+    if (Digit == 0 && TemStr[0] != '0') {\r
+      //\r
+      // Invalid Lun Char\r
+      //\r
+      break;\r
+    }\r
     if ((Index & 1) == 0) {\r
-      Byte = Digit;\r
+      BinBuffer [Index/2] = Digit;\r
     } else {\r
-      Byte = BinBuffer[*BinLength - 1 - Index / 2];\r
-      Byte &= 0x0F;\r
-      Byte = (UINT8) (Byte | (Digit << 4));\r
+      BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);\r
     }\r
-\r
-    BinBuffer[*BinLength - 1 - Index / 2] = Byte;\r
   }\r
+  \r
+  *BinLength = (UINT32) ((Index + 1)/2);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -749,6 +744,9 @@ IScsiGetTcpConnDevicePath (
   // Duplicate it.\r
   //\r
   DevicePath  = DuplicateDevicePath (DevicePath);\r
+  if (DevicePath == NULL) {\r
+    return NULL;\r
+  }\r
 \r
   DPathNode   = (EFI_DEV_PATH *) DevicePath;\r
 \r