Skip to contentSkip to conversation

staging: rtl8188eu: Remove an unused variable and some lines of code

PATCH Superseded Fabio M. De Francesco 2 participants 6 messages Jul 1, 2021 – Jul 2, 2021 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8188eu: Remove an unused variable and some lines of code

Remove set but unused iw_operation_mode[]. Remove all the lines of code from the function rtw_wx_set_rate, except the "return 0;" line to not break userland code that somewhat uses this IOCTL.

---
 .../staging/rtl8188eu/os_dep/ioctl_linux.c    | 72 -------------------
 1 file changed, 72 deletions(-)
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 -72
index b958a8d882b0..a66d8838c034 100644
@@ -46,11 +46,6 @@ static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
 	6000000, 9000000, 12000000, 18000000, 24000000, 36000000,
 	48000000, 54000000};
 
-static const char * const iw_operation_mode[] = {
-	"Auto", "Ad-Hoc", "Managed",  "Master", "Repeater",
-	"Secondary", "Monitor"
-};
-
 void indicate_wx_scan_complete_event(struct adapter *padapter)
 {
 	union iwreq_data wrqu;
@@ -1266,73 +1261,6 @@ static int rtw_wx_set_rate(struct net_device *dev,
 			   struct iw_request_info *a,
 			   union iwreq_data *wrqu, char *extra)
 {
-	int i;
-	u8 datarates[NumRates];
-	u32	target_rate = wrqu->bitrate.value;
-	u32	fixed = wrqu->bitrate.fixed;
-	u32	ratevalue = 0;
-	u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
-
-	if (target_rate == -1) {
-		ratevalue = 11;
-		goto set_rate;
-	}
-	target_rate /= 100000;
-
-	switch (target_rate) {
-	case 10:
-		ratevalue = 0;
-		break;
-	case 20:
-		ratevalue = 1;
-		break;
-	case 55:
-		ratevalue = 2;
-		break;
-	case 60:
-		ratevalue = 3;
-		break;
-	case 90:
-		ratevalue = 4;
-		break;
-	case 110:
-		ratevalue = 5;
-		break;
-	case 120:
-		ratevalue = 6;
-		break;
-	case 180:
-		ratevalue = 7;
-		break;
-	case 240:
-		ratevalue = 8;
-		break;
-	case 360:
-		ratevalue = 9;
-		break;
-	case 480:
-		ratevalue = 10;
-		break;
-	case 540:
-		ratevalue = 11;
-		break;
-	default:
-		ratevalue = 11;
-		break;
-	}
-
-set_rate:
-
-	for (i = 0; i < NumRates; i++) {
-		if (ratevalue == mpdatarate[i]) {
-			datarates[i] = mpdatarate[i];
-			if (fixed == 0)
-				break;
-		} else {
-			datarates[i] = 0xff;
-		}
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.32.0
#1 lore raw
Quoted 26 lines · Fabio M. De Francesco

Remove set but unused iw_operation_mode[]. Remove all the lines of code from the function rtw_wx_set_rate, except the "return 0;" line to not break userland code that somewhat uses this IOCTL.

---
 .../staging/rtl8188eu/os_dep/ioctl_linux.c    | 72 -------------------
 1 file changed, 72 deletions(-)
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 -5
index b958a8d882b0..a66d8838c034 100644
@@ -46,11 +46,6 @@ static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
 	6000000, 9000000, 12000000, 18000000, 24000000, 36000000,
 	48000000, 54000000};
 
-static const char * const iw_operation_mode[] = {
-	"Auto", "Ad-Hoc", "Managed",  "Master", "Repeater",
-	"Secondary", "Monitor"
-};
-
 void indicate_wx_scan_complete_event(struct adapter *padapter)
 {
 	union iwreq_data wrqu;

drivers/staging/rtl8188eu/os_dep/ioctl_linux.c static int rtw_wx_set_rate(struct net_device *dev, · line 1263

Quoted 3 lines
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 -0
@@ -1266,73 +1261,6 @@ static int rtw_wx_set_rate(struct net_device *dev,
 			   struct iw_request_info *a,
 			   union iwreq_data *wrqu, char *extra)
 {

Just delete this whole file. It doesn't do anything now.

regards,
dan carpenter

#2 lore raw
Quoted 18 lines · Dan Carpenter
Quoted 17 lines · Fabio M. De Francesco

Remove set but unused iw_operation_mode[]. Remove all the lines of code from the function rtw_wx_set_rate, except the "return 0;" line to not break userland code that somewhat uses this IOCTL.

---
 .../staging/rtl8188eu/os_dep/ioctl_linux.c    | 72 -------------------
 1 file changed, 72 deletions(-)
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 -0
index b958a8d882b0..a66d8838c034 100644
@@ -46,11 +46,6 @@ static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
 	6000000, 9000000, 12000000, 18000000, 24000000, 36000000,
 	48000000, 54000000};
 
Quoted 14 lines

drivers/staging/rtl8188eu/os_dep/ioctl_linux.c static int rtw_wx_set_rate(struct net_device *dev, · line 1263

Quoted 12 lines
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 -5
-static const char * const iw_operation_mode[] = {
-	"Auto", "Ad-Hoc", "Managed",  "Master", "Repeater",
-	"Secondary", "Monitor"
-};
-
 void indicate_wx_scan_complete_event(struct adapter *padapter)
 {
 	union iwreq_data wrqu;
@@ -1266,73 +1261,6 @@ static int rtw_wx_set_rate(struct net_device *dev,
 			   struct iw_request_info *a,
 			   union iwreq_data *wrqu, char *extra)
 {

Just delete this whole file. It doesn't do anything now.

Sorry, I meant function, not file. *chortle*. :P

regards,
dan carpenter

#3 lore raw
Quoted 9 lines · CEST Dan Carpenter
Quoted 8 lines · Dan Carpenter
Quoted 6 lines · Fabio M. De Francesco

Remove set but unused iw_operation_mode[]. Remove all the lines of code from the function rtw_wx_set_rate, except the "return 0;" line to not break userland code that somewhat uses this IOCTL.

Dear Dan,

Quoted 3 lines
Quoted 1 line

Just delete this whole file. It doesn't do anything now.

Sorry, I meant function, not file. *chortle*. :P

No worries, it is clear it was unintended.

Back to the function... As you may suspect :-) I know practically nothing neither of Linux device drivers or of whatever else kernel, so I take your words for good. ASAP, I'll send a v2 of this patch.

However, I usually like to understand what I make (just for fun and... more).

That rtw_wx_set_rate() is the implementation of the SIOCSIWRATE IOCTL command. I hope that I have not misunderstood it, have I?

However, we know that this function does practically nothing and then simply returns 0 to the user. That's exactly the reason why I deleted all its lines (except one).

If I am a user of that command I get a "success" return code (0) and I don't notice that it won't be able to set the bit rate. However everything should still keep running (I suppose using the default bit rate of the hardware; who really knows?).

Now it's time for two questions:

1) what happens if that command is used by some users that (hopelessly) expect the function to set the bit rate? I mean: if the function is not anymore in the list of the IOCTL commands of the rtw_handlers array will still the user program compile, link, and don't crash at runtime?

2) how should I delete the association of SIOCSIWRATE with rtw_wx_set_rate() in the rtw_handlers array?
- delete the entry and shift the array one position up?
- set the SIOCSIWRATE entry to NULL?

Regards,

Fabio

Quoted 3 lines

regards,
dan carpenter

#4 lore raw
Quoted 19 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Dan Carpenter
Quoted 8 lines · Dan Carpenter
Quoted 6 lines · Fabio M. De Francesco

Remove set but unused iw_operation_mode[]. Remove all the lines of code from the function rtw_wx_set_rate, except the "return 0;" line to not break userland code that somewhat uses this IOCTL.

Dear Dan,

Quoted 3 lines
Quoted 1 line

Just delete this whole file. It doesn't do anything now.

Sorry, I meant function, not file. *chortle*. :P

No worries, it is clear it was unintended.

Quoted 8 lines

Back to the function... As you may suspect :-) I know practically nothing neither of Linux device drivers or of whatever else kernel, so I take your words for good. ASAP, I'll send a v2 of this patch.

However, I usually like to understand what I make (just for fun and... more).

That rtw_wx_set_rate() is the implementation of the SIOCSIWRATE IOCTL command. I hope that I have not misunderstood it, have I?

Correct.

Quoted 4 lines

However, we know that this function does practically nothing and then simply returns 0 to the user. That's exactly the reason why I deleted all its lines (except one).

It used to do nothing in a much more complicated way before commit 1aef69ecacda ("staging: rtl8188eu: Remove function rtw_setdatarate_cmd()")

Quoted 5 lines

If I am a user of that command I get a "success" return code (0) and I don't notice that it won't be able to set the bit rate. However everything should still keep running (I suppose using the default bit rate of the hardware; who really knows?).

It will still do nothing but now instead of returning success it will return -ENOTSUPP. This is done in wireless_process_ioctl().

Quoted 8 lines

Now it's time for two questions:

1) what happens if that command is used by some users that (hopelessly) expect the function to set the bit rate? I mean: if the function is not anymore in the list of the IOCTL commands of the rtw_handlers array will still the user program compile, link, and don't crash at runtime?

Userspace programs are supposed to be written so that they work with every wifi driver, so they should be able to handle -ENOTSUPP. If this breaks a userspace application then we will have to change it back. But returning -ENOTSUPP is the correct behavior, so let's first try to do the correct thing and then think about working around bugs in userspace if we find them.

Quoted 4 lines

2) how should I delete the association of SIOCSIWRATE with rtw_wx_set_rate() in the rtw_handlers array?
- delete the entry and shift the array one position up?
- set the SIOCSIWRATE entry to NULL?

The IW_HANDLER() macro puts the function in the correct position in the array. So just delete it. Everything else will remain unchanged.

regards,
dan carpenter

#5 lore raw

You should write that at the start of the commit message.

This driver doesn't support SIOCSIWRATE. It just returns zero and does nothing. Change it to return -ENOTSUPP instead. (This is an API change but we don't expect it to break anything).

regards,
dan carpenter