2017-10-29 20:10:51

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/5] wlcore: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 21:02:34 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Use common error handling code in wlcore_nvs_cb()
Delete an unnecessary check statement in wlcore_set_beacon_template()
Return directly after a failed ieee80211_beacon_get()
in wlcore_set_beacon_template()
Use common error handling code in wlcore_set_beacon_template()
Use common error handling code in wl1271_op_suspend()

drivers/net/wireless/ti/wlcore/main.c | 51 ++++++++++++++++-------------------
1 file changed, 23 insertions(+), 28 deletions(-)

--
2.14.3


2017-10-29 20:16:16

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/5] wlcore: Use common error handling code in wl1271_op_suspend()

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 20:36:39 +0100

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the macro "wl1271_warning" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/wireless/ti/wlcore/main.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 12a9d6509382..a110f61110d5 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -1732,8 +1732,7 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
ret = wl1271_configure_suspend(wl, wlvif, wow);
if (ret < 0) {
mutex_unlock(&wl->mutex);
- wl1271_warning("couldn't prepare device to suspend");
- return ret;
+ goto report_preparation_failure;
}
}

@@ -1752,10 +1751,8 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
wl1271_ps_elp_sleep(wl);
mutex_unlock(&wl->mutex);

- if (ret < 0) {
- wl1271_warning("couldn't prepare device to suspend");
- return ret;
- }
+ if (ret < 0)
+ goto report_preparation_failure;

/* flush any remaining work */
wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
@@ -1783,6 +1780,10 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
cancel_delayed_work(&wl->tx_watchdog_work);

return 0;
+
+report_preparation_failure:
+ wl1271_warning("couldn't prepare device to suspend");
+ return ret;
}

static int wl1271_op_resume(struct ieee80211_hw *hw)
--
2.14.3

2017-10-29 20:13:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/5] wlcore: Return directly after a failed ieee80211_beacon_get() in wlcore_set_beacon_template()

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 20:00:41 +0100

Return directly after a call of the function "ieee80211_beacon_get"
failed at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/wireless/ti/wlcore/main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index efea811c1c83..0365b5e40a8d 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -4018,10 +4018,8 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
u16 tmpl_id;

- if (!beacon) {
- ret = -EINVAL;
- goto out;
- }
+ if (!beacon)
+ return -EINVAL;

wl1271_debug(DEBUG_MASTER, "beacon updated");

--
2.14.3

2017-10-30 13:32:39

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 3/5] wlcore: Return directly after a failed ieee80211_beacon_get() in wlcore_set_beacon_template()

On Mon, Oct 30, 2017 at 7:13 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 29 Oct 2017 20:00:41 +0100
>
> Return directly after a call of the function "ieee80211_beacon_get"
> failed at the beginning.
>
> Signed-off-by: Markus Elfring <[email protected]>

Reviewed-by: Julian Calaby <[email protected]>

Thanks,

--
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/

2017-10-29 20:14:47

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/5] wlcore: Use common error handling code in wlcore_set_beacon_template()

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 20:16:22 +0100

Adjust jump targets so that a bit of exception handling can be better
reused at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/wireless/ti/wlcore/main.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 0365b5e40a8d..12a9d6509382 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -4024,10 +4024,9 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
wl1271_debug(DEBUG_MASTER, "beacon updated");

ret = wl1271_ssid_set(wlvif, beacon, ieoffset);
- if (ret < 0) {
- dev_kfree_skb(beacon);
- goto out;
- }
+ if (ret < 0)
+ goto free_skb;
+
min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
CMD_TEMPL_BEACON;
@@ -4035,10 +4034,8 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
beacon->data,
beacon->len, 0,
min_rate);
- if (ret < 0) {
- dev_kfree_skb(beacon);
- goto out;
- }
+ if (ret < 0)
+ goto free_skb;

wlvif->wmm_enabled =
cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
@@ -4051,7 +4048,7 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
* by usermode, don't use the beacon data.
*/
if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
- goto end_bcn;
+ goto free_skb;

/* remove TIM ie from probe response */
wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
@@ -4081,9 +4078,8 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
beacon->data,
beacon->len, 0,
min_rate);
-end_bcn:
+free_skb:
dev_kfree_skb(beacon);
-out:
return ret;
}

--
2.14.3

2017-10-30 13:40:42

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 5/5] wlcore: Use common error handling code in wl1271_op_suspend()

Hi Markus,

On Mon, Oct 30, 2017 at 7:16 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 29 Oct 2017 20:36:39 +0100
>
> Add a jump target so that a specific error message is stored only once
> at the end of this function implementation.
> Replace two calls of the macro "wl1271_warning" by goto statements.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

This patch is bogus, moving error messages around like this is just bizarre.

These are both reporting different failures, so the error messages
should be different.

> ---
> drivers/net/wireless/ti/wlcore/main.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
> index 12a9d6509382..a110f61110d5 100644
> --- a/drivers/net/wireless/ti/wlcore/main.c
> +++ b/drivers/net/wireless/ti/wlcore/main.c
> @@ -1732,8 +1732,7 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
> ret = wl1271_configure_suspend(wl, wlvif, wow);
> if (ret < 0) {
> mutex_unlock(&wl->mutex);
> - wl1271_warning("couldn't prepare device to suspend");

"couldn't configure device for suspend"?

> - return ret;
> + goto report_preparation_failure;
> }
> }
>
> @@ -1752,10 +1751,8 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
> wl1271_ps_elp_sleep(wl);
> mutex_unlock(&wl->mutex);
>
> - if (ret < 0) {
> - wl1271_warning("couldn't prepare device to suspend");

"couldn't enable power saving"?

> - return ret;
> - }
> + if (ret < 0)
> + goto report_preparation_failure;
>
> /* flush any remaining work */
> wl1271_debug(DEBUG_MAC80211, "flushing remaining works");

