Skip to content

Commit b2056e0

Browse files
jukkarkartben
authored andcommitted
net: wifi_cred: Introduce variables at the start of function
Follow the net coding style and declare the variables at the start of the function. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 3aa0c86 commit b2056e0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

subsys/net/lib/wifi_credentials/wifi_credentials.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void wifi_credentials_uncache_ssid(size_t idx)
104104
int wifi_credentials_get_by_ssid_personal_struct(const char *ssid, size_t ssid_len,
105105
struct wifi_credentials_personal *buf)
106106
{
107+
ssize_t idx;
107108
int ret;
108109

109110
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
@@ -119,7 +120,7 @@ int wifi_credentials_get_by_ssid_personal_struct(const char *ssid, size_t ssid_l
119120

120121
k_mutex_lock(&wifi_credentials_mutex, K_FOREVER);
121122

122-
ssize_t idx = lookup_idx(ssid, ssid_len);
123+
idx = lookup_idx(ssid, ssid_len);
123124

124125
if (idx == -1) {
125126
LOG_DBG("Cannot retrieve WiFi credentials, no entry found for the provided SSID");
@@ -152,6 +153,7 @@ int wifi_credentials_get_by_ssid_personal_struct(const char *ssid, size_t ssid_l
152153

153154
int wifi_credentials_set_personal_struct(const struct wifi_credentials_personal *creds)
154155
{
156+
ssize_t idx;
155157
int ret;
156158

157159
if (creds == NULL) {
@@ -166,7 +168,7 @@ int wifi_credentials_set_personal_struct(const struct wifi_credentials_personal
166168

167169
k_mutex_lock(&wifi_credentials_mutex, K_FOREVER);
168170

169-
ssize_t idx = lookup_idx(creds->header.ssid, creds->header.ssid_len);
171+
idx = lookup_idx(creds->header.ssid, creds->header.ssid_len);
170172

171173
if (idx == -1) {
172174
idx = lookup_unused_idx();
@@ -199,6 +201,7 @@ int wifi_credentials_set_personal(const char *ssid, size_t ssid_len, enum wifi_s
199201
{
200202
int ret = 0;
201203
uint8_t buf[ENTRY_MAX_LEN] = {0};
204+
struct wifi_credentials_header *header;
202205

203206
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
204207
LOG_ERR("Cannot set WiFi credentials, SSID has invalid format");
@@ -219,7 +222,7 @@ int wifi_credentials_set_personal(const char *ssid, size_t ssid_len, enum wifi_s
219222
}
220223

221224
/* pack entry */
222-
struct wifi_credentials_header *header = (struct wifi_credentials_header *)buf;
225+
header = (struct wifi_credentials_header *)buf;
223226

224227
header->type = type;
225228
memcpy(header->ssid, ssid, ssid_len);
@@ -267,6 +270,7 @@ int wifi_credentials_get_by_ssid_personal(const char *ssid, size_t ssid_len,
267270
{
268271
int ret = 0;
269272
uint8_t buf[ENTRY_MAX_LEN] = {0};
273+
struct wifi_credentials_header *header;
270274

271275
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
272276
LOG_ERR("Cannot retrieve WiFi credentials, SSID has invalid format");
@@ -292,7 +296,7 @@ int wifi_credentials_get_by_ssid_personal(const char *ssid, size_t ssid_len,
292296
}
293297

294298
/* unpack entry*/
295-
struct wifi_credentials_header *header = (struct wifi_credentials_header *)buf;
299+
header = (struct wifi_credentials_header *)buf;
296300

297301
*type = header->type;
298302
*flags = header->flags;
@@ -327,6 +331,7 @@ int wifi_credentials_get_by_ssid_personal(const char *ssid, size_t ssid_len,
327331

328332
int wifi_credentials_delete_by_ssid(const char *ssid, size_t ssid_len)
329333
{
334+
ssize_t idx;
330335
int ret = 0;
331336

332337
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
@@ -335,7 +340,7 @@ int wifi_credentials_delete_by_ssid(const char *ssid, size_t ssid_len)
335340
}
336341

337342
k_mutex_lock(&wifi_credentials_mutex, K_FOREVER);
338-
ssize_t idx = lookup_idx(ssid, ssid_len);
343+
idx = lookup_idx(ssid, ssid_len);
339344

340345
if (idx == -1) {
341346
LOG_DBG("WiFi credentials entry was not found");

0 commit comments

Comments
 (0)