* [PATCH v2] staging: vt6655: use memset to make code clearer
@ 2022-09-09 9:08 Nam Cao
2022-09-09 10:23 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2022-09-09 9:08 UTC (permalink / raw)
To: forest, gregkh; +Cc: namcaov, linux-kernel, linux-staging
A line of code sets the entire struct vnt_rdes0 to zero by treating it as
unsigned int. This works because sizeof(unsigned int) is equal to
sizeof(struct vnt_rdes0) (4 bytes). However it is not obvious what this
code is doing. Re-write this using memset to make the code clearer.
Signed-off-by: Nam Cao <namcaov@gmail.com>
---
v2: re-write commit message because previous message describes a
non-existent problem.
drivers/staging/vt6655/device_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 8e2a976aaaad..a38657769c20 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -867,7 +867,7 @@ static bool device_alloc_rx_buf(struct vnt_private *priv,
return false;
}
- *((unsigned int *)&rd->rd0) = 0; /* FIX cast */
+ memset((void *)&rd->rd0, 0, sizeof(rd->rd0));
rd->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
rd->rd0.owner = OWNED_BY_NIC;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: vt6655: use memset to make code clearer
2022-09-09 9:08 [PATCH v2] staging: vt6655: use memset to make code clearer Nam Cao
@ 2022-09-09 10:23 ` Greg KH
2022-09-09 11:29 ` Nam Cao
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-09-09 10:23 UTC (permalink / raw)
To: Nam Cao; +Cc: forest, linux-kernel, linux-staging
On Fri, Sep 09, 2022 at 11:08:57AM +0200, Nam Cao wrote:
> A line of code sets the entire struct vnt_rdes0 to zero by treating it as
> unsigned int. This works because sizeof(unsigned int) is equal to
> sizeof(struct vnt_rdes0) (4 bytes). However it is not obvious what this
> code is doing. Re-write this using memset to make the code clearer.
>
> Signed-off-by: Nam Cao <namcaov@gmail.com>
> ---
> v2: re-write commit message because previous message describes a
> non-existent problem.
>
> drivers/staging/vt6655/device_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
> index 8e2a976aaaad..a38657769c20 100644
> --- a/drivers/staging/vt6655/device_main.c
> +++ b/drivers/staging/vt6655/device_main.c
> @@ -867,7 +867,7 @@ static bool device_alloc_rx_buf(struct vnt_private *priv,
> return false;
> }
>
> - *((unsigned int *)&rd->rd0) = 0; /* FIX cast */
> + memset((void *)&rd->rd0, 0, sizeof(rd->rd0));
Why do you have to cast this to (void *)? That should almost never be
needed.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: vt6655: use memset to make code clearer
2022-09-09 10:23 ` Greg KH
@ 2022-09-09 11:29 ` Nam Cao
2022-09-09 11:47 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2022-09-09 11:29 UTC (permalink / raw)
To: Greg KH; +Cc: forest, linux-kernel, linux-staging
On Fri, Sep 9, 2022 at 12:23 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> Why do you have to cast this to (void *)? That should almost never be
> needed.
Because I want to suppress a compiler warning:
drivers/staging/vt6655/device_main.c:869:9: warning: passing argument
1 of ‘memset’ discards ‘volatile’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
869 | memset(&rd->rd0, 0, sizeof(rd->rd0));
| ^~~~~~~~
Best regards,
Nam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: vt6655: use memset to make code clearer
2022-09-09 11:29 ` Nam Cao
@ 2022-09-09 11:47 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2022-09-09 11:47 UTC (permalink / raw)
To: Nam Cao; +Cc: forest, linux-kernel, linux-staging
On Fri, Sep 09, 2022 at 01:29:44PM +0200, Nam Cao wrote:
> On Fri, Sep 9, 2022 at 12:23 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > Why do you have to cast this to (void *)? That should almost never be
> > needed.
>
> Because I want to suppress a compiler warning:
> drivers/staging/vt6655/device_main.c:869:9: warning: passing argument
> 1 of ‘memset’ discards ‘volatile’ qualifier from pointer target type
> [-Wdiscarded-qualifiers]
> 869 | memset(&rd->rd0, 0, sizeof(rd->rd0));
> | ^~~~~~~~
Why would that have a type of "volatile"? That should be fixed first
please.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-09 11:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 9:08 [PATCH v2] staging: vt6655: use memset to make code clearer Nam Cao
2022-09-09 10:23 ` Greg KH
2022-09-09 11:29 ` Nam Cao
2022-09-09 11:47 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.