Thanks,

--
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/

2017-10-30 13:29:06

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 1/5] wlcore: Use common error handling code in wlcore_nvs_cb()

Hi Markus,

On Mon, Oct 30, 2017 at 7:11 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 29 Oct 2017 18:38:04 +0100
>
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/net/wireless/ti/wlcore/main.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
> index c346c021b999..48380d48ef09 100644
> --- a/drivers/net/wireless/ti/wlcore/main.c
> +++ b/drivers/net/wireless/ti/wlcore/main.c
> @@ -6551,6 +6549,11 @@ static void wlcore_nvs_cb(const struct firmware *fw, void *context)
> out:
> release_firmware(fw);
> complete_all(&wl->nvs_loading_complete);
> + return;
> +
> +power_off:

Name this "out_power_off" to match the other labels.

> + wl1271_power_off(wl);
> + goto out_free_nvs;

Why not put this in front of the out_free_nvs label? It looks weird here.

Thanks,

--
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/

2017-10-29 20:11:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/5] wlcore: Use common error handling code in wlcore_nvs_cb()

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 18:38:04 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/wireless/ti/wlcore/main.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index c346c021b999..48380d48ef09 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -6496,16 +6496,14 @@ static void wlcore_nvs_cb(const struct firmware *fw, void *context)
ret = wl12xx_get_hw_info(wl);
if (ret < 0) {
wl1271_error("couldn't get hw info");
- wl1271_power_off(wl);
- goto out_free_nvs;
+ goto power_off;
}

ret = request_threaded_irq(wl->irq, hardirq_fn, wlcore_irq,
wl->irq_flags, pdev->name, wl);
if (ret < 0) {
wl1271_error("interrupt configuration failed");
- wl1271_power_off(wl);
- goto out_free_nvs;
+ goto power_off;
}

#ifdef CONFIG_PM
@@ -6551,6 +6549,11 @@ static void wlcore_nvs_cb(const struct firmware *fw, void *context)
out:
release_firmware(fw);
complete_all(&wl->nvs_loading_complete);
+ return;
+
+power_off:
+ wl1271_power_off(wl);
+ goto out_free_nvs;
}

int wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
--
2.14.3

2017-10-30 13:44:55

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 4/5] wlcore: Use common error handling code in wlcore_set_beacon_template()

>> @@ -4081,9 +4078,8 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
>> beacon->data,
>> beacon->len, 0,
>> min_rate);
>> -end_bcn:
>> +free_skb:
>
> Why rename the label?

I find it clearer according to the Linux coding style.

Regards,
Markus

2017-10-30 13:26:39

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 2/5] wlcore: Delete an unnecessary check statement in wlcore_set_beacon_template()

On Mon, Oct 30, 2017 at 7:12 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 29 Oct 2017 19:45:07 +0100
>
> A goto statement jumped to a target which followed a condition check
> immediately without the specification of useful actions between.
> Thus remove such unnecessary source code at the end of this function.
>
> Signed-off-by: Markus Elfring <[email protected]>

Looks good to me.

Reviewed-by: Julian Calaby <[email protected]>

--
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/

2017-10-30 13:40:43

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 1/5] wlcore: Use common error handling code in wlcore_nvs_cb()

>> @@ -6551,6 +6549,11 @@ static void wlcore_nvs_cb(const struct firmware *fw, void *context)
>> out:
>> release_firmware(fw);
>> complete_all(&wl->nvs_loading_complete);
>> + return;
>> +
>> +power_off:
>
> Name this "out_power_off" to match the other labels.

Do you expect a second approach for this patch series then?


>> + wl1271_power_off(wl);
>> + goto out_free_nvs;
>
> Why not put this in front of the out_free_nvs label?

It seems that I can not really follow this suggestion at the moment.


> It looks weird here.

Which detail do you not like?

Regards,
Markus

2017-10-29 20:12:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/5] wlcore: Delete an unnecessary check statement in wlcore_set_beacon_template()

From: Markus Elfring <[email protected]>
Date: Sun, 29 Oct 2017 19:45:07 +0100

A goto statement jumped to a target which followed a condition check
immediately without the specification of useful actions between.
Thus remove such unnecessary source code at the end of this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/wireless/ti/wlcore/main.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 48380d48ef09..efea811c1c83 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -4085,9 +4085,6 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
min_rate);
end_bcn:
dev_kfree_skb(beacon);
- if (ret < 0)
- goto out;
-
out:
return ret;
}
--
2.14.3

2017-10-30 13:34:13

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 4/5] wlcore: Use common error handling code in wlcore_set_beacon_template()

Hi Markus,

On Mon, Oct 30, 2017 at 7:14 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 29 Oct 2017 20:16:22 +0100
>
> Adjust jump targets so that a bit of exception handling can be better
> reused at the end of this function.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Reviewed-by: Julian Calaby <[email protected]>

However,

> ---
> drivers/net/wireless/ti/wlcore/main.c | 18 +++++++-----------
> 1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
> index 0365b5e40a8d..12a9d6509382 100644
> --- a/drivers/net/wireless/ti/wlcore/main.c
> +++ b/drivers/net/wireless/ti/wlcore/main.c
> @@ -4081,9 +4078,8 @@ static int wlcore_set_beacon_template(struct wl1271 *wl,
> beacon->data,
> beacon->len, 0,
> min_rate);
> -end_bcn:
> +free_skb:

Why rename the label?

Thanks,

--
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/