2021-08-28 11:12:47

by Aakash Hemadri

[permalink] [raw]
Subject: [PATCH v5 0/3] staging: r8188eu: fix sparse warnings

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

Changes in v4 -> v5
- Dropped two patches as they have already been fixed by Larry's changes
to endian sensitive variables in `struct dhcpMessage`

Changes in v3 -> v4
- Added this changelog, as requested by Greg's patch bot

Changes in v2 -> v3
- Fixed incorrect usage/removal of endian swaps and checks

Changes in v1 -> v2
- Split patch

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

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


base-commit: 4adb389e08c95fdf91995271932c59250ff0d561
--
2.32.0


2021-08-28 11:12:51

by Aakash Hemadri

[permalink] [raw]
Subject: [PATCH v5 1/3] staging: r8188eu: restricted __be16 degrades to int

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 <[email protected]>
---
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 62a672243696..aa56cd1a8490 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

2021-08-28 11:13:40

by Aakash Hemadri

[permalink] [raw]
Subject: [PATCH v5 3/3] staging: r8188eu: incorrect type in assignment

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 <[email protected]>
---
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 38f1bd591da9..bce73e8cbd52 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

2021-08-30 10:54:53

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] staging: r8188eu: fix sparse warnings

These patches are fine.

Reviewed-by: Dan Carpenter <[email protected]>

regards,
dan carpenter

2021-09-02 10:02:11

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v5 1/3] staging: r8188eu: restricted __be16 degrades to int

On Sat, Aug 28, 2021 at 04:40:44PM +0530, Aakash Hemadri 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 <[email protected]>
> ---
> 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 62a672243696..aa56cd1a8490 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
>

If this change happens, that means the existing driver does not work at
all on little-endian machines today? But that seems odd and wrong, are
you sure this change is correct?

How did you test this?

thanks,

greg k-h

2021-09-02 10:02:50

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v5 3/3] staging: r8188eu: incorrect type in assignment

On Sat, Aug 28, 2021 at 04:40:46PM +0530, 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

I do not understand this sentence, what are you trying to say?

Remember, "it's" is short for "it is".

> Signed-off-by: Aakash Hemadri <[email protected]>
> ---
> 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 38f1bd591da9..bce73e8cbd52 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;

Is this whole function ever actually called?

Can someone run a ftrace on the driver to see if this function ever
runs, and if not, remove it?

thanks,

greg k-h

2021-09-03 11:37:49

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v5 3/3] staging: r8188eu: incorrect type in assignment

On Thu, Sep 02, 2021 at 11:28:45AM +0200, Greg Kroah-Hartman wrote:
> On Sat, Aug 28, 2021 at 04:40:46PM +0530, Aakash Hemadri wrote:
> > @@ -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;
>
> Is this whole function ever actually called?
>
> Can someone run a ftrace on the driver to see if this function ever
> runs, and if not, remove it?
>

Yeah. That was my thinking when reviewing this patchset is that the NAT
stuff is probably not well tested. It's only used for WIFI_STATION_STATE
or WIFI_ADHOC_STATE.

I don't think it's dead code but having NAT code in the driver is the
wrong layer probably?

regards,
dan carpenter