linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] staging: r8188eu: fix sparse warnings
@ 2021-08-21 16:18 Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Hi,
	This patch series fixes some sparse warnings in rtw_br_ext.c

Thanks,
Aakash Hemadri

Aakash Hemadri (5):
  staging: r8188eu: restricted __be16 degrades to int
  staging: r8188eu: cast to restricted __be32
  staging: r8188eu: incorrect type in csum_ipv6_magic
  staging: r8188eu: restricted __be16 degrades to int
  staging: r8188eu: incorrect type in assignment

 drivers/staging/r8188eu/core/rtw_br_ext.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)


base-commit: 093991aaadf0fbb34184fa37a46e7a157da3f386
-- 
2.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
@ 2021-08-21 16:18 ` Aakash Hemadri
  2021-08-21 17:23   ` Phillip Potter
  2021-08-21 16:18 ` [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32 Aakash Hemadri
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Fix sparse warning:
> rtw_br_ext.c:73:23: warning: restricted __be16 degrades to integer

Here tag->tag_len is be16, use be16_to_cpu()

Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
---
 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 ee52f28a1e56..f6d1f6029ec3 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -70,7 +70,7 @@ static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
 	struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
 	int data_len;
 
-	data_len = tag->tag_len + TAG_HDR_LEN;
+	data_len = be16_to_cpu(tag->tag_len) + TAG_HDR_LEN;
 	if (skb_tailroom(skb) < data_len) {
 		_DEBUG_ERR("skb_tailroom() failed in add SID tag!\n");
 		return -1;
-- 
2.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
@ 2021-08-21 16:18 ` Aakash Hemadri
  2021-08-23  8:44   ` Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 3/5] staging: r8188eu: incorrect type in csum_ipv6_magic Aakash Hemadri
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Fix sparse warning:
> rtw_br_ext.c:836:54: warning: cast to restricted __be32

dhpch->cookie is be32, change it's type.

Suggested-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index f6d1f6029ec3..f65d94bfa286 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -649,7 +649,7 @@ struct dhcpMessage {
 	u_int8_t chaddr[16];
 	u_int8_t sname[64];
 	u_int8_t file[128];
-	u_int32_t cookie;
+	__be32 cookie;
 	u_int8_t options[308]; /* 312 - cookie */
 };
 
@@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
 					struct dhcpMessage *dhcph =
 						(struct dhcpMessage *)((size_t)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.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 3/5] staging: r8188eu: incorrect type in csum_ipv6_magic
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32 Aakash Hemadri
@ 2021-08-21 16:18 ` Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 4/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Fix sparse warning:
> rtw_br_ext.c:771:84:    got restricted __be16 [usertype] payload_len
> rtw_br_ext.c:773:110: warning: incorrect type in argument 2
    (different base types)
> rtw_br_ext.c:773:110:    expected int len
> rtw_br_ext.c:773:110:    got restricted __be16 [usertype] payload_len

csum_ipv6_magic and csum_partial expect int len not __be16, use
be16_to_cpu()

Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index f65d94bfa286..26606093a3c3 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -615,9 +615,9 @@ int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
 						struct icmp6hdr  *hdr = (struct icmp6hdr *)(skb->data + ETH_HLEN + sizeof(*iph));
 						hdr->icmp6_cksum = 0;
 						hdr->icmp6_cksum = csum_ipv6_magic(&iph->saddr, &iph->daddr,
-										iph->payload_len,
+										be16_to_cpu(iph->payload_len),
 										IPPROTO_ICMPV6,
-										csum_partial((__u8 *)hdr, iph->payload_len, 0));
+										csum_partial((__u8 *)hdr, be16_to_cpu(iph->payload_len), 0));
 					}
 				}
 			}
-- 
2.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 4/5] staging: r8188eu: restricted __be16 degrades to int
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
                   ` (2 preceding siblings ...)
  2021-08-21 16:18 ` [PATCH v3 3/5] staging: r8188eu: incorrect type in csum_ipv6_magic Aakash Hemadri
