2013-04-16 18:32:05

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

Fixed: warning: cast from pointer to integer of different size

Reported-by: kbuild test robot <[email protected]>
Signed-off-by: Haiyang Zhang <[email protected]>
Reviewed-by: K. Y. Srinivasan <[email protected]>

---
drivers/net/hyperv/netvsc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index f5f0f09..8c03033 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -500,7 +500,7 @@ int netvsc_send(struct hv_device *device,
int ret = 0;
struct nvsp_message sendMessage;
struct net_device *ndev;
- u64 req_id;
+ ulong req_id;

net_device = get_outbound_net_device(device);
if (!net_device)
@@ -522,7 +522,7 @@ int netvsc_send(struct hv_device *device,
sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_size = 0;

if (packet->completion.send.send_completion)
- req_id = (u64)packet;
+ req_id = (ulong)packet;
else
req_id = 0;

--
1.7.4.1


2013-04-16 19:11:47

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

From: Haiyang Zhang <[email protected]>
Date: Tue, 16 Apr 2013 12:03:51 -0700

> Fixed: warning: cast from pointer to integer of different size
>
> Reported-by: kbuild test robot <[email protected]>
> Signed-off-by: Haiyang Zhang <[email protected]>
> Reviewed-by: K. Y. Srinivasan <[email protected]>

If you're coding pointers into request IDs you better make that
explicit and add lots of comments explaining why that's OK and
why it's going to work fine in these circumstances.

I'm not applying this patch, it just makes a bad situation even
worse. Either your request IDs are 64-bit or they are not, it
can't be both.

2013-04-16 19:36:53

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

> -----Original Message-----
> From: David Miller [mailto:[email protected]]
> Sent: Tuesday, April 16, 2013 3:12 PM
> To: Haiyang Zhang
> Cc: [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()
>
> From: Haiyang Zhang <[email protected]>
> Date: Tue, 16 Apr 2013 12:03:51 -0700
>
> > Fixed: warning: cast from pointer to integer of different size
> >
> > Reported-by: kbuild test robot <[email protected]>
> > Signed-off-by: Haiyang Zhang <[email protected]>
> > Reviewed-by: K. Y. Srinivasan <[email protected]>
>
> If you're coding pointers into request IDs you better make that explicit and add lots of comments explaining
> why that's OK and why it's going to work fine in these circumstances.

> I'm not applying this patch, it just makes a bad situation even worse. Either your request IDs are 64-bit or they are not, it can't be both.

The Hyper-V hosts always use 64 bit request id. The guests can have 32 or 64 bit pointers which equal to
the ulong type size. So we cast it to ulong type. And, assigning 32bit integer to 64 bit variable works fine.

Actually, before the recent patch (f1ea3cd7011), the packet pointer was casted to ulong. And this patch
restore the same type casting as the old code.

The VMBus returns the same id in the completion packet. But the value has no effect on the host side.

Does these comments sound good?

Thanks,
- Haiyang

2013-04-16 19:49:17

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

From: Haiyang Zhang <[email protected]>
Date: Tue, 16 Apr 2013 19:34:52 +0000

> The Hyper-V hosts always use 64 bit request id. The guests can have
> 32 or 64 bit pointers which equal to the ulong type size. So we cast
> it to ulong type. And, assigning 32bit integer to 64 bit variable
> works fine.

It works fine, but it's unclean.

Keep the req_id type as "u64", because that's what it is, a 64-bit request ID.

2013-04-16 20:24:11

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

> -----Original Message-----
> From: David Miller [mailto:[email protected]]
> Sent: Tuesday, April 16, 2013 3:49 PM
> To: Haiyang Zhang
> Cc: [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()
>
> From: Haiyang Zhang <[email protected]>
> Date: Tue, 16 Apr 2013 19:34:52 +0000
>
> > The Hyper-V hosts always use 64 bit request id. The guests can have
> > 32 or 64 bit pointers which equal to the ulong type size. So we cast
> > it to ulong type. And, assigning 32bit integer to 64 bit variable
> > works fine.
>
> It works fine, but it's unclean.
>
> Keep the req_id type as "u64", because that's what it is, a 64-bit request ID.

I will make this update and submit a new patch, with the added comments.

Thanks,
- Haiyang

2013-04-16 20:31:08

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

On Tue, 2013-04-16 at 20:18 +0000, Haiyang Zhang wrote:
> > From: David Miller [mailto:[email protected]]
> > It works fine, but it's unclean.
> > Keep the req_id type as "u64", because that's what it is, a 64-bit request ID.
> I will make this update and submit a new patch, with the added comments.

Do you mean you'll use this to avoid compiler warnings?

req_id = (u64)(unsigned long)packet;

2013-04-16 20:46:44

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()

> -----Original Message-----
> From: Joe Perches [mailto:[email protected]]
> Sent: Tuesday, April 16, 2013 4:31 PM
> To: Haiyang Zhang
> Cc: David Miller; [email protected]; KY Srinivasan; [email protected];
> [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH net] hyperv: Fix a compiler warning in netvsc_send()
>
> On Tue, 2013-04-16 at 20:18 +0000, Haiyang Zhang wrote:
> > > From: David Miller [mailto:[email protected]] It works fine, but
> > > it's unclean.
> > > Keep the req_id type as "u64", because that's what it is, a 64-bit request
> ID.
> > I will make this update and submit a new patch, with the added comments.
>
> Do you mean you'll use this to avoid compiler warnings?
>
> req_id = (u64)(unsigned long)packet;

I will use:
req_id = (ulong)packet;

Assigning 32 bit integer to 64 bit variable is fine.

Thanks,
- Haiyang