Skip to content

Commit 3c59bd4

Browse files
jukkarkartben
authored andcommitted
net: wifi_cred: Decrease flash usage for error print strings
As the error print strings are very similar, construct the final output at runtime to save some flash space. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 8deebce commit 3c59bd4

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

subsys/net/lib/wifi_credentials/wifi_credentials.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,27 @@ int wifi_credentials_get_by_ssid_personal_struct(const char *ssid, size_t ssid_l
108108
int ret;
109109

110110
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
111-
LOG_ERR("Cannot retrieve WiFi credentials, SSID has invalid format");
111+
LOG_ERR("Cannot %s WiFi credentials, %s", "retrieve", "SSID has invalid format");
112112
return -EINVAL;
113113
}
114114

115115
if (buf == NULL) {
116-
LOG_ERR("Cannot retrieve WiFi credentials, "
117-
"destination struct pointer cannot be NULL");
116+
LOG_ERR("Cannot %s WiFi credentials, %s", "retrieve", "destination is NULL");
118117
return -EINVAL;
119118
}
120119

121120
k_mutex_lock(&wifi_credentials_mutex, K_FOREVER);
122121

123122
idx = lookup_idx(ssid, ssid_len);
124123
if (idx == -1) {
125-
LOG_DBG("Cannot retrieve WiFi credentials, no entry found for the provided SSID");
124+
LOG_DBG("Cannot %s WiFi credentials, %s", "retrieve", "SSID not found");
126125
ret = -ENOENT;
127126
goto exit;
128127
}
129128

130129
ret = wifi_credentials_load_entry(idx, buf, sizeof(struct wifi_credentials_personal));
131130
if (ret) {
132-
LOG_ERR("Failed to load WiFi credentials at index %d, err: %d", idx, ret);
131+
LOG_ERR("Failed to %s WiFi credentials at index %d, err: %d", "load", idx, ret);
133132
goto exit;
134133
}
135134