@ 2021-08-21 16:18 ` Aakash Hemadri
  2021-08-21 16:18 ` [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment Aakash Hemadri
  2021-08-21 16:20 ` [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Greg Kroah-Hartman
  5 siblings, 0 replies; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Fix sparse warning:
> rtw_br_ext.c:839:70: warning: restricted __be16 degrades to integer
> rtw_br_ext.c:845:70: warning: invalid assignment: |=
> rtw_br_ext.c:845:70:    left side has type unsigned short
> rtw_br_ext.c:845:70:    right side has type restricted __be16

dhcp->flags is be16, so change its type to that.
Change htons() to cpu_to_be16() for clarity.

Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
---
 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 26606093a3c3..83a4594a4214 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -641,7 +641,7 @@ struct dhcpMessage {
 	u_int8_t hops;
 	u_int32_t xid;
 	u_int16_t secs;
-	u_int16_t flags;
+	__be16 flags;
 	u_int32_t ciaddr;
 	u_int32_t yiaddr;
 	u_int32_t siaddr;
@@ -674,13 +674,13 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 					u32 cookie = be32_to_cpu(dhcph->cookie);
 
 					if (cookie == DHCP_MAGIC) { /*  match magic word */
-						if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
+						if (!(dhcph->flags & cpu_to_be16(BROADCAST_FLAG))) {
 							/*  if not broadcast */
 							register int sum = 0;
 
 							DEBUG_INFO("DHCP: change flag of DHCP request to broadcast.\n");
 							/*  or BROADCAST flag */
-							dhcph->flags |= htons(BROADCAST_FLAG);
+							dhcph->flags |= cpu_to_be16(BROADCAST_FLAG);
 							/*  recalculate checksum */
 							sum = ~(udph->check) & 0xffff;
 							sum += be16_to_cpu(dhcph->flags);
-- 
2.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
                   ` (3 preceding siblings ...)
  2021-08-21 16:18 ` [PATCH v3 4/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
@ 2021-08-21 16:18 ` Aakash Hemadri
  2021-08-22 20:25   ` Larry Finger
  2021-08-21 16:20 ` [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Greg Kroah-Hartman
  5 siblings, 1 reply; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-21 16:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

Fix sparse warning:
> rtw_br_ext.c:516:57: warning: incorrect type in assignment
    (different base types)
> rtw_br_ext.c:516:57:    expected unsigned short
> rtw_br_ext.c:516:57:    got restricted __be16 [usertype]

*pMagic holds __be16 change it's type to __be16

Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index 83a4594a4214..14cf13516d34 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -474,7 +474,7 @@ int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
 		/*                Handle PPPoE frame                 */
 		/*---------------------------------------------------*/
 		struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
-		unsigned short *pMagic;
+		__be16 *pMagic;
 
 		switch (method) {
 		case NAT25_CHECK:
@@ -512,7 +512,7 @@ int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
 						tag->tag_len = htons(MAGIC_CODE_LEN+RTL_RELAY_TAG_LEN+old_tag_len);
 
 						/*  insert the magic_code+client mac in relay tag */
-						pMagic = (unsigned short *)tag->tag_data;
+						pMagic = (__be16 *)tag->tag_data;
 						*pMagic = htons(MAGIC_CODE);
 						memcpy(tag->tag_data+MAGIC_CODE_LEN, skb->data+ETH_ALEN, ETH_ALEN);
 
-- 
2.32.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 0/5] staging: r8188eu: fix sparse warnings
  2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
                   ` (4 preceding siblings ...)
  2021-08-21 16:18 ` [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment Aakash Hemadri
@ 2021-08-21 16:20 ` Greg Kroah-Hartman
  5 siblings, 0 replies; 15+ messages in thread
From: Greg Kroah-Hartman @ 2021-08-21 16:20 UTC (permalink / raw)
  To: Aakash Hemadri; +Cc: Larry Finger, Phillip Potter, linux-staging, linux-kernel

On Sat, Aug 21, 2021 at 09:48:27PM +0530, Aakash Hemadri wrote:
> Hi,
> 	This patch series fixes some sparse warnings in rtw_br_ext.c
> 
> Thanks,
> Aakash Hemadri
> 
> Aakash Hemadri (5):
>   staging: r8188eu: restricted __be16 degrades to int
>   staging: r8188eu: cast to restricted __be32
>   staging: r8188eu: incorrect type in csum_ipv6_magic
>   staging: r8188eu: restricted __be16 degrades to int
>   staging: r8188eu: incorrect type in assignment
> 
>  drivers/staging/r8188eu/core/rtw_br_ext.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> 
> base-commit: 093991aaadf0fbb34184fa37a46e7a157da3f386
> -- 
> 2.32.0
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- This looks like a new version of a previously submitted patch, but you
  did not list below the --- line any changes from the previous version.
  Please read the section entitled "The canonical patch format" in the
  kernel file, Documentation/SubmittingPatches for what needs to be done
  here to properly describe this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int
  2021-08-21 16:18 ` [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
@ 2021-08-21 17:23   ` Phillip Potter
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Potter @ 2021-08-21 17:23 UTC (permalink / raw)
  To: Aakash Hemadri
  Cc: Greg Kroah-Hartman, Larry Finger, linux-staging,
	Linux Kernel Mailing List

On Sat, 21 Aug 2021 at 17:18, Aakash Hemadri <aakashhemadri123@gmail.com> wrote:
>
> Fix sparse warning:
> > rtw_br_ext.c:73:23: warning: restricted __be16 degrades to integer
>
> Here tag->tag_len is be16, use be16_to_cpu()
>
> Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
> ---
>  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 ee52f28a1e56..f6d1f6029ec3 100644
> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> @@ -70,7 +70,7 @@ static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
>         struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
>         int data_len;
>
> -       data_len = tag->tag_len + TAG_HDR_LEN;
> +       data_len = be16_to_cpu(tag->tag_len) + TAG_HDR_LEN;
>         if (skb_tailroom(skb) < data_len) {
>                 _DEBUG_ERR("skb_tailroom() failed in add SID tag!\n");
>                 return -1;
> --
> 2.32.0
>

Thanks for this - looks good from what I can see.

Acked-by: Phillip Potter <phil@philpotter.co.uk>

Regards,
Phil

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment
  2021-08-21 16:18 ` [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment Aakash Hemadri
@ 2021-08-22 20:25   ` Larry Finger
  0 siblings, 0 replies; 15+ messages in thread
From: Larry Finger @ 2021-08-22 20:25 UTC (permalink / raw)
  To: Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter
  Cc: linux-staging, linux-kernel

On 8/21/21 11:18 AM, Aakash Hemadri wrote:
> Fix sparse warning:
>> rtw_br_ext.c:516:57: warning: incorrect type in assignment
>      (different base types)
>> rtw_br_ext.c:516:57:    expected unsigned short
>> rtw_br_ext.c:516:57:    got restricted __be16 [usertype]
> 
> *pMagic holds __be16 change it's type to __be16
> 
> Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
> ---
>   drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> index 83a4594a4214..14cf13516d34 100644
> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> @@ -474,7 +474,7 @@ int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
>   		/*                Handle PPPoE frame                 */
>   		/*---------------------------------------------------*/
>   		struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
> -		unsigned short *pMagic;
> +		__be16 *pMagic;
>   
>   		switch (method) {
>   		case NAT25_CHECK:
> @@ -512,7 +512,7 @@ int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
>   						tag->tag_len = htons(MAGIC_CODE_LEN+RTL_RELAY_TAG_LEN+old_tag_len);
>   
>   						/*  insert the magic_code+client mac in relay tag */
> -						pMagic = (unsigned short *)tag->tag_data;
> +						pMagic = (__be16 *)tag->tag_data;
>   						*pMagic = htons(MAGIC_CODE);
>   						memcpy(tag->tag_data+MAGIC_CODE_LEN, skb->data+ETH_ALEN, ETH_ALEN);
>   
> 

For all 5 patches,

Ack by Larry Finger <Larry.finger#lwfinger.net>

Thanks,

Larry


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-21 16:18 ` [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32 Aakash Hemadri
@ 2021-08-23  8:44   ` Aakash Hemadri
  2021-08-23 14:24     ` Larry Finger
  0 siblings, 1 reply; 15+ messages in thread
From: Aakash Hemadri @ 2021-08-23  8:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Phillip Potter
  Cc: linux-staging, linux-kernel

On 21/08/21 09:48PM, Aakash Hemadri wrote:
> Fix sparse warning:
> > rtw_br_ext.c:836:54: warning: cast to restricted __be32
> 
> dhpch->cookie is be32, change it's type.
> 
> Suggested-by: Larry Finger <Larry.Finger@lwfinger.net>
> Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> index f6d1f6029ec3..f65d94bfa286 100644
> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> @@ -649,7 +649,7 @@ struct dhcpMessage {
>  	u_int8_t chaddr[16];
>  	u_int8_t sname[64];
>  	u_int8_t file[128];
> -	u_int32_t cookie;
> +	__be32 cookie;
>  	u_int8_t options[308]; /* 312 - cookie */
>  };
>  
> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
>  				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
>  					struct dhcpMessage *dhcph =
>  						(struct dhcpMessage *)((size_t)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.32.0
> 

David Laight suggested to use get_unaligned_be32, I am not sure if it's
the right thing to do because as far as I understand get_unaligned_be32
byteshifts the argument.

Can someone please confirm if this change is okay?

Thanks,
Aakash Hemadri.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-23  8:44   ` Aakash Hemadri
@ 2021-08-23 14:24     ` Larry Finger
  2021-08-25  9:13       ` David Laight
  0 siblings, 1 reply; 15+ messages in thread
From: Larry Finger @ 2021-08-23 14:24 UTC (permalink / raw)
  To: Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter
  Cc: linux-staging, linux-kernel

On 8/23/21 3:44 AM, Aakash Hemadri wrote:
> On 21/08/21 09:48PM, Aakash Hemadri wrote:
>> Fix sparse warning:
>>> rtw_br_ext.c:836:54: warning: cast to restricted __be32
>>
>> dhpch->cookie is be32, change it's type.
>>
>> Suggested-by: Larry Finger <Larry.Finger@lwfinger.net>
>> Signed-off-by: Aakash Hemadri <aakashhemadri123@gmail.com>
>> ---
>>   drivers/staging/r8188eu/core/rtw_br_ext.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
>> index f6d1f6029ec3..f65d94bfa286 100644
>> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
>> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
>> @@ -649,7 +649,7 @@ struct dhcpMessage {
>>   	u_int8_t chaddr[16];
>>   	u_int8_t sname[64];
>>   	u_int8_t file[128];
>> -	u_int32_t cookie;
>> +	__be32 cookie;
>>   	u_int8_t options[308]; /* 312 - cookie */
>>   };
>>   
>> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
>>   				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
>>   					struct dhcpMessage *dhcph =
>>   						(struct dhcpMessage *)((size_t)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.32.0
>>
> 
> David Laight suggested to use get_unaligned_be32, I am not sure if it's
> the right thing to do because as far as I understand get_unaligned_be32
> byteshifts the argument.
> 
> Can someone please confirm if this change is okay?
> 

It is not needed. variable dhcph->cookie is 4-byte aligned. Usind the unaligned 
version would just add cpu cycles and arrivw at the same point!

Larry


^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-23 14:24     ` Larry Finger
@ 2021-08-25  9:13       ` David Laight
  2021-08-25  9:19         ` Dan Carpenter
  0 siblings, 1 reply; 15+ messages in thread
From: David Laight @ 2021-08-25  9:13 UTC (permalink / raw)
  To: 'Larry Finger',
	Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter
  Cc: linux-staging, linux-kernel

From: Larry Finger
> Sent: 23 August 2021 15:24
> 
> On 8/23/21 3:44 AM, Aakash Hemadri wrote:
> > On 21/08/21 09:48PM, Aakash Hemadri wrote:
> >> Fix sparse warning:
> >>> rtw_br_ext.c:836:54: warning: cast to restricted __be32
> >>
> >> dhpch->cookie is be32, change it's type.
...
> >> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> >> index f6d1f6029ec3..f65d94bfa286 100644
> >> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> >> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
...
> >> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> >>   				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
> >>   					struct dhcpMessage *dhcph =
> >>   						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));

This assignment looks dubious at best - WTF is (size_t) for?
I don't seem to have a source tree with this driver in it (probably only in 'next'?).
I suspect it should be:
	struct dhcp_message *dhcph = (void *)(udph + 1);

> >> -					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.32.0
> >>
> >
> > David Laight suggested to use get_unaligned_be32, I am not sure if it's
> > the right thing to do because as far as I understand get_unaligned_be32
> > byteshifts the argument.
> >
> > Can someone please confirm if this change is okay?
> >
> 
> It is not needed. variable dhcph->cookie is 4-byte aligned. Usind the unaligned
> version would just add cpu cycles and arrivw at the same point!

It rather depends on whether the input buffer is aligned.
Although if it might not be then then the structure(s) that map
it need to be marked 'packed'.
Which would also mean the get_unaligned_be32() isn't the correct
way to handle a misaligned buffer.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-25  9:13       ` David Laight
@ 2021-08-25  9:19         ` Dan Carpenter
  2021-08-25 10:21           ` David Laight
  0 siblings, 1 reply; 15+ messages in thread
From: Dan Carpenter @ 2021-08-25  9:19 UTC (permalink / raw)
  To: David Laight
  Cc: 'Larry Finger',
	Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter,
	linux-staging, linux-kernel

On Wed, Aug 25, 2021 at 09:13:44AM +0000, David Laight wrote:
> From: Larry Finger
> > Sent: 23 August 2021 15:24
> > 
> > On 8/23/21 3:44 AM, Aakash Hemadri wrote:
> > > On 21/08/21 09:48PM, Aakash Hemadri wrote:
> > >> Fix sparse warning:
> > >>> rtw_br_ext.c:836:54: warning: cast to restricted __be32
> > >>
> > >> dhpch->cookie is be32, change it's type.
> ...
> > >> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> > >> index f6d1f6029ec3..f65d94bfa286 100644
> > >> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> > >> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> ...
> > >> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> > >>   				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
> > >>   					struct dhcpMessage *dhcph =
> > >>   						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
> 
> This assignment looks dubious at best - WTF is (size_t) for?
> I don't seem to have a source tree with this driver in it (probably only in 'next'?).
> I suspect it should be:
> 	struct dhcp_message *dhcph = (void *)(udph + 1);

Those are equivalent.  Either way works.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-25  9:19         ` Dan Carpenter
@ 2021-08-25 10:21           ` David Laight
  2021-08-25 10:39             ` Dan Carpenter
  0 siblings, 1 reply; 15+ messages in thread
From: David Laight @ 2021-08-25 10:21 UTC (permalink / raw)
  To: 'Dan Carpenter'
  Cc: 'Larry Finger',
	Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter,
	linux-staging, linux-kernel

From: Dan Carpenter
> Sent: 25 August 2021 10:19
> 
> On Wed, Aug 25, 2021 at 09:13:44AM +0000, David Laight wrote:
> > From: Larry Finger
> > > Sent: 23 August 2021 15:24
> > >
> > > On 8/23/21 3:44 AM, Aakash Hemadri wrote:
> > > > On 21/08/21 09:48PM, Aakash Hemadri wrote:
> > > >> Fix sparse warning:
> > > >>> rtw_br_ext.c:836:54: warning: cast to restricted __be32
> > > >>
> > > >> dhpch->cookie is be32, change it's type.
> > ...
> > > >> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c
> b/drivers/staging/r8188eu/core/rtw_br_ext.c
> > > >> index f6d1f6029ec3..f65d94bfa286 100644
> > > >> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> > > >> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> > ...
> > > >> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> > > >>   				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
> > > >>   					struct dhcpMessage *dhcph =
> > > >>   						(struct dhcpMessage *)((size_t)udph + sizeof(struct
> udphdr));
> >
> > This assignment looks dubious at best - WTF is (size_t) for?
> > I don't seem to have a source tree with this driver in it (probably only in 'next'?).
> > I suspect it should be:
> > 	struct dhcp_message *dhcph = (void *)(udph + 1);
> 
> Those are equivalent.  Either way works.

size_t isn't guaranteed to be large enough to hold a pointer.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32
  2021-08-25 10:21           ` David Laight
@ 2021-08-25 10:39             ` Dan Carpenter
  0 siblings, 0 replies; 15+ messages in thread
From: Dan Carpenter @ 2021-08-25 10:39 UTC (permalink / raw)
  To: David Laight
  Cc: 'Larry Finger',
	Aakash Hemadri, Greg Kroah-Hartman, Phillip Potter,
	linux-staging, linux-kernel

On Wed, Aug 25, 2021 at 10:21:23AM +0000, David Laight wrote:
> From: Dan Carpenter
> > Sent: 25 August 2021 10:19
> > 
> > On Wed, Aug 25, 2021 at 09:13:44AM +0000, David Laight wrote:
> > > From: Larry Finger
> > > > Sent: 23 August 2021 15:24
> > > >
> > > > On 8/23/21 3:44 AM, Aakash Hemadri wrote:
> > > > > On 21/08/21 09:48PM, Aakash Hemadri wrote:
> > > > >> Fix sparse warning:
> > > > >>> rtw_br_ext.c:836:54: warning: cast to restricted __be32
> > > > >>
> > > > >> dhpch->cookie is be32, change it's type.
> > > ...
> > > > >> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c
> > b/drivers/staging/r8188eu/core/rtw_br_ext.c
> > > > >> index f6d1f6029ec3..f65d94bfa286 100644
> > > > >> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> > > > >> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> > > ...
> > > > >> @@ -671,7 +671,7 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
> > > > >>   				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
> > > > >>   					struct dhcpMessage *dhcph =
> > > > >>   						(struct dhcpMessage *)((size_t)udph + sizeof(struct
> > udphdr));
> > >
> > > This assignment looks dubious at best - WTF is (size_t) for?
> > > I don't seem to have a source tree with this driver in it (probably only in 'next'?).
> > > I suspect it should be:
> > > 	struct dhcp_message *dhcph = (void *)(udph + 1);
> > 
> > Those are equivalent.  Either way works.
> 
> size_t isn't guaranteed to be large enough to hold a pointer.

It is on every system that Linux is ever going to build on.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-08-25 10:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-21 16:18 [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Aakash Hemadri
2021-08-21 16:18 ` [PATCH v3 1/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
2021-08-21 17:23   ` Phillip Potter
2021-08-21 16:18 ` [PATCH v3 2/5] staging: r8188eu: cast to restricted __be32 Aakash Hemadri
2021-08-23  8:44   ` Aakash Hemadri
2021-08-23 14:24     ` Larry Finger
2021-08-25  9:13       ` David Laight
2021-08-25  9:19         ` Dan Carpenter
2021-08-25 10:21           ` David Laight
2021-08-25 10:39             ` Dan Carpenter
2021-08-21 16:18 ` [PATCH v3 3/5] staging: r8188eu: incorrect type in csum_ipv6_magic Aakash Hemadri
2021-08-21 16:18 ` [PATCH v3 4/5] staging: r8188eu: restricted __be16 degrades to int Aakash Hemadri
2021-08-21 16:18 ` [PATCH v3 5/5] staging: r8188eu: incorrect type in assignment Aakash Hemadri
2021-08-22 20:25   ` Larry Finger
2021-08-21 16:20 ` [PATCH v3 0/5] staging: r8188eu: fix sparse warnings Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).