* [PATCH v2 0/2] staging: r8188eu: casting simplified
@ 2022-11-06 17:54 Deepak R Varma
2022-11-06 17:55 ` [PATCH v2 1/2] staging: r8188eu: simplify complex pointer casting Deepak R Varma
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Deepak R Varma @ 2022-11-06 17:54 UTC (permalink / raw)
To: Larry Finger, Phillip Potter, Pavel Skripkin, Greg Kroah-Hartman,
linux-staging, linux-kernel
Patch set proposes variable casting simplifications. Change improves code
readability and appears more maintainable.
Changes in v2:
1. Patch set introduced.
Changes associated with pointer casting and variable casting are
split into separate patches. Hence the patch set.
Suggested by gregkh@linuxfoundation.org
Deepak R Varma (2):
staging: r8188eu: simplify complex pointer casting
staging: r8188eu: remove unnecessary casting
drivers/staging/r8188eu/core/rtw_br_ext.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] staging: r8188eu: simplify complex pointer casting
2022-11-06 17:54 [PATCH v2 0/2] staging: r8188eu: casting simplified Deepak R Varma
@ 2022-11-06 17:55 ` Deepak R Varma
2022-11-06 17:57 ` [PATCH v2 2/2] staging: r8188eu: remove unnecessary casting Deepak R Varma
2022-11-07 6:24 ` [PATCH v2 0/2] staging: r8188eu: casting simplified Philipp Hortmann
2 siblings, 0 replies; 4+ messages in thread
From: Deepak R Varma @ 2022-11-06 17:55 UTC (permalink / raw)
To: Larry Finger, Phillip Potter, Pavel Skripkin, Greg Kroah-Hartman,
linux-staging, linux-kernel
Pointers to structures udphdr and dhcpMessage are derived by casting
adjacent pointers with size_t. Such typecast of pointer using size_t
is not preferred. The code looks complex and delicate. Simplify such
casting by utilizing generic "void *" casting.
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v2:
1. Separate the change associated with variable cookie in a separate patch.
Now in patch 2 of this set. Suggested by gregkh@linuxfoundation.org
2. Correct variable ordering. Code cimplified to match current style.
Feedback from gregkh@linuxfoundation.org.
drivers/staging/r8188eu/core/rtw_br_ext.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index a23f7df373ed..4deaa7e352a3 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -610,12 +610,11 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
if (iph->protocol == IPPROTO_UDP) { /* UDP */
- struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+ struct udphdr *udph = (void *)iph + (iph->ihl << 2);
if ((udph->source == htons(CLIENT_PORT)) &&
(udph->dest == htons(SERVER_PORT))) { /* DHCP request */
- struct dhcpMessage *dhcph =
- (struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
+ struct dhcpMessage *dhcph = (void *)udph + sizeof(struct udphdr);
u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
if (cookie == DHCP_MAGIC) { /* match magic word */
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] staging: r8188eu: remove unnecessary casting
2022-11-06 17:54 [PATCH v2 0/2] staging: r8188eu: casting simplified Deepak R Varma
2022-11-06 17:55 ` [PATCH v2 1/2] staging: r8188eu: simplify complex pointer casting Deepak R Varma
@ 2022-11-06 17:57 ` Deepak R Varma
2022-11-07 6:24 ` [PATCH v2 0/2] staging: r8188eu: casting simplified Philipp Hortmann
2 siblings, 0 replies; 4+ messages in thread
From: Deepak R Varma @ 2022-11-06 17:57 UTC (permalink / raw)
To: Larry Finger, Phillip Potter, Pavel Skripkin, Greg Kroah-Hartman,
linux-staging, linux-kernel
The dhcpMessage struct member variable "cookie" is already declared
to be of type __be32. There is no need to cast it again as __be32.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v2:
1. Change associated with variable cookie separated into this patch.
Feedback from gregkh@linuxfoundation.org.
drivers/staging/r8188eu/core/rtw_br_ext.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index 4deaa7e352a3..a7c67014dde0 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -615,7 +615,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
if ((udph->source == htons(CLIENT_PORT)) &&
(udph->dest == htons(SERVER_PORT))) { /* DHCP request */
struct dhcpMessage *dhcph = (void *)udph + sizeof(struct udphdr);
- u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
+ u32 cookie = be32_to_cpu(dhcph->cookie);
if (cookie == DHCP_MAGIC) { /* match magic word */
if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 0/2] staging: r8188eu: casting simplified
2022-11-06 17:54 [PATCH v2 0/2] staging: r8188eu: casting simplified Deepak R Varma
2022-11-06 17:55 ` [PATCH v2 1/2] staging: r8188eu: simplify complex pointer casting Deepak R Varma
2022-11-06 17:57 ` [PATCH v2 2/2] staging: r8188eu: remove unnecessary casting Deepak R Varma
@ 2022-11-07 6:24 ` Philipp Hortmann
2 siblings, 0 replies; 4+ messages in thread
From: Philipp Hortmann @ 2022-11-07 6:24 UTC (permalink / raw)
To: Deepak R Varma, Larry Finger, Phillip Potter, Pavel Skripkin,
Greg Kroah-Hartman, linux-staging, linux-kernel
On 11/6/22 18:54, Deepak R Varma wrote:
> Patch set proposes variable casting simplifications. Change improves code
> readability and appears more maintainable.
>
> Changes in v2:
> 1. Patch set introduced.
> Changes associated with pointer casting and variable casting are
> split into separate patches. Hence the patch set.
> Suggested by gregkh@linuxfoundation.org
>
>
> Deepak R Varma (2):
> staging: r8188eu: simplify complex pointer casting
> staging: r8188eu: remove unnecessary casting
>
> drivers/staging/r8188eu/core/rtw_br_ext.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> --
> 2.34.1
>
>
>
>
Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com> # Edimax N150
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-07 6:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-06 17:54 [PATCH v2 0/2] staging: r8188eu: casting simplified Deepak R Varma
2022-11-06 17:55 ` [PATCH v2 1/2] staging: r8188eu: simplify complex pointer casting Deepak R Varma
2022-11-06 17:57 ` [PATCH v2 2/2] staging: r8188eu: remove unnecessary casting Deepak R Varma
2022-11-07 6:24 ` [PATCH v2 0/2] staging: r8188eu: casting simplified Philipp Hortmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox