2022-10-17 14:31:02

by Deepak R Varma

[permalink] [raw]
Subject: [PATCH 4/4] staging: r8188eu: use htons macro instead of __constant_htons

Macro "htons" is more efficiant and clearer. It should be used for
constants instead of the __contast_htons macro. Resolves following
checkpatch script complaint:
WARNING: __constant_htons should be htons

Signed-off-by: Deepak R Varma <[email protected]>
---
drivers/staging/r8188eu/core/rtw_br_ext.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index 290affe50d0b..334360de23da 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -612,14 +612,14 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));

- if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
+ if (protocol == htons(ETH_P_IP)) { /* IP */
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));

- if ((udph->source == __constant_htons(CLIENT_PORT)) &&
- (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
+ if ((udph->source == htons(CLIENT_PORT)) &&
+ (udph->dest == htons(SERVER_PORT))) { /* DHCP request */
struct dhcpMessage *dhcph =
(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
--
2.30.2




2022-10-19 06:41:28

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 4/4] staging: r8188eu: use htons macro instead of __constant_htons

On Mon, 2022-10-17 at 18:54 +0530, Deepak R Varma wrote:
> Macro "htons" is more efficiant and clearer. It should be used for
> constants instead of the __contast_htons macro. Resolves following

typo: __constant_htons

> checkpatch script complaint:
> WARNING: __constant_htons should be htons
[]
> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
[]
> @@ -612,14 +612,14 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
> __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
>
> - if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
> + if (protocol == htons(ETH_P_IP)) { /* IP */
> 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));
>
> - if ((udph->source == __constant_htons(CLIENT_PORT)) &&
> - (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
> + if ((udph->source == htons(CLIENT_PORT)) &&
> + (udph->dest == htons(SERVER_PORT))) { /* DHCP request */

OK, this bit seems fine

> struct dhcpMessage *dhcph =
> (struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));

IMO: this existing code however is ugly.
Casting a pointer to a size_t isn't great.

Perhaps:

struct dhcpMessage *dhcp;

dhcp = (void *)udhp + sizeof(struct udphdr);

in a separate patch.

> u32 cookie = be32_to_cpu((__be32)dhcph->cookie);

And dhcph->cookie already is a __be32 so the cast is pointless.

drivers/staging/r8188eu/core/rtw_br_ext.c-598- __be32 cookie;

2022-10-19 14:04:19

by Deepak R Varma

[permalink] [raw]
Subject: Re: [PATCH 4/4] staging: r8188eu: use htons macro instead of __constant_htons

On Tue, Oct 18, 2022 at 11:08:06PM -0700, Joe Perches wrote:
> On Mon, 2022-10-17 at 18:54 +0530, Deepak R Varma wrote:
> > Macro "htons" is more efficiant and clearer. It should be used for
> > constants instead of the __contast_htons macro. Resolves following
>
> typo: __constant_htons
>
> > checkpatch script complaint:
> > WARNING: __constant_htons should be htons
> []
> > diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> []
> > @@ -612,14 +612,14 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> > if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
> > __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
> >
> > - if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
> > + if (protocol == htons(ETH_P_IP)) { /* IP */
> > 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));
> >
> > - if ((udph->source == __constant_htons(CLIENT_PORT)) &&
> > - (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
> > + if ((udph->source == htons(CLIENT_PORT)) &&
> > + (udph->dest == htons(SERVER_PORT))) { /* DHCP request */
>
> OK, this bit seems fine
>
> > struct dhcpMessage *dhcph =
> > (struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
>
> IMO: this existing code however is ugly.
> Casting a pointer to a size_t isn't great.
>
> Perhaps:
>
> struct dhcpMessage *dhcp;
>
> dhcp = (void *)udhp + sizeof(struct udphdr);
>
> in a separate patch.
>
> > u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
>
> And dhcph->cookie already is a __be32 so the cast is pointless.
>
> drivers/staging/r8188eu/core/rtw_br_ext.c-598- __be32 cookie;

Thank you Joe. I will include this code clean up as separates patches are resend
the patch set.

>
>


2022-11-05 16:03:07

by Deepak R Varma

[permalink] [raw]
Subject: Re: [PATCH 4/4] staging: r8188eu: use htons macro instead of __constant_htons

On Tue, Oct 18, 2022 at 11:08:06PM -0700, Joe Perches wrote:
> On Mon, 2022-10-17 at 18:54 +0530, Deepak R Varma wrote:
> > Macro "htons" is more efficiant and clearer. It should be used for
> > constants instead of the __contast_htons macro. Resolves following
>
> typo: __constant_htons
>
> > checkpatch script complaint:
> > WARNING: __constant_htons should be htons
> []
> > diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> []
> > @@ -612,14 +612,14 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> > if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
> > __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
> >
> > - if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
> > + if (protocol == htons(ETH_P_IP)) { /* IP */
> > 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));
> >
> > - if ((udph->source == __constant_htons(CLIENT_PORT)) &&
> > - (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
> > + if ((udph->source == htons(CLIENT_PORT)) &&
> > + (udph->dest == htons(SERVER_PORT))) { /* DHCP request */
>
> OK, this bit seems fine
>
> > struct dhcpMessage *dhcph =
> > (struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
>
> IMO: this existing code however is ugly.
> Casting a pointer to a size_t isn't great.

Hello Joe,
Other thank looking ugly, is there any impact / risk associated with such
casting? I tried to look for the reasons myself but did not find anything
relevant or to the point.

Thank you,
./drv

>
> Perhaps:
>
> struct dhcpMessage *dhcp;
>
> dhcp = (void *)udhp + sizeof(struct udphdr);
>
> in a separate patch.
>
> > u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
>
> And dhcph->cookie already is a __be32 so the cast is pointless.
>
> drivers/staging/r8188eu/core/rtw_br_ext.c-598- __be32 cookie;
>