@@ -155,12 +154,12 @@ int wifi_credentials_set_personal_struct(const struct wifi_credentials_personal
155154
int ret;
156155

157156
if (creds == NULL) {
158-
LOG_ERR("Cannot set WiFi credentials, provided struct pointer cannot be NULL");
157+
LOG_ERR("Cannot %s WiFi credentials, %s", "set", "credential not set");
159158
return -EINVAL;
160159
}
161160

162161
if (creds->header.ssid_len > WIFI_SSID_MAX_LEN || creds->header.ssid_len == 0) {
163-
LOG_ERR("Cannot set WiFi credentials, SSID has invalid format");
162+
LOG_ERR("Cannot %s WiFi credentials, %s", "set", "SSID has invalid format");
164163
return -EINVAL;
165164
}
166165

@@ -170,15 +169,15 @@ int wifi_credentials_set_personal_struct(const struct wifi_credentials_personal
170169
if (idx == -1) {
171170
idx = lookup_unused_idx();
172171
if (idx == -1) {
173-
LOG_ERR("Cannot store WiFi credentials, no space left");
172+
LOG_ERR("Cannot %s WiFi credentials, %s", "store", "no space left");
174173
ret = -ENOBUFS;
175174
goto exit;
176175
}
177176
}
178177

179178
ret = wifi_credentials_store_entry(idx, creds, sizeof(struct wifi_credentials_personal));
180179
if (ret) {
181-
LOG_ERR("Failed to store WiFi credentials at index %d, err: %d", idx, ret);
180+
LOG_ERR("Failed to %s WiFi credentials at index %d, err: %d", "store", idx, ret);
182181
goto exit;
183182
}
184183

@@ -200,20 +199,21 @@ int wifi_credentials_set_personal(const char *ssid, size_t ssid_len, enum wifi_s
200199
struct wifi_credentials_header *header;
201200

202201
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
203-
LOG_ERR("Cannot set WiFi credentials, SSID has invalid format");
202+
LOG_ERR("Cannot %s WiFi credentials, %s", "set", "SSID has invalid format");
204203
return -EINVAL;
205204
}
206205

207206
if (flags & WIFI_CREDENTIALS_FLAG_BSSID &&
208207
(bssid_len != WIFI_MAC_ADDR_LEN || bssid == NULL)) {
209-
LOG_ERR("Cannot set WiFi credentials, "
210-
"provided flags indicated BSSID, but no BSSID provided");
208+
LOG_ERR("Cannot %s WiFi credentials, %s", "set",
209+
"provided flags indicated BSSID but no BSSID provided");
211210
return -EINVAL;
212211
}
213212

214213
if ((type != WIFI_SECURITY_TYPE_NONE && (password_len == 0 || password == NULL)) ||
215214
(password_len > WIFI_CREDENTIALS_MAX_PASSWORD_LEN)) {
216-
LOG_ERR("Cannot set WiFi credentials, password not provided or invalid");
215+
LOG_ERR("Cannot %s WiFi credentials, %s", "set",
216+
"password not provided or invalid");
217217
return -EINVAL;
218218
}
219219

@@ -246,9 +246,8 @@ int wifi_credentials_set_personal(const char *ssid, size_t ssid_len, enum wifi_s
246246
break;
247247
}
248248
default:
249-
LOG_ERR("Cannot set WiFi credentials, "
250-
"provided security type %d is unsupported",
251-
type);
249+
LOG_ERR("Cannot %s WiFi credentials, provided security type %d is unsupported",
250+
"set", type);
252251
return -ENOTSUP;
253252
}
254253

@@ -269,18 +268,18 @@ int wifi_credentials_get_by_ssid_personal(const char *ssid, size_t ssid_len,
269268
struct wifi_credentials_header *header;
270269

271270
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
272-
LOG_ERR("Cannot retrieve WiFi credentials, SSID has invalid format");
271+
LOG_ERR("Cannot %s WiFi credentials, %s", "retrieve", "SSID has invalid format");
273272
return -EINVAL;
274273
}
275274

276275
if (bssid_buf_len != WIFI_MAC_ADDR_LEN || bssid_buf == NULL) {
277-
LOG_ERR("BSSID buffer needs to be provided");
276+
LOG_ERR("%s buffer needs to be provided", "BSSID");
278277
return -EINVAL;
279278
}
280279

281280
if (password_buf == NULL || password_buf_len > WIFI_CREDENTIALS_MAX_PASSWORD_LEN ||
282281
password_buf_len == 0) {
283-
LOG_ERR("WiFi password buffer needs to be provided");
282+
LOG_ERR("%s buffer needs to be provided", "WiFi password");
284283
return -EINVAL;
285284
}
286285

@@ -318,7 +317,7 @@ int wifi_credentials_get_by_ssid_personal(const char *ssid, size_t ssid_len,
318317
break;
319318
}
320319
default:
321-
LOG_ERR("Cannot get WiFi credentials, "
320+
LOG_ERR("Cannot %s WiFi credentials, %s", "get",
322321
"the requested credentials have invalid WIFI_SECURITY_TYPE");
323322
ret = -EPROTO;
324323
}
@@ -331,7 +330,7 @@ int wifi_credentials_delete_by_ssid(const char *ssid, size_t ssid_len)
331330
int ret = 0;
332331

333332
if (ssid == NULL || ssid_len > WIFI_SSID_MAX_LEN || ssid_len == 0) {
334-
LOG_ERR("Cannot delete WiFi credentials, SSID has invalid format");
333+
LOG_ERR("Cannot %s WiFi credentials, %s", "delete", "SSID has invalid format");
335334
return -EINVAL;
336335
}
337336

@@ -345,7 +344,7 @@ int wifi_credentials_delete_by_ssid(const char *ssid, size_t ssid_len)
345344

346345
ret = wifi_credentials_delete_entry(idx);
347346
if (ret) {
348-
LOG_ERR("Failed to delete WiFi credentials index %d, err: %d", idx, ret);
347+
LOG_ERR("Failed to %s WiFi credentials index %d, err: %d", "delete", idx, ret);
349348
goto exit;
350349
}
351350

@@ -393,8 +392,8 @@ int wifi_credentials_delete_all(void)
393392
if (is_entry_used(i)) {
394393
ret = wifi_credentials_delete_entry(i);
395394
if (ret) {
396-
LOG_ERR("Failed to delete WiFi credentials index %d, err: %d", i,
397-
ret);
395+
LOG_ERR("Failed to %s WiFi credentials index %d, err: %d",
396+
"delete", i, ret);
398397
break;
399398
}
400399

0 commit comments

Comments
 (0)