linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
  2016-07-24 20:15                                   ` [PATCH 0/3] staging: wilc1000: Fine-tuning for two function implementations SF Markus Elfring
@ 2016-07-24 20:23                                     ` SF Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-07-24 20:23 UTC (permalink / raw)
  To: linux-wireless, devel, Austin Shin, Chris Park, Glen Lee,
	Greg Kroah-Hartman, Johnny Kim, Leo Kim, Tony Cho
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 24 Jul 2016 21:45:37 +0200

Three local variables were used only within a single case branch.

* Thus move the data type definition for "rssi" and "size" into the
  corresponding code block.

* The variable "length" was not modified after its initialisation.
  Thus pass a constant value in the affected function call instead.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/staging/wilc1000/linux_wlan.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 7b1ebcc..173be16 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1094,8 +1094,6 @@ int wilc_mac_close(struct net_device *ndev)
 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 {
 	u8 *buff = NULL;
-	s8 rssi;
-	u32 size = 0, length = 0;
 	struct wilc_vif *vif;
 	s32 ret = 0;
 	struct wilc *wilc;
@@ -1110,8 +1108,7 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 	case SIOCSIWPRIV:
 	{
 		struct iwreq *wrq = (struct iwreq *)req;
-
-		size = wrq->u.data.length;
+		u32 size = wrq->u.data.length;
 
 		if (size && wrq->u.data.pointer) {
 			buff = memdup_user(wrq->u.data.pointer,
@@ -1119,7 +1116,9 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 			if (IS_ERR(buff))
 				return PTR_ERR(buff);
 
-			if (strncasecmp(buff, "RSSI", length) == 0) {
+			if (strncasecmp(buff, "RSSI", 0) == 0) {
+				s8 rssi;
+
 				ret = wilc_get_rssi(vif, &rssi);
 				netdev_info(ndev, "RSSI :%d\n", rssi);
 
-- 
2.9.2


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

* Re: [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
@ 2016-07-25 19:17 Lino Sanfilippo
  2016-07-25 19:32 ` walter harms
  2016-07-26  6:25 ` SF Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Lino Sanfilippo @ 2016-07-25 19:17 UTC (permalink / raw)
  To: SF Markus Elfring; +Cc: LKML, kernel-janitors, linux-wireless

>  
> -			if (strncasecmp(buff, "RSSI", length) == 0) {
> +			if (strncasecmp(buff, "RSSI", 0) == 0) {
> +				s8 rssi;
> +

Um, please think a second about if it makes any sense at all to compare 
zero chars of two strings.

Lino

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

* Re: [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
  2016-07-25 19:17 [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl() Lino Sanfilippo
@ 2016-07-25 19:32 ` walter harms
  2016-07-26  6:25 ` SF Markus Elfring
  1 sibling, 0 replies; 6+ messages in thread
From: walter harms @ 2016-07-25 19:32 UTC (permalink / raw)
  To: Lino Sanfilippo; +Cc: SF Markus Elfring, LKML, kernel-janitors, linux-wireless



Am 25.07.2016 21:17, schrieb Lino Sanfilippo:
>>  
>> -			if (strncasecmp(buff, "RSSI", length) == 0) {
>> +			if (strncasecmp(buff, "RSSI", 0) == 0) {
>> +				s8 rssi;
>> +
> 
> Um, please think a second about if it makes any sense at all to compare 
> zero chars of two strings.
> 
> Lino

also:
the switch has only one case and default.

re,
 wh

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

* Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
  2016-07-25 19:17 [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl() Lino Sanfilippo
  2016-07-25 19:32 ` walter harms
@ 2016-07-26  6:25 ` SF Markus Elfring
  2016-07-28 11:45   ` Aw: " Lino Sanfilippo
  1 sibling, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2016-07-26  6:25 UTC (permalink / raw)
  To: Lino Sanfilippo
  Cc: LKML, kernel-janitors, linux-wireless, devel, Greg Kroah-Hartman,
	Steve Caldwell

>> -			if (strncasecmp(buff, "RSSI", length) == 0) {
>> +			if (strncasecmp(buff, "RSSI", 0) == 0) {
>> +				s8 rssi;
>> +
> 
> Um, please think a second about if it makes any sense at all to compare 
> zero chars of two strings.

Under which circumstances should the variable "length" contain an other
value than zero?

How can this open issue be fixed better?

Regards,
Markus

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

* Aw: Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
  2016-07-26  6:25 ` SF Markus Elfring
@ 2016-07-28 11:45   ` Lino Sanfilippo
  2016-07-28 16:00     ` SF Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Lino Sanfilippo @ 2016-07-28 11:45 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: LKML, kernel-janitors, linux-wireless, devel, Greg Kroah-Hartman,
	Steve Caldwell



> Gesendet: Dienstag, 26. Juli 2016 um 08:25 Uhr
> Von: "SF Markus Elfring" <elfring@users.sourceforge.net>

>
> >> -			if (strncasecmp(buff, "RSSI", length) == 0) {
> >> +			if (strncasecmp(buff, "RSSI", 0) == 0) {
> >> +				s8 rssi;
> >> +
> > 
> > Um, please think a second about if it makes any sense at all to compare 
> > zero chars of two strings.
> 
> Under which circumstances should the variable "length" contain an other
> value than zero?

Which circumstances do "not any sense at all" imply? 

> 
> How can this open issue be fixed better?

The code is not too complicated and I think it is very obvious which value/variable
should be passed instead of 0. I suggest to fix this since it is indeed a bug, instead of 
doing "micro optimizations" - which is the last thing that code in the staging area 
needs (as IIRC you have already been told by others, including the staging maintainer).

Regards,
Lino



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

* Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()
  2016-07-28 11:45   ` Aw: " Lino Sanfilippo
@ 2016-07-28 16:00     ` SF Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2016-07-28 16:00 UTC (permalink / raw)
  To: Lino Sanfilippo
  Cc: LKML, kernel-janitors, linux-wireless, devel, Greg Kroah-Hartman,
	Steve Caldwell

> Which circumstances do "not any sense at all" imply? 

Should the expression 'strlen("RSSI")' be passed for the parameter 'length' instead?


> I suggest to fix this since it is indeed a bug,

We can agree that this function implementation was broken for a while there.


> instead of doing "micro optimizations" - which is the last thing that code in the staging area 
> needs (as IIRC you have already been told by others, including the staging maintainer).

The acceptance might grow a bit more for such software fine-tuning
(like refactoring around variable usage).

Regards,
Markus

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

end of thread, other threads:[~2016-07-28 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-25 19:17 [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl() Lino Sanfilippo
2016-07-25 19:32 ` walter harms
2016-07-26  6:25 ` SF Markus Elfring
2016-07-28 11:45   ` Aw: " Lino Sanfilippo
2016-07-28 16:00     ` SF Markus Elfring
     [not found] <5307CAA2.8060406@users.sourceforge.net>
     [not found] ` <alpine.DEB.2.02.1402212321410.2043@localhost6.localdomain6>
     [not found]   ` <530A086E.8010901@users.sourceforge.net>
     [not found]     ` <alpine.DEB.2.02.1402231635510.1985@localhost6.localdomain6>
     [not found]       ` <530A72AA.3000601@users.sourceforge.net>
     [not found]         ` <alpine.DEB.2.02.1402240658210.2090@localhost6.localdomain6>
     [not found]           ` <530B5FB6.6010207@users.sourceforge.net>
     [not found]             ` <alpine.DEB.2.10.1402241710370.2074@hadrien>
     [not found]               ` <530C5E18.1020800@users.sourceforge.net>
     [not found]                 ` <alpine.DEB.2.10.1402251014170.2080@hadrien>
     [not found]                   ` <530CD2C4.4050903@users.sourceforge.net>
     [not found]                     ` <alpine.DEB.2.10.1402251840450.7035@hadrien>
     [not found]                       ` <530CF8FF.8080600@users.sourceforge.net>
     [not found]                         ` <alpine.DEB.2.02.1402252117150.2047@localhost6.localdomain6>
     [not found]                           ` <530DD06F.4090703@users.sourceforge.net>
     [not found]                             ` <alpine.DEB.2.02.1402262129250.2221@localhost6.localdomain6>
     [not found]                               ` <5317A59D.4@users.sourceforge.net>
2015-06-27 14:29                                 ` [PATCH 0/2] staging: wilc1000: Deletion of two unnecessary checks SF Markus Elfring
2016-07-24 20:15                                   ` [PATCH 0/3] staging: wilc1000: Fine-tuning for two function implementations SF Markus Elfring
2016-07-24 20:23                                     ` [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl() SF Markus Elfring

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).