2009-07-29 12:14:44

by Nicolas Palix

[permalink] [raw]
Subject: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)


Fix compilation warning by casting the const void *Buffer
variable into a void *.

Signed-off-by: Nicolas Palix <[email protected]>
---
drivers/staging/hv/Channel.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
index 68f3442..854fa30 100644
--- a/drivers/staging/hv/Channel.c
+++ b/drivers/staging/hv/Channel.c
@@ -787,7 +787,7 @@ VmbusChannelSendPacket(
bufferList[0].Data = &desc;
bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);

- bufferList[1].Data = Buffer;
+ bufferList[1].Data = (void *)Buffer;
bufferList[1].Length = BufferLen;

bufferList[2].Data = &alignedData;
--
1.6.0.4


--
Nicolas Palix


2009-07-29 13:03:38

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)

On Wed, 2009-07-29 at 14:10 +0200, Nicolas Palix wrote:
> Fix compilation warning by casting the const void *Buffer
> variable into a void *.
> diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
> index 68f3442..854fa30 100644
> --- a/drivers/staging/hv/Channel.c
> +++ b/drivers/staging/hv/Channel.c
> @@ -787,7 +787,7 @@ VmbusChannelSendPacket(
> bufferList[0].Data = &desc;
> bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
>
> - bufferList[1].Data = Buffer;
> + bufferList[1].Data = (void *)Buffer;
> bufferList[1].Length = BufferLen;

Perhaps this is better?

diff --git a/drivers/staging/hv/RingBuffer.c b/drivers/staging/hv/RingBuffer.c
index 6a9f568..fa40f46 100644
--- a/drivers/staging/hv/RingBuffer.c
+++ b/drivers/staging/hv/RingBuffer.c
@@ -228,7 +228,7 @@ static u32
CopyToRingBuffer(
RING_BUFFER_INFO *RingInfo,
u32 StartWriteOffset,
- void * Src,
+ const void * Src,
u32 SrcLen);

static u32
@@ -559,7 +559,7 @@ u32
CopyToRingBuffer(
RING_BUFFER_INFO *RingInfo,
u32 StartWriteOffset,
- void * Src,
+ const void * Src,
u32 SrcLen)
{
void * ringBuffer=GetRingBuffer(RingInfo);
diff --git a/drivers/staging/hv/RingBuffer.h b/drivers/staging/hv/RingBuffer.h
index a0b6e0e..4cea2af 100644
--- a/drivers/staging/hv/RingBuffer.h
+++ b/drivers/staging/hv/RingBuffer.h
@@ -28,7 +28,7 @@
#include "include/osd.h"

typedef struct _SG_BUFFER_LIST {
- void * Data;
+ const void *Data;
u32 Length;
} SG_BUFFER_LIST;


2009-07-29 13:08:32

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)

On Wednesday 29 July 2009, Nicolas Palix wrote:
> Fix compilation warning by casting the const void *Buffer
> variable into a void *.
>
> Signed-off-by: Nicolas Palix <[email protected]>

Not sure if this one is worthwhile. Replacing SG_BUFFER_LIST
with the existing struct scatterlist might be a better
fix, as sg_set_buf() does not generate a warning like this
anyway.

Arnd <><

2009-07-29 13:13:16

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)

On Wed, Jul 29, 2009 at 02:10:28PM +0200, Nicolas Palix wrote:
>
> Fix compilation warning by casting the const void *Buffer
> variable into a void *.
>
> Signed-off-by: Nicolas Palix <[email protected]>
> ---
> drivers/staging/hv/Channel.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
> index 68f3442..854fa30 100644
> --- a/drivers/staging/hv/Channel.c
> +++ b/drivers/staging/hv/Channel.c
> @@ -787,7 +787,7 @@ VmbusChannelSendPacket(
> bufferList[0].Data = &desc;
> bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
>
> - bufferList[1].Data = Buffer;
> + bufferList[1].Data = (void *)Buffer;

Yeah, I thought about doing this as well, but it's wrong. If this
buffer really isn't being modified, then the Data pointer needs to be
const.

Or, if the Data pointer really is going to not be const, then the
function parameters need to be changed, but that means lots of code
needs to be changed.

Hank, what do you think is the correct thing to do here?

thanks,

greg k-h

2009-07-29 13:21:40

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)

