Skip to content

Commit db24722

Browse files
jerome-pouillerdanieldegrasse
authored andcommitted
drivers: wifi: siwx91x: Align the ways errors are managed
Unify the way the error code are tested: - sl_status_t is an alias to an int. The compiler won't complain if an int is assigned or compared to a sl_status_t. In the other hand, "int" is well known to manage error code. So, just use "int" everywhere. - Always name the return code "ret" - Unless it is meaningful, test the value of ret against 0 (SL_STATUS_OK is just a convoluted way to say 0). Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
1 parent dd0afec commit db24722

File tree

6 files changed

+53
-57
lines changed

6 files changed

+53
-57
lines changed

drivers/wifi/siwx91x/siwx91x_wifi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2023 Antmicro
3-
* Copyright (c) 2024 Silicon Laboratories Inc.
3+
* Copyright (c) 2024-2025 Silicon Laboratories Inc.
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#define DT_DRV_COMPAT silabs_siwx91x_wifi
@@ -79,7 +79,7 @@ int siwx91x_status(const struct device *dev, struct wifi_iface_status *status)
7979
status->twt_capable = true;
8080

8181
ret = sl_si91x_get_join_configuration(interface, &join_config);
82-
if (ret != SL_STATUS_OK) {
82+
if (ret) {
8383
LOG_ERR("Failed to get join configuration: 0x%x", ret);
8484
return -EINVAL;
8585
}
@@ -324,16 +324,16 @@ static int siwx91x_get_version(const struct device *dev, struct wifi_version *pa
324324
sl_wifi_firmware_version_t fw_version = { };
325325
struct siwx91x_dev *sidev = dev->data;
326326
static char fw_version_str[32];
327-
sl_status_t status;
327+
int ret;
328328

329329
__ASSERT(params, "params cannot be NULL");
330330

331331
if (sidev->state == WIFI_STATE_INTERFACE_DISABLED) {
332332
return -EIO;
333333
}
334334

335-
status = sl_wifi_get_firmware_version(&fw_version);
336-
if (status != SL_STATUS_OK) {
335+
ret = sl_wifi_get_firmware_version(&fw_version);
336+
if (ret) {
337337
return -EINVAL;
338338
}
339339

@@ -352,7 +352,7 @@ static int siwx91x_get_version(const struct device *dev, struct wifi_version *pa
352352
static void siwx91x_iface_init(struct net_if *iface)
353353
{
354354
struct siwx91x_dev *sidev = iface->if_dev->dev->data;
355-
sl_status_t status;
355+
int ret;
356356

357357
sidev->state = WIFI_STATE_INTERFACE_DISABLED;
358358
sidev->iface = iface;
@@ -367,9 +367,9 @@ static void siwx91x_iface_init(struct net_if *iface)
367367
sl_wifi_set_callback(SL_WIFI_STATS_RESPONSE_EVENTS, siwx91x_wifi_module_stats_event_handler,
368368
sidev);
369369

370-
status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, &sidev->macaddr);
371-
if (status) {
372-
LOG_ERR("sl_wifi_get_mac_address(): %#04x", status);
370+
ret = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, &sidev->macaddr);
371+
if (ret) {
372+
LOG_ERR("sl_wifi_get_mac_address(): %#04x", ret);
373373
return;
374374
}
375375
net_if_set_link_addr(iface, sidev->macaddr.octet, sizeof(sidev->macaddr.octet),

drivers/wifi/siwx91x/siwx91x_wifi_ap.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int siwx91x_ap_disable(const struct device *dev)
8787
}
8888
wifi_mgmt_raise_ap_disable_result_event(sidev->iface, WIFI_STATUS_AP_SUCCESS);
8989
sidev->state = WIFI_STATE_INTERFACE_DISABLED;
90-
return ret;
90+
return 0;
9191
}
9292

9393
static int siwx91x_ap_disable_if_required(const struct device *dev,
@@ -131,10 +131,6 @@ int siwx91x_ap_enable(const struct device *dev, struct wifi_connect_req_params *
131131
{
132132
sl_wifi_interface_t interface = sl_wifi_get_default_interface();
133133
struct siwx91x_dev *sidev = dev->data;
134-
sl_wifi_ap_configuration_t saved_ap_cfg;
135-
int ret;
136-
int sec;
137-
138134
sl_wifi_ap_configuration_t siwx91x_ap_cfg = {
139135
.credential_id = SL_NET_DEFAULT_WIFI_AP_CREDENTIAL_ID,
140136
.keepalive_type = SL_SI91X_AP_NULL_BASED_KEEP_ALIVE,
@@ -150,6 +146,8 @@ int siwx91x_ap_enable(const struct device *dev, struct wifi_connect_req_params *
150146
.options = 0,
151147
.is_11n_enabled = 1,
152148
};
149+
sl_wifi_ap_configuration_t saved_ap_cfg;
150+
int ret;
153151

154152
if (FIELD_GET(SIWX91X_INTERFACE_MASK, interface) != SL_WIFI_AP_INTERFACE) {
155153
LOG_ERR("Interface not in AP mode");
@@ -189,19 +187,19 @@ int siwx91x_ap_enable(const struct device *dev, struct wifi_connect_req_params *
189187
return -EINVAL;
190188
}
191189

192-
sec = siwx91x_map_ap_security(params->security);
193-
if (sec < 0) {
190+
ret = siwx91x_map_ap_security(params->security);
191+
if (ret < 0) {
194192
LOG_ERR("Invalid security type");
195193
wifi_mgmt_raise_ap_enable_result_event(sidev->iface,
196194
WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED);
197195
return -EINVAL;
198196
}
197+
siwx91x_ap_cfg.security = ret;
199198

200-
siwx91x_ap_cfg.security = sec;
201199
if (params->security != WIFI_SECURITY_TYPE_NONE) {
202200
ret = sl_net_set_credential(siwx91x_ap_cfg.credential_id, SL_NET_WIFI_PSK,
203201
params->psk, params->psk_length);
204-
if (ret != SL_STATUS_OK) {
202+
if (ret) {
205203
LOG_ERR("Failed to set credentials: 0x%x", ret);
206204
wifi_mgmt_raise_ap_enable_result_event(sidev->iface, WIFI_STATUS_AP_FAIL);
207205
return -EINVAL;
@@ -233,7 +231,7 @@ int siwx91x_ap_enable(const struct device *dev, struct wifi_connect_req_params *
233231
}
234232

235233
ret = sl_wifi_start_ap(SL_WIFI_AP_INTERFACE | SL_WIFI_2_4GHZ_INTERFACE, &siwx91x_ap_cfg);
236-
if (ret != SL_STATUS_OK) {
234+
if (ret) {
237235
LOG_ERR("Failed to enable AP mode: 0x%x", ret);
238236
wifi_mgmt_raise_ap_enable_result_event(sidev->iface, WIFI_STATUS_AP_FAIL);
239237
return -EIO;

drivers/wifi/siwx91x/siwx91x_wifi_ps.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ static int siwx91x_get_connected_ap_beacon_interval_ms(void)
2020
{
2121
sl_wifi_operational_statistics_t sl_stat;
2222
sl_wifi_interface_t interface;
23-
int status;
23+
int ret;
2424

2525
interface = sl_wifi_get_default_interface();
2626
if (FIELD_GET(SIWX91X_INTERFACE_MASK, interface) != SL_WIFI_CLIENT_INTERFACE) {
2727
return 0;
2828
}
2929

30-
status = sl_wifi_get_operational_statistics(SL_WIFI_CLIENT_INTERFACE, &sl_stat);
31-
if (status) {
30+
ret = sl_wifi_get_operational_statistics(SL_WIFI_CLIENT_INTERFACE, &sl_stat);
31+
if (ret) {
3232
return 0;
3333
}
3434

@@ -40,7 +40,7 @@ int siwx91x_apply_power_save(struct siwx91x_dev *sidev)
4040
sl_wifi_performance_profile_t sl_ps_profile;
4141
sl_wifi_interface_t interface;
4242
int beacon_interval;
43-
int status;
43+
int ret;
4444

4545
interface = sl_wifi_get_default_interface();
4646
if (FIELD_GET(SIWX91X_INTERFACE_MASK, interface) != SL_WIFI_CLIENT_INTERFACE) {
@@ -90,14 +90,14 @@ int siwx91x_apply_power_save(struct siwx91x_dev *sidev)
9090
}
9191

9292
out:
93-
status = sl_wifi_set_performance_profile(&sl_ps_profile);
94-
return status ? -EIO : 0;
93+
ret = sl_wifi_set_performance_profile(&sl_ps_profile);
94+
return ret ? -EIO : 0;
9595
}
9696

9797
int siwx91x_set_power_save(const struct device *dev, struct wifi_ps_params *params)
9898
{
9999
struct siwx91x_dev *sidev = dev->data;
100-
int status;
100+
int ret;
101101

102102
__ASSERT(params, "params cannot be NULL");
103103

@@ -143,10 +143,10 @@ int siwx91x_set_power_save(const struct device *dev, struct wifi_ps_params *para
143143
params->fail_reason = WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL;
144144
return -EINVAL;
145145
}
146-
status = siwx91x_apply_power_save(sidev);
147-
if (status) {
146+
ret = siwx91x_apply_power_save(sidev);
147+
if (ret) {
148148
params->fail_reason = WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL;
149-
return status;
149+
return ret;
150150
}
151151
return 0;
152152
}
@@ -157,7 +157,7 @@ int siwx91x_get_power_save_config(const struct device *dev, struct wifi_ps_confi
157157
struct siwx91x_dev *sidev = dev->data;
158158
sl_wifi_interface_t interface;
159159
uint16_t beacon_interval;
160-
sl_status_t status;
160+
int ret;
161161

162162
__ASSERT(config, "config cannot be NULL");
163163

@@ -172,9 +172,9 @@ int siwx91x_get_power_save_config(const struct device *dev, struct wifi_ps_confi
172172
return -EINVAL;
173173
}
174174

175-
status = sl_wifi_get_performance_profile(&sl_ps_profile);
176-
if (status != SL_STATUS_OK) {
177-
LOG_ERR("Failed to get power save profile: 0x%x", status);
175+
ret = sl_wifi_get_performance_profile(&sl_ps_profile);
176+
if (ret) {
177+
LOG_ERR("Failed to get power save profile: 0x%x", ret);
178178
return -EIO;
179179
}
180180

@@ -229,9 +229,7 @@ static int siwx91x_convert_z_sl_twt_req_type(enum wifi_twt_setup_cmd z_req_cmd)
229229

230230
static int siwx91x_set_twt_setup(struct wifi_twt_params *params)
231231
{
232-
sl_status_t status;
233232
int twt_req_type = siwx91x_convert_z_sl_twt_req_type(params->setup_cmd);
234-
235233
sl_wifi_twt_request_t twt_req = {
236234
.twt_retry_interval = 5,
237235
.wake_duration_unit = 0,
@@ -245,6 +243,7 @@ static int siwx91x_set_twt_setup(struct wifi_twt_params *params)
245243
.twt_enable = 1,
246244
.req_type = twt_req_type,
247245
};
246+
int ret;
248247

249248
if (twt_req_type < 0) {
250249
params->fail_reason = WIFI_TWT_FAIL_CMD_EXEC_FAIL;
@@ -278,8 +277,8 @@ static int siwx91x_set_twt_setup(struct wifi_twt_params *params)
278277
twt_req.wake_duration = params->setup.twt_wake_interval / 256;
279278
}
280279

281-
status = sl_wifi_enable_target_wake_time(&twt_req);
282-
if (status != SL_STATUS_OK) {
280+
ret = sl_wifi_enable_target_wake_time(&twt_req);
281+
if (ret) {
283282
params->fail_reason = WIFI_TWT_FAIL_CMD_EXEC_FAIL;
284283
params->resp_status = WIFI_TWT_RESP_NOT_RECEIVED;
285284
return -EINVAL;
@@ -290,8 +289,8 @@ static int siwx91x_set_twt_setup(struct wifi_twt_params *params)
290289

291290
static int siwx91x_set_twt_teardown(struct wifi_twt_params *params)
292291
{
293-
sl_status_t status;
294292
sl_wifi_twt_request_t twt_req = { };
293+
int ret;
295294

296295
twt_req.twt_enable = 0;
297296

@@ -301,8 +300,8 @@ static int siwx91x_set_twt_teardown(struct wifi_twt_params *params)
301300
twt_req.twt_flow_id = params->flow_id;
302301
}
303302

304-
status = sl_wifi_disable_target_wake_time(&twt_req);
305-
if (status != SL_STATUS_OK) {
303+
ret = sl_wifi_disable_target_wake_time(&twt_req);
304+
if (ret) {
306305
params->fail_reason = WIFI_TWT_FAIL_CMD_EXEC_FAIL;
307306
params->teardown_status = WIFI_TWT_TEARDOWN_FAILED;
308307
return -EINVAL;

drivers/wifi/siwx91x/siwx91x_wifi_scan.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static void siwx91x_report_scan_res(struct siwx91x_dev *sidev, sl_wifi_scan_resu
3131
{ SL_WIFI_WPA_ENTERPRISE, WIFI_SECURITY_TYPE_EAP },
3232
{ SL_WIFI_WPA2_ENTERPRISE, WIFI_SECURITY_TYPE_EAP },
3333
};
34-
3534
struct wifi_scan_result tmp = {
3635
.channel = result->scan_info[item].rf_channel,
3736
.rssi = result->scan_info[item].rssi_val,
@@ -98,7 +97,7 @@ siwx91x_configure_scan_dwell_time(sl_wifi_scan_type_t scan_type, uint16_t dwell_
9897
uint16_t dwell_time_passive,
9998
sl_wifi_advanced_scan_configuration_t *advanced_scan_config)
10099
{
101-
int ret = 0;
100+
int ret;
102101

103102
if (dwell_time_active && (dwell_time_active < 5 || dwell_time_active > 1000)) {
104103
LOG_ERR("Invalid active scan dwell time");
@@ -114,14 +113,14 @@ siwx91x_configure_scan_dwell_time(sl_wifi_scan_type_t scan_type, uint16_t dwell_
114113
case SL_WIFI_SCAN_TYPE_ACTIVE:
115114
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
116115
dwell_time_active);
117-
break;
116+
return ret;
118117
case SL_WIFI_SCAN_TYPE_PASSIVE:
119118
if (!dwell_time_passive) {
120119
dwell_time_passive = SIWX91X_DEFAULT_PASSIVE_SCAN_DWELL_TIME;
121120
}
122121
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT,
123122
dwell_time_passive);
124-
break;
123+
return ret;
125124
case SL_WIFI_SCAN_TYPE_ADV_SCAN:
126125
__ASSERT(advanced_scan_config, "advanced_scan_config cannot be NULL");
127126

@@ -134,12 +133,10 @@ siwx91x_configure_scan_dwell_time(sl_wifi_scan_type_t scan_type, uint16_t dwell_
134133
dwell_time_passive = CONFIG_WIFI_SILABS_SIWX91X_ADV_PASSIVE_SCAN_DURATION;
135134
}
136135
advanced_scan_config->passive_channel_time = dwell_time_passive;
137-
break;
136+
return 0;
138137
default:
139-
break;
138+
return 0;
140139
}
141-
142-
return ret;
143140
}
144141

145142
int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_scan_config,
@@ -191,14 +188,14 @@ int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_scan_confi
191188
&advanced_scan_config);
192189

193190
ret = sl_wifi_set_advanced_scan_configuration(&advanced_scan_config);
194-
if (ret != SL_STATUS_OK) {
195-
LOG_ERR("advanced scan configuration failed with status %x", ret);
191+
if (ret) {
192+
LOG_ERR("Advanced scan configuration failed with status %x", ret);
196193
return -EINVAL;
197194
}
198195

199196
ret = sl_wifi_set_roam_configuration(interface, &roam_configuration);
200-
if (ret != SL_STATUS_OK) {
201-
LOG_ERR("roaming configuration failed with status %x", ret);
197+
if (ret) {
198+
LOG_ERR("Roaming configuration failed with status %x", ret);
202199
return -EINVAL;
203200
}
204201

@@ -219,7 +216,7 @@ int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_scan_confi
219216
z_scan_config->dwell_time_passive,
220217
NULL);
221218
}
222-
if (ret != SL_STATUS_OK) {
219+
if (ret) {
223220
LOG_ERR("Failed to configure timeout");
224221
return -EINVAL;
225222
}

drivers/wifi/siwx91x/siwx91x_wifi_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2023 Antmicro
3-
* Copyright (c) 2024 Silicon Laboratories Inc.
3+
* Copyright (c) 2024-2025 Silicon Laboratories Inc.
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <zephyr/net/net_offload.h>

drivers/wifi/siwx91x/siwx91x_wifi_sta.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ int siwx91x_disconnect(const struct device *dev)
196196
}
197197

198198
ret = sl_wifi_disconnect(interface);
199-
if (ret != SL_STATUS_OK) {
199+
if (ret) {
200200
wifi_mgmt_raise_disconnect_result_event(sidev->iface, ret);
201201
return -EIO;
202202
}
@@ -254,7 +254,7 @@ int siwx91x_connect(const struct device *dev, struct wifi_connect_req_params *pa
254254
};
255255
struct siwx91x_dev *sidev = dev->data;
256256
enum wifi_mfp_options mfp_conf;
257-
int ret = 0;
257+
int ret;
258258

259259
if (sidev->state == WIFI_STATE_COMPLETED) {
260260
ret = siwx91x_disconnect_if_required(dev, params);
@@ -311,9 +311,11 @@ int siwx91x_connect(const struct device *dev, struct wifi_connect_req_params *pa
311311
ret = sl_net_set_credential(SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID,
312312
SL_NET_WIFI_PSK, params->sae_password,
313313
params->sae_password_length);
314+
} else {
315+
ret = 0;
314316
}
315317

316-
if (ret != SL_STATUS_OK) {
318+
if (ret) {
317319
LOG_ERR("Failed to set credentials: 0x%x", ret);
318320
wifi_mgmt_raise_connect_result_event(sidev->iface, WIFI_STATUS_CONN_FAIL);
319321
return -EINVAL;

0 commit comments

Comments
 (0)