* Re: [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces
@ 2017-03-15 14:54 Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2017-03-15 14:54 UTC (permalink / raw)
To: Suniel Mahesh; +Cc: gregkh, Dan Carpenter, devel, linux-kernel, karthiknishu
As Dan said, the original was better, but
it could still be improved.
There is only a single case used in the switch.
Perhaps better would be to reduce indentation
by removing the switch and using another goto
label for the memory allocation freeing like the
below.
Perhaps better still, if there were to be more
cases added in the future, would be to move the
case handling logic into separate functions.
---
drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 177 +++++++++++++--------------
1 file changed, 82 insertions(+), 95 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 4c0caa6701a9..8c48b0a527ec 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -2283,115 +2283,102 @@ static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
int ret = -1;
struct rtllib_device *ieee = priv->rtllib;
u32 key[4];
- const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ static const u8 broadcast_addr[ETH_ALEN] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ };
struct iw_point *p = &wrq->u.data;
struct ieee_param *ipw = NULL;
mutex_lock(&priv->wx_mutex);
- switch (cmd) {
- case RTL_IOCTL_WPA_SUPPLICANT:
- if (p->length < sizeof(struct ieee_param) || !p->pointer) {
- ret = -EINVAL;
- goto out;
- }
+ if (cmd != RTL_IOCTL_WPA_SUPPLICANT) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
- ipw = memdup_user(p->pointer, p->length);
- if (IS_ERR(ipw)) {
- ret = PTR_ERR(ipw);
- goto out;
- }
+ if (p->length < sizeof(struct ieee_param) || !p->pointer) {
+ ret = -EINVAL;
+ goto out;
+ }
- if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
- if (ipw->u.crypt.set_tx) {
- if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
- ieee->pairwise_key_type = KEY_TYPE_CCMP;
- else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
- ieee->pairwise_key_type = KEY_TYPE_TKIP;
- else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
- if (ipw->u.crypt.key_len == 13)
- ieee->pairwise_key_type =
- KEY_TYPE_WEP104;
- else if (ipw->u.crypt.key_len == 5)
- ieee->pairwise_key_type =
- KEY_TYPE_WEP40;
- } else {
- ieee->pairwise_key_type = KEY_TYPE_NA;
- }
+ ipw = memdup_user(p->pointer, p->length);
+ if (IS_ERR(ipw)) {
+ ret = PTR_ERR(ipw);
+ goto out;
+ }
- if (ieee->pairwise_key_type) {
- if (is_zero_ether_addr(ieee->ap_mac_addr))
- ieee->iw_mode = IW_MODE_ADHOC;
- memcpy((u8 *)key, ipw->u.crypt.key, 16);
- rtl92e_enable_hw_security_config(dev);
- rtl92e_set_swcam(dev, 4,
- ipw->u.crypt.idx,
- ieee->pairwise_key_type,
- (u8 *)ieee->ap_mac_addr,
- 0, key, 0);
- rtl92e_set_key(dev, 4, ipw->u.crypt.idx,
- ieee->pairwise_key_type,
- (u8 *)ieee->ap_mac_addr,
- 0, key);
- if (ieee->iw_mode == IW_MODE_ADHOC) {
- rtl92e_set_swcam(dev,
- ipw->u.crypt.idx,
- ipw->u.crypt.idx,
- ieee->pairwise_key_type,
- (u8 *)ieee->ap_mac_addr,
- 0, key, 0);
- rtl92e_set_key(dev,
- ipw->u.crypt.idx,
- ipw->u.crypt.idx,
- ieee->pairwise_key_type,
- (u8 *)ieee->ap_mac_addr,
- 0, key);
- }
- }
- if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
- && ieee->pHTInfo->bCurrentHTSupport) {
- rtl92e_writeb(dev, 0x173, 1);
- }
+ if (ipw->cmd != IEEE_CMD_SET_ENCRYPTION)
+ goto out_free;
- } else {
- memcpy((u8 *)key, ipw->u.crypt.key, 16);
- if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
- ieee->group_key_type = KEY_TYPE_CCMP;
- else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
- ieee->group_key_type = KEY_TYPE_TKIP;
- else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
- if (ipw->u.crypt.key_len == 13)
- ieee->group_key_type =
- KEY_TYPE_WEP104;
- else if (ipw->u.crypt.key_len == 5)
- ieee->group_key_type =
- KEY_TYPE_WEP40;
- } else
- ieee->group_key_type = KEY_TYPE_NA;
-
- if (ieee->group_key_type) {
- rtl92e_set_swcam(dev, ipw->u.crypt.idx,
- ipw->u.crypt.idx,
- ieee->group_key_type,
- broadcast_addr, 0, key,
- 0);
- rtl92e_set_key(dev, ipw->u.crypt.idx,
- ipw->u.crypt.idx,
- ieee->group_key_type,
- broadcast_addr, 0, key);
- }
+ if (ipw->u.crypt.set_tx) {
+ if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
+ ieee->pairwise_key_type = KEY_TYPE_CCMP;
+ } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
+ ieee->pairwise_key_type = KEY_TYPE_TKIP;
+ } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+ if (ipw->u.crypt.key_len == 13)
+ ieee->pairwise_key_type = KEY_TYPE_WEP104;
+ else if (ipw->u.crypt.key_len == 5)
+ ieee->pairwise_key_type = KEY_TYPE_WEP40;
+ } else {
+ ieee->pairwise_key_type = KEY_TYPE_NA;
+ }
+
+ if (ieee->pairwise_key_type) {
+ if (is_zero_ether_addr(ieee->ap_mac_addr))
+ ieee->iw_mode = IW_MODE_ADHOC;
+ memcpy((u8 *)key, ipw->u.crypt.key, 16);
+ rtl92e_enable_hw_security_config(dev);
+ rtl92e_set_swcam(dev, 4, ipw->u.crypt.idx,
+ ieee->pairwise_key_type,
+ (u8 *)ieee->ap_mac_addr, 0, key, 0);
+ rtl92e_set_key(dev, 4, ipw->u.crypt.idx,
+ ieee->pairwise_key_type,
+ (u8 *)ieee->ap_mac_addr, 0, key);
+ if (ieee->iw_mode == IW_MODE_ADHOC) {
+ rtl92e_set_swcam(dev, ipw->u.crypt.idx,
+ ipw->u.crypt.idx,
+ ieee->pairwise_key_type,
+ (u8 *)ieee->ap_mac_addr,
+ 0, key, 0);
+ rtl92e_set_key(dev, ipw->u.crypt.idx,
+ ipw->u.crypt.idx,
+ ieee->pairwise_key_type,
+ (u8 *)ieee->ap_mac_addr, 0, key);
}
}
+ if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) &&
+ ieee->pHTInfo->bCurrentHTSupport)
+ rtl92e_writeb(dev, 0x173, 1);
+ } else {
+ memcpy((u8 *)key, ipw->u.crypt.key, 16);
+ if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
+ ieee->group_key_type = KEY_TYPE_CCMP;
+ } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
+ ieee->group_key_type = KEY_TYPE_TKIP;
+ } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+ if (ipw->u.crypt.key_len == 13)
+ ieee->group_key_type = KEY_TYPE_WEP104;
+ else if (ipw->u.crypt.key_len == 5)
+ ieee->group_key_type = KEY_TYPE_WEP40;
+ } else {
+ ieee->group_key_type = KEY_TYPE_NA;
+ }
- ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data,
- 0);
- kfree(ipw);
- break;
- default:
- ret = -EOPNOTSUPP;
- break;
+ if (ieee->group_key_type) {
+ rtl92e_set_swcam(dev, ipw->u.crypt.idx,
+ ipw->u.crypt.idx, ieee->group_key_type,
+ broadcast_addr, 0, key, 0);
+ rtl92e_set_key(dev, ipw->u.crypt.idx, ipw->u.crypt.idx,
+ ieee->group_key_type, broadcast_addr,
+ 0, key);
+ }
}
+out_free:
+ ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data, 0);
+ kfree(ipw);
+
out:
mutex_unlock(&priv->wx_mutex);
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2 1/5] staging: rtl8192e: Fix coding style issues
@ 2017-03-12 13:41 Greg KH
2017-03-15 9:51 ` [PATCH v3 0/8] staging: rtl8192e: Fix coding style, warnings and checks sunil.m
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2017-03-12 13:41 UTC (permalink / raw)
To: sunil.m; +Cc: dan.carpenter, devel, linux-kernel, suniel.spartan
On Fri, Mar 10, 2017 at 12:20:44AM +0530, sunil.m@techveda.org wrote:
> From: Suniel Mahesh <sunil.m@techveda.org>
>
> Fix coding style issues and comments in rtl_core.c
What issues would that be? Please always be specific and tell us what
you do.
Also always test-build your patches, otherwise you make maintainers
really really grumpy :(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 0/8] staging: rtl8192e: Fix coding style, warnings and checks
2017-03-12 13:41 [PATCH v2 1/5] staging: rtl8192e: Fix coding style issues Greg KH
@ 2017-03-15 9:51 ` sunil.m
2017-03-15 9:51 ` [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces sunil.m
0 siblings, 1 reply; 3+ messages in thread
From: sunil.m @ 2017-03-15 9:51 UTC (permalink / raw)
To: gregkh, dan.carpenter; +Cc: devel, linux-kernel, karthiknishu, Suniel Mahesh
From: Suniel Mahesh <sunil.m@techveda.org>
Split earlier patches into multiple commits for easy review as
suggested by Dan Carpenter.
Modified subject, description and in few patches both for
better readability as suggested by Greg KH.
Fixed the following issues reported by checkpatch.pl:
Block comments should align the * on each line, aligned.
Block comments use * on subsequent lines, other characters
are replaced by * .
line over 80 characters, modified as per coding style.
Removed unnecessary 'out of memory' message.
Comparison's to NULL could be written '!foo' or 'foo', modified.
Fixed unbalanced braces around else statement.
Added braces on all arms of the if-else statements to comply with
kernel coding style.
Replaced sizeof(struct foo) into sizeof(*ptr).
Spaces preferred around that 'operator', spacing provided.
Logical continuations should be on the previous line, modified accordingly.
Unnecessary parentheses around variables, removed.
Please use a blank line after function/struct/union/enum declarations, used.
Blank lines aren't necessary after an open brace '{' and before a
close brace '}', removed.
No space is necessary after a cast, removed.
Please don't use multiple blank lines, removed.
Rebased on top of next-20170310.
Patches were tested and built on next-20170310 and staging-testing
as suggested by Greg K-H, no errors reported.
Suniel Mahesh (8):
staging: rtl8192e: Fix comments as per kernel coding style
staging: rtl8192e: Fix coding style
staging: rtl8192e: Remove unnecessary 'out of memory' message
staging: rtl8192e: Rectify pointer comparisions with NULL
staging: rtl8192e: Fix unbalanced braces
staging: rtl8192e: Pass a pointer as an argument to sizeof() instead
of struct
staging: rtl8192e: Fix issues reported by checkpatch.pl
staging: rtl8192e: Fix blank lines and space after a cast
drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 201 +++++++++++----------------
1 file changed, 84 insertions(+), 117 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces
2017-03-15 9:51 ` [PATCH v3 0/8] staging: rtl8192e: Fix coding style, warnings and checks sunil.m
@ 2017-03-15 9:51 ` sunil.m
2017-03-15 10:24 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: sunil.m @ 2017-03-15 9:51 UTC (permalink / raw)
To: gregkh, dan.carpenter; +Cc: devel, linux-kernel, karthiknishu, Suniel Mahesh
From: Suniel Mahesh <sunil.m@techveda.org>
Fixed unbalanced braces around else statement
Add braces on all arms of the if-else statements to comply with
kernel coding style.
Signed-off-by: Suniel Mahesh <sunil.m@techveda.org>
---
Changes for v3:
- Split earlier patches into multiple commits for easy review
as suggested by Greg K-H
- Modified subject and description for better readability
- Rebased on top of next-20170310
- Patches were tested and built on next-20170310 and staging-testing
as suggested by Greg K-H, no errors reported
Changes for v2:
- new patch addition to the series
- Rebased on top of next-20170306
---
drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 30 +++++++++++++++++-----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 0fa4017..c355ee7 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -2294,17 +2294,20 @@ static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
if (ipw->u.crypt.set_tx) {
- if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
+ if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
ieee->pairwise_key_type = KEY_TYPE_CCMP;
- else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
+ } else if (strcmp(ipw->u.crypt.alg,
+ "TKIP") == 0) {
ieee->pairwise_key_type = KEY_TYPE_TKIP;
- else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
- if (ipw->u.crypt.key_len == 13)
+ } else if (strcmp(ipw->u.crypt.alg,
+ "WEP") == 0) {
+ if (ipw->u.crypt.key_len == 13) {
ieee->pairwise_key_type =
KEY_TYPE_WEP104;
- else if (ipw->u.crypt.key_len == 5)
+ } else if (ipw->u.crypt.key_len == 5) {
ieee->pairwise_key_type =
KEY_TYPE_WEP40;
+ }
} else {
ieee->pairwise_key_type = KEY_TYPE_NA;
}
@@ -2346,20 +2349,23 @@ static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
} else {
memcpy((u8 *)key, ipw->u.crypt.key, 16);
- if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
+ if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
ieee->group_key_type = KEY_TYPE_CCMP;
- else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
+ } else if (strcmp(ipw->u.crypt.alg,
+ "TKIP") == 0) {
ieee->group_key_type = KEY_TYPE_TKIP;
- else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
- if (ipw->u.crypt.key_len == 13)
+ } else if (strcmp(ipw->u.crypt.alg,
+ "WEP") == 0) {
+ if (ipw->u.crypt.key_len == 13) {
ieee->group_key_type =
KEY_TYPE_WEP104;
- else if (ipw->u.crypt.key_len == 5)
+ } else if (ipw->u.crypt.key_len == 5) {
ieee->group_key_type =
KEY_TYPE_WEP40;
- } else
+ }
+ } else {
ieee->group_key_type = KEY_TYPE_NA;
-
+ }
if (ieee->group_key_type) {
rtl92e_set_swcam(dev, ipw->u.crypt.idx,
ipw->u.crypt.idx,
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces
2017-03-15 9:51 ` [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces sunil.m
@ 2017-03-15 10:24 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2017-03-15 10:24 UTC (permalink / raw)
To: sunil.m; +Cc: gregkh, devel, linux-kernel, karthiknishu
On Wed, Mar 15, 2017 at 03:21:54PM +0530, sunil.m@techveda.org wrote:
> @@ -2294,17 +2294,20 @@ static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
>
> if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
> if (ipw->u.crypt.set_tx) {
> - if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
> + if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
> ieee->pairwise_key_type = KEY_TYPE_CCMP;
> - else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
> + } else if (strcmp(ipw->u.crypt.alg,
> + "TKIP") == 0) {
This is higgledy piggledy. The original was better.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-15 14:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-15 14:54 [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces Joe Perches
-- strict thread matches above, loose matches on Subject: below --
2017-03-12 13:41 [PATCH v2 1/5] staging: rtl8192e: Fix coding style issues Greg KH
2017-03-15 9:51 ` [PATCH v3 0/8] staging: rtl8192e: Fix coding style, warnings and checks sunil.m
2017-03-15 9:51 ` [PATCH v3 5/8] staging: rtl8192e: Fix unbalanced braces sunil.m
2017-03-15 10:24 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox