staging: r8188eu: Used u16 instead of __le16 in rtl8188e_set_FwMediaStatus_cmd()
PATCH 1/1 staging: r8188eu: Used u16 instead of __le16 in rtl8188e_set_FwMediaStatus_cmd()
- Changed 2nd argument from __le16 to u16 to fix sparse warning "warning: incorrect type in argument 2 (different base types)"
- Removed le16_to_cpu() in staging/r8188eu/hal/rtl8188e_cmd.c
--- drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 4 ++-- drivers/staging/r8188eu/include/rtl8188e_cmd.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2 -2
@@ -193,9 +193,9 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) } -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +u16 mst_rpt = mstatus_rpt;FillH2CCmd_88E (adapt,H2C_COM_MEDIA_STATUS_RPT ,sizeof (mst_rpt), (u8 *)&mst_rpt); }
drivers/staging/r8188eu/include/rtl8188e_cmd.h +1 -1
@@ -85,6 +85,6 @@ void rtl8188e_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 arg,void rtl8188e_set_p2p_ps_offload_cmd (struct adapter *adapt,u8 p2p_ps_state);void CheckFwRsvdPageContent (struct adapter *adapt); -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt); +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt);#endif /* __RTL8188E_CMD_H__ */
Signature · 1 line
2.39.0
Quoted 15 lines · Gaurav Pathak
- Changed 2nd argument from
__le16to u16 to fix sparse warning "warning: incorrect type in argument 2 (different base types)"
- Removedle16_to_cpu()instaging/r8188eu/hal/rtl8188e_cmd.cSigned-off-by Gaurav Pathak <[email protected]>--- drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 4 ++-- drivers/staging/r8188eu/include/rtl8188e_cmd.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/staging/r8188eu/hal/rtl8188e_cmd.c +0
-0
drivers/staging/r8188eu/hal/rtl8188e_cmd.c void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) · line 198
Quoted 8 lines
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2
-2@@ -193,9 +193,9 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) } -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +u16 mst_rpt = mstatus_rpt;
You are changing the behavior of the code here for big endian systems. Either the change is good or bad. TLDR; I suspect the change is bad but I don't know.
The mstatus_rpt is CPU endian. It is the one of two things for connect or disconnect:
connect: (psta->mac_id << 8) | 1
disconnect: (psta->mac_id << 8) | 0
So the question is in FillH2CCmd_88E() should the connect/disconnect come before the mac_id as it currently does or should it only work that way on little endian systems and be reversed on big endian systems? My feeling is that the second option makes no sense so this patch is not correct.
Instead what should happen is:
-void rtl8188e_set_FwMediaStatus_cmd(struct adapter *adapt, __le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd(struct adapter *adapt, u16 mstatus_rpt)
{
- u16 mst_rpt = le16_to_cpu(mstatus_rpt);
+ __le16 mst_rpt = cpu_to_le16(mstatus_rpt);
But this is just my intuition and I don't know this hardware.
regards,
dan carpenter
Quoted 49 lines · Dan Carpenter
Quoted 15 lines · Gaurav Pathak
- Changed 2nd argument from
__le16to u16 to fix sparse warning "warning: incorrect type in argument 2 (different base types)"
- Removedle16_to_cpu()instaging/r8188eu/hal/rtl8188e_cmd.cSigned-off-by Gaurav Pathak <[email protected]>--- drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 4 ++-- drivers/staging/r8188eu/include/rtl8188e_cmd.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/staging/r8188eu/hal/rtl8188e_cmd.c +0
-0drivers/staging/r8188eu/hal/rtl8188e_cmd.c void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) · line 198
Quoted 8 lines
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2
-2@@ -193,9 +193,9 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) } -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +u16 mst_rpt = mstatus_rpt;You are changing the behavior of the code here for big endian systems. Either the change is good or bad. TLDR; I suspect the change is bad but I don't know.
The
mstatus_rptis CPU endian. It is the one of two things for connect or disconnect:connect: (psta->mac_id << 8) | 1disconnect: (
psta->mac_id<< 8) | 0So the question is in
FillH2CCmd_88E()should the connect/disconnect come before themac_idas it currently does or should it only work that way on little endian systems and be reversed on big endian systems? My feeling is that the second option makes no sense so this patch is not correct.Instead what should happen is:
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2
-2-void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +__le16 mst_rpt =cpu_to_le16 (mstatus_rpt);
Quoted 1 line
But this is just my intuition and I don't know this hardware.
I agree with Dan. This patch was attacking the symptom, not the cause. The original Realtek driver confuses cpu_to_le16() with le16_to_cpu() in many places. Apparently, I missed this one. On little-endian systems, both are no-ops, thus it does not matter.
I have a big-endian system (PowerBook G4) and will test later today.
Larry
Thanks Dan and Larry for looking into it.
I also don't have much understanding of the underlying hardware, please do let me know of your tests on big-endin machine.
Quoted 1 line
On little-endian systems, both are no-ops, thus it does not matter
Does it mean that the patch is not required and the original implementation is okay?
Quoted 60 lines · Larry Finger
Quoted 47 lines · Dan Carpenter
Quoted 15 lines · Gaurav Pathak
- Changed 2nd argument from
__le16to u16 to fix sparse warning "warning: incorrect type in argument 2 (different base types)"
- Removedle16_to_cpu()instaging/r8188eu/hal/rtl8188e_cmd.cSigned-off-by Gaurav Pathak <[email protected]>--- drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 4 ++-- drivers/staging/r8188eu/include/rtl8188e_cmd.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/staging/r8188eu/hal/rtl8188e_cmd.c +0
-0drivers/staging/r8188eu/hal/rtl8188e_cmd.c void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) · line 196
Quoted 6 lines
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2
-2@@ -193,9 +193,9 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) } -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +u16 mst_rpt = mstatus_rpt;You are changing the behavior of the code here for big endian systems. Either the change is good or bad. TLDR; I suspect the change is bad but I don't know.
The
mstatus_rptis CPU endian. It is the one of two things for connect or disconnect:connect: (psta->mac_id << 8) | 1disconnect: (
psta->mac_id<< 8) | 0So the question is in
FillH2CCmd_88E()should the connect/disconnect come before themac_idas it currently does or should it only work that way on little endian systems and be reversed on big endian systems? My feeling is that the second option makes no sense so this patch is not correct.Instead what should happen is:
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2
-2-void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +__le16 mst_rpt =cpu_to_le16 (mstatus_rpt);Quoted 1 line
But this is just my intuition and I don't know this hardware.
I agree with Dan. This patch was attacking the symptom, not the cause. The original Realtek driver confuses
cpu_to_le16()withle16_to_cpu()in many places. Apparently, I missed this one. On little-endian systems, both are no-ops, thus it does not matter.I have a big-endian system (PowerBook G4) and will test later today.
Larry
Quoted 3 lines · Gaurav Pathak
- Changed 2nd argument from
__le16to u16 to fix sparse warning "warning: incorrect type in argument 2 (different base types)"
- Removedle16_to_cpu()instaging/r8188eu/hal/rtl8188e_cmd.c
The first change was correct; however the second was wrong. The FillH2CCmd_88E(adapt() call sends information from the host to the computer on the card, which must be little endian, but the argument to the routine is in CPU order. See the commit message in the attached patch.
I have no interest in submitting that patch upstream, but you might find it an interesting read when you prepare V2 of this patch. Of particular note is that even though the semantics were wrong, the previous code worked correctly because cpu_to_le16() and le16_to_cpu() both byte swap a 16-bit word and their results are the same.
Larry
From 1aa7b9e5e6c02b48cc0e2c487b9b791299921af3 Mon Sep 17 00:00:00 2001
From: Larry Finger <[email protected]>
Date: Thu, 12 Jan 2023 21:38:13 -0600
Subject: [PATCH] staging: r8188eu: Fix some endian problems
To: [email protected]
Cc: [email protected]
Sparse lists the following warnings:
CHECK drivers/staging/r8188eu/core/rtw_mlme.cdrivers/staging/r8188eu/core/rtw_mlme.c:1197:49: warning: incorrect type in
argument 2 (different base types)drivers/staging/r8188eu/core/rtw_mlme.c:1197:49: expected restricted
__le16 [usertype] mstatus_rptdrivers/staging/r8188eu/core/rtw_mlme.c:1197:49: got unsigned short
[assigned] [usertype] media_status_rptdrivers/staging/r8188eu/core/rtw_mlme.c:1275:57: warning: incorrect type in
argument 2 (different base types)drivers/staging/r8188eu/core/rtw_mlme.c:1275:57: expected restricted
__le16 [usertype] mstatus_rptdrivers/staging/r8188eu/core/rtw_mlme.c:1275:57: got unsigned short
[assigned] [usertype] media_status
CHECK drivers/staging/r8188eu/core/rtw_mlme_ext.cdrivers/staging/r8188eu/core/rtw_mlme_ext.c:6842:58: warning: incorrect type
in argument 2 (different base types)drivers/staging/r8188eu/core/rtw_mlme_ext.c:6842:58: expected restricted
__le16 [usertype] mstatus_rptdrivers/staging/r8188eu/core/rtw_mlme_ext.c:6842:58: got unsigned short
[assigned] [usertype] media_status
The second argument of rtl8188e_set_FwMediaStatus_cmd() needs to be in CPU order, not little-endian; however, when it uses that value to call FillH2CCmd_88E() the parameter must be in little-endian order as that value will be sent to the firmware. Note that the conversion from LE to CPU order was le16_to_cpu() rather than the correct cpu_to_le16.
The definition of FillH2CCmd_88E() is revised, and the proper conversion routine is used.
Note that the original code performed one byte swap on the secong argument of FillH2CCmd_88E(), and got the correct answer even though the semantics were very wrong.
--- drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 4 ++-- drivers/staging/r8188eu/include/rtl8188e_cmd.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/r8188eu/hal/rtl8188e_cmd.c +2 -2
@@ -193,9 +193,9 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) } -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt) +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt) { -u16 mst_rpt =le16_to_cpu (mstatus_rpt); +__le16 mst_rpt =cpu_to_le16 (mstatus_rpt);FillH2CCmd_88E (adapt,H2C_COM_MEDIA_STATUS_RPT ,sizeof (mst_rpt), (u8 *)&mst_rpt); }
drivers/staging/r8188eu/include/rtl8188e_cmd.h +1 -1
@@ -85,6 +85,6 @@ void rtl8188e_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 arg,void rtl8188e_set_p2p_ps_offload_cmd (struct adapter *adapt,u8 p2p_ps_state);void CheckFwRsvdPageContent (struct adapter *adapt); -void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,__le16 mstatus_rpt); +void rtl8188e_set_FwMediaStatus_cmd (struct adapter *adapt,u16 mstatus_rpt);#endif /* __RTL8188E_CMD_H__ */
Signature · 1 line
2.39.0