On 05/28/13 20:55, Jordan Justen wrote:
> I tried to build this with VS2012, but it failed. (I assume it would
> fail with other VS as well.)

Sigh. Probably those deliberate UINT_M = UINT_N assignments where M < N.
I promised that I would pay attention to them, but I must have been
focusing on what I was actually trying to implement, and these
truncations were barely a blip on my radar ("yeah that's safe").

> Do you have the capability to build with VS?

I don't, but I just realized I should be able to catch the above
category with -Wconversion (and by removing -Werror, because
-Wconversion fires for many other parts of edk2):

.../OvmfPkg/VirtioNetDxe/SnpInitialize.c:125: warning: conversion to 'UINT16' 
from 'int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpInitialize.c:146: warning: conversion to 'UINT16' 
from 'int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpInitialize.c:226: warning: conversion to 'UINT16' 
from 'int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpInitialize.c:266: warning: conversion to 'UINT16' 
from 'int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpInitialize.c:270: warning: conversion to 'UINT32' 
from 'long long unsigned int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpReceive.c:161: warning: conversion to 'UINT16' from 
'int' may alter its value
.../OvmfPkg/VirtioNetDxe/SnpReceive.c:174: warning: conversion to 'UINT16' from 
'UINT32' may alter its value

I'll turn these into explicit casts.

... Can you please try the attached patch on top? Does it allow VS to
compile the module? If so I'll fold the patch in v4.


> Do you think anyone with ipxe-virtio or qemu-virtio-net experience
> might have an interest in looking this over?

I'll send an email to qemu-devel, but don't hold your breath :) There's
experience galore there, but time, not so much.

Thanks,
Laszlo
diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c 
b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
index cb49fbc..d577b8b 100644
--- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
+++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
@@ -122,7 +122,8 @@ VirtioNetInitTx (
 {
   UINTN PktIdx;
 
-  Dev->TxMaxPending = MIN (Dev->TxRing.QueueSize / 2, VNET_MAX_PENDING);
+  Dev->TxMaxPending = (UINT16) MIN (Dev->TxRing.QueueSize / 2,
+                                 VNET_MAX_PENDING);
   Dev->TxCurPending = 0;
   Dev->TxFreeStack  = AllocatePool (Dev->TxMaxPending *
                         sizeof *Dev->TxFreeStack);
@@ -143,7 +144,7 @@ VirtioNetInitTx (
     Dev->TxRing.Desc[DescIdx].Addr  = (UINTN) &Dev->TxSharedReq;
     Dev->TxRing.Desc[DescIdx].Len   = sizeof Dev->TxSharedReq;
     Dev->TxRing.Desc[DescIdx].Flags = VRING_DESC_F_NEXT;
-    Dev->TxRing.Desc[DescIdx].Next  = DescIdx + 1;
+    Dev->TxRing.Desc[DescIdx].Next  = (UINT16) (DescIdx + 1);
 
     //
     // The second descriptor of each pending TX packet is updated on the fly,
@@ -223,7 +224,7 @@ VirtioNetInitRx (
   // Limit the number of pending RX packets if the queue is big. The division
   // by two is due to the above "two descriptors per packet" trait.
   //
-  RxAlwaysPending = MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PENDING);
+  RxAlwaysPending = (UINT16) MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PENDING);
 
   Dev->RxBuf = AllocatePool (RxAlwaysPending * RxBufSize);
   if (Dev->RxBuf == NULL) {
@@ -263,11 +264,12 @@ VirtioNetInitRx (
     Dev->RxRing.Desc[DescIdx].Addr  = (UINTN) RxPtr;
     Dev->RxRing.Desc[DescIdx].Len   = sizeof (VIRTIO_NET_REQ);
     Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE | VRING_DESC_F_NEXT;
-    Dev->RxRing.Desc[DescIdx].Next  = DescIdx + 1;
+    Dev->RxRing.Desc[DescIdx].Next  = (UINT16) (DescIdx + 1);
     RxPtr += Dev->RxRing.Desc[DescIdx++].Len;
 
     Dev->RxRing.Desc[DescIdx].Addr  = (UINTN) RxPtr;
-    Dev->RxRing.Desc[DescIdx].Len   = RxBufSize - sizeof (VIRTIO_NET_REQ);
+    Dev->RxRing.Desc[DescIdx].Len   = (UINT32) (RxBufSize -
+                                                sizeof (VIRTIO_NET_REQ));
     Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE;
     RxPtr += Dev->RxRing.Desc[DescIdx++].Len;
   }
diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c 
b/OvmfPkg/VirtioNetDxe/SnpReceive.c
index c7d733b..c9461f9 100644
--- a/OvmfPkg/VirtioNetDxe/SnpReceive.c
+++ b/OvmfPkg/VirtioNetDxe/SnpReceive.c
@@ -158,7 +158,7 @@ VirtioNetReceive (
   RxPtr += SIZE_OF_VNET (VhdrMac);
 
   if (Protocol != NULL) {
-    *Protocol = ((UINT16) RxPtr[0] << 8) | RxPtr[1];
+    *Protocol = (UINT16) ((RxPtr[0] << 8) | RxPtr[1]);
   }
   RxPtr += sizeof (UINT16);
 
@@ -171,7 +171,8 @@ RecycleDesc:
   // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device
   //
   AvailIdx = *Dev->RxRing.Avail.Idx;
-  Dev->RxRing.Avail.Ring[AvailIdx++ % Dev->RxRing.QueueSize] = DescIdx;
+  Dev->RxRing.Avail.Ring[AvailIdx++ % Dev->RxRing.QueueSize] =
+    (UINT16) DescIdx;
 
   MemoryFence ();
   *Dev->RxRing.Avail.Idx = AvailIdx;
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to