2020-04-29 15:25:56

by Oscar Carter

[permalink] [raw]
Subject: [PATCH 0/2] staging: vt6656: Refactor the vnt_set_bss_mode function

This patch series refactors the vnt_set_bss_mode function through two
patches.

The first one checks the return value of all the functions that return
zero if successful or a negative error code on failure.

The second patch removes all the duplicate code in the "if, else if, else"
statements as all the branches in every "if" are almost the same.

Oscar Carter (2):
staging: vt6656: Check the return values in vnt_set_bss_mode function
staging: vt6656: Refactor the vnt_set_bss_mode function

drivers/staging/vt6656/card.c | 77 ++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 38 deletions(-)

--
2.20.1


2020-04-29 15:26:32

by Oscar Carter

[permalink] [raw]
Subject: [PATCH 1/2] staging: vt6656: Check the return values in vnt_set_bss_mode function

Check the return value of all the functions that return zero if
successful or a negative error code on failure inside the function
vnt_set_bss_mode.

Also, remove the unnecessary variable initialization as this variable is
set a few lines later.

Signed-off-by: Oscar Carter <[email protected]>
---
drivers/staging/vt6656/card.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 872717f9df49..0854b70cb89f 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -471,12 +471,15 @@ int vnt_radio_power_on(struct vnt_private *priv)

int vnt_set_bss_mode(struct vnt_private *priv)
{
- int ret = 0;
+ int ret;

if (priv->rf_type == RF_AIROHA7230 && priv->bb_type == BB_TYPE_11A)
- vnt_mac_set_bb_type(priv, BB_TYPE_11G);
+ ret = vnt_mac_set_bb_type(priv, BB_TYPE_11G);
else
- vnt_mac_set_bb_type(priv, priv->bb_type);
+ ret = vnt_mac_set_bb_type(priv, priv->bb_type);
+
+ if (ret)
+ return ret;

priv->packet_type = vnt_get_pkt_type(priv);

@@ -492,8 +495,13 @@ int vnt_set_bss_mode(struct vnt_private *priv)
if (ret)
return ret;

- vnt_update_ifs(priv);
- vnt_set_rspinf(priv, (u8)priv->bb_type);
+ ret = vnt_update_ifs(priv);
+ if (ret)
+ return ret;
+
+ ret = vnt_set_rspinf(priv, (u8)priv->bb_type);
+ if (ret)
+ return ret;

if (priv->bb_type == BB_TYPE_11A) {
if (priv->rf_type == RF_AIROHA7230) {
@@ -521,6 +529,5 @@ int vnt_set_bss_mode(struct vnt_private *priv)
priv->bb_vga[3] = 0x0;
}

- vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
- return 0;
+ return vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
}
--
2.20.1

2020-04-29 15:26:55

by Oscar Carter

[permalink] [raw]
Subject: [PATCH 2/2] staging: vt6656: Refactor the vnt_set_bss_mode function

Remove all the duplicate code in the "if, else if, else" statements as
all the branches in every "if" are almost the same. The only difference
between branches is some value. So, use variables instead of repeat
code.

Also, remove the unnecessary casting to u8 type because the
"priv->bb_type" variable is already an u8 tpe.

Signed-off-by: Oscar Carter <[email protected]>
---
drivers/staging/vt6656/card.c | 68 ++++++++++++++++-------------------
1 file changed, 31 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 0854b70cb89f..3cb97c4daeb8 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -472,62 +472,56 @@ int vnt_radio_power_on(struct vnt_private *priv)
int vnt_set_bss_mode(struct vnt_private *priv)
{
int ret;
+ unsigned char type = priv->bb_type;
+ unsigned char data = 0;
+ unsigned char bb_vga_0 = 0x1c;
+ unsigned char bb_vga_2_3 = 0x00;

if (priv->rf_type == RF_AIROHA7230 && priv->bb_type == BB_TYPE_11A)
- ret = vnt_mac_set_bb_type(priv, BB_TYPE_11G);
- else
- ret = vnt_mac_set_bb_type(priv, priv->bb_type);
+ type = BB_TYPE_11G;

+ ret = vnt_mac_set_bb_type(priv, type);
if (ret)
return ret;

priv->packet_type = vnt_get_pkt_type(priv);

- if (priv->bb_type == BB_TYPE_11A)
- ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
- 0x88, 0x03);
- else if (priv->bb_type == BB_TYPE_11B)
- ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
- 0x88, 0x02);
- else if (priv->bb_type == BB_TYPE_11G)
+ if (priv->bb_type == BB_TYPE_11A) {
+ data = 0x03;
+ bb_vga_0 = 0x20;
+ bb_vga_2_3 = 0x10;
+ } else if (priv->bb_type == BB_TYPE_11B) {
+ data = 0x02;
+ } else if (priv->bb_type == BB_TYPE_11G) {
+ data = 0x08;
+ }
+
+ if (data) {
ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
- 0x88, 0x08);
- if (ret)
- return ret;
+ 0x88, data);
+ if (ret)
+ return ret;
+ }

ret = vnt_update_ifs(priv);
if (ret)
return ret;

- ret = vnt_set_rspinf(priv, (u8)priv->bb_type);
+ ret = vnt_set_rspinf(priv, priv->bb_type);
if (ret)
return ret;

- if (priv->bb_type == BB_TYPE_11A) {
- if (priv->rf_type == RF_AIROHA7230) {
- priv->bb_vga[0] = 0x20;
+ if (priv->rf_type == RF_AIROHA7230) {
+ priv->bb_vga[0] = bb_vga_0;

- ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
- 0xe7, priv->bb_vga[0]);
- if (ret)
- return ret;
- }
-
- priv->bb_vga[2] = 0x10;
- priv->bb_vga[3] = 0x10;
- } else {
- if (priv->rf_type == RF_AIROHA7230) {
- priv->bb_vga[0] = 0x1c;
-
- ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
- 0xe7, priv->bb_vga[0]);
- if (ret)
- return ret;
- }
-
- priv->bb_vga[2] = 0x0;
- priv->bb_vga[3] = 0x0;
+ ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
+ 0xe7, priv->bb_vga[0]);
+ if (ret)
+ return ret;
}

+ priv->bb_vga[2] = bb_vga_2_3;
+ priv->bb_vga[3] = bb_vga_2_3;
+
return vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
}
--
2.20.1