On Wed, Jul 29, 2009 at 03:08:24PM +0200, Arnd Bergmann wrote:
> On Wednesday 29 July 2009, Nicolas Palix wrote:
> > Fix compilation warning by casting the const void *Buffer
> > variable into a void *.
> >
> > Signed-off-by: Nicolas Palix <[email protected]>
>
> Not sure if this one is worthwhile. Replacing SG_BUFFER_LIST
> with the existing struct scatterlist might be a better
> fix, as sg_set_buf() does not generate a warning like this
> anyway.

Yes, that's the correct fix to make. That should be done instead.

thanks,

greg k-h

2009-07-29 20:13:59

by Hank Janssen

[permalink] [raw]
Subject: RE: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)


>On Wed, Jul 29, 2009 at 02:10:28PM +0200, Nicolas Palix wrote:
>>
>> Fix compilation warning by casting the const void *Buffer
>> variable into a void *.
>>
>>>
[....]
>> Signed-off-by: Nicolas Palix <[email protected]>
>> ---
>> drivers/staging/hv/Channel.c | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
>> index 68f3442..854fa30 100644
>> --- a/drivers/staging/hv/Channel.c
>> +++ b/drivers/staging/hv/Channel.c
>> @@ -787,7 +787,7 @@ VmbusChannelSendPacket(
>> bufferList[0].Data = &desc;
>> bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
>>
>> - bufferList[1].Data = Buffer;
>> + bufferList[1].Data = (void *)Buffer;
>
>Yeah, I thought about doing this as well, but it's wrong. If this
>buffer really isn't being modified, then the Data pointer needs to be
>const.
>
>Or, if the Data pointer really is going to not be const, then the
>function parameters need to be changed, but that means lots of code
>needs to be changed.
>
>Hank, what do you think is the correct thing to do here?
>
>thanks,
>
>greg k-h

I think both will work. At some point in the past for this design was
To leave open the possibility for having the buffer modified. Right
Now I am pretty sure that it does not get modified.

I am not tied to using either void or const. What makes more sense, are
The kernel guidelines that if it does not get modified to define it as const?

The only thing about changing the API signature is that it does trickle into
A bunch of changes (primarily in Channel.[ch], ChannelInterface.[ch] and RingBuffer.[ch])


Thanks,

Hank.

2009-07-29 20:46:43

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 4/4] Staging: hv: Fix warning by casting a (const void *) to (void *)

On Wed, Jul 29, 2009 at 08:13:56PM +0000, Hank Janssen wrote:
>
> >On Wed, Jul 29, 2009 at 02:10:28PM +0200, Nicolas Palix wrote:
> >>
> >> Fix compilation warning by casting the const void *Buffer
> >> variable into a void *.
> >>
> >>>
> [....]
> >> Signed-off-by: Nicolas Palix <[email protected]>
> >> ---
> >> drivers/staging/hv/Channel.c | 2 +-
> >> 1 files changed, 1 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
> >> index 68f3442..854fa30 100644
> >> --- a/drivers/staging/hv/Channel.c
> >> +++ b/drivers/staging/hv/Channel.c
> >> @@ -787,7 +787,7 @@ VmbusChannelSendPacket(
> >> bufferList[0].Data = &desc;
> >> bufferList[0].Length = sizeof(VMPACKET_DESCRIPTOR);
> >>
> >> - bufferList[1].Data = Buffer;
> >> + bufferList[1].Data = (void *)Buffer;
> >
> >Yeah, I thought about doing this as well, but it's wrong. If this
> >buffer really isn't being modified, then the Data pointer needs to be
> >const.
> >
> >Or, if the Data pointer really is going to not be const, then the
> >function parameters need to be changed, but that means lots of code
> >needs to be changed.
> >
> >Hank, what do you think is the correct thing to do here?
> >
> >thanks,
> >
> >greg k-h
>
> I think both will work. At some point in the past for this design was
> To leave open the possibility for having the buffer modified. Right
> Now I am pretty sure that it does not get modified.
>
> I am not tied to using either void or const. What makes more sense, are
> The kernel guidelines that if it does not get modified to define it as const?

Yes.

But the best thing to do is the other suggestion, convert it to use the
real scatter-gather api, and not duplicate the functionality here. That
should solve this issue, right?

> The only thing about changing the API signature is that it does trickle into
> A bunch of changes (primarily in Channel.[ch], ChannelInterface.[ch] and RingBuffer.[ch])

Yeah, that's why I didn't think it was a good idea overall to do that.

Oh, the ringbuffer code will eventually need to get removed anyway, the
kernel already has such infrastructure, so it should be used instead.

thanks,

greg k-h