Skip to content

Commit 1c5dc87

Browse files
committed
sys/log: Address review comments
1 parent f9fad8b commit 1c5dc87

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

sys/log/full/include/log/log_fcb.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ struct fcb_log {
133133
*
134134
* @param fcb_log The log to configure.
135135
* @param buf The buffer to use for bookmarks.
136-
* @param bmark_count The bookmark capacity of the supplied buffer.
136+
* @param avl_bmark_cnt The bookmark capacity of the supplied buffer,
137+
* available bookmark count
137138
* @param en_sect_bmarks Enable sector bookmarks
138139
*
139140
* @return 0 on success, non-zero on failure
140141
*/
141142
int log_fcb_init_bmarks(struct fcb_log *fcb_log,
142-
struct log_fcb_bmark *buf, int bmark_count,
143+
struct log_fcb_bmark *buf, int avl_bmark_cnt,
143144
bool en_sect_bmarks);
144145

145146
/** @brief Remove bookmarks which point to oldest FCB/FCB2 area. This is

sys/log/full/src/log_fcb_bmark.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ log_fcb_init_sector_bmarks(struct fcb_log *fcb_log)
4040

4141
rc = fcb_getnext(&fcb_log->fl_fcb, &loc);
4242
if (rc) {
43-
return -1;
43+
return rc;
4444
}
4545
#else
4646
struct flash_sector_range *range = NULL;
4747
struct fcb2_entry loc = {0};
4848

4949
rc = fcb2_getnext(&fcb_log->fl_fcb, &loc);
5050
if (rc) {
51-
return -1;
51+
return rc;
5252
}
5353
#endif
5454

@@ -71,10 +71,10 @@ log_fcb_init_sector_bmarks(struct fcb_log *fcb_log)
7171

7272
#if MYNEWT_VAL(LOG_FCB)
7373
j = 0;
74-
74+
fa = loc.fe_area;
7575
/* Keep skipping sectors until lfs_sect_bmark_itvl is reached */
7676
do {
77-
fa = fcb_getnext_area(&fcb_log->fl_fcb, loc.fe_area);
77+
fa = fcb_getnext_area(&fcb_log->fl_fcb, fa);
7878
if (!fa) {
7979
break;
8080
}
@@ -125,14 +125,14 @@ log_fcb_init_bmarks(struct fcb_log *fcb_log,
125125
bool en_sect_bmarks)
126126
{
127127
struct log_fcb_bset *bset = &fcb_log->fl_bset;
128+
/* Required bookmark count */
128129
int reqd_bmark_cnt = MYNEWT_VAL(LOG_FCB_NUM_ABS_BOOKMARKS);
129130

130131
(void)reqd_bmark_cnt;
131132
if (!bset || !buf || !avl_bmark_cnt) {
132133
return SYS_EINVAL;
133134
}
134135

135-
memset(bset, 0, sizeof(*bset));
136136
memset(buf, 0, sizeof(struct log_fcb_bmark) * avl_bmark_cnt);
137137

138138
*bset = (struct log_fcb_bset) {
@@ -146,10 +146,13 @@ log_fcb_init_bmarks(struct fcb_log *fcb_log,
146146
/* Default sector bookmark interval is 1 */
147147
bset->lfs_sect_bmark_itvl = 1;
148148
reqd_bmark_cnt += fcb_log->fl_fcb.f_sector_cnt;
149-
/* Make sure we have allocated the exact number of bookmarks */
149+
/* Make sure we have allocated the exact number of bookmarks
150+
* compare available bookmark count Vs required bookmark count
151+
*/
150152
if (avl_bmark_cnt < reqd_bmark_cnt) {
151153
/* Not enough space allocated for sector bookmarks,
152-
* add bookmarks at sector intervals */
154+
* add bookmarks at sector intervals
155+
*/
153156
bset->lfs_sect_bmark_itvl =
154157
fcb_log->fl_fcb.f_sector_cnt / avl_bmark_cnt;
155158
bset->lfs_sect_cap = avl_bmark_cnt -
@@ -158,9 +161,7 @@ log_fcb_init_bmarks(struct fcb_log *fcb_log,
158161
bset->lfs_sect_cap = fcb_log->fl_fcb.f_sector_cnt;
159162
}
160163
}
161-
#endif
162164

163-
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
164165
if (en_sect_bmarks) {
165166
return log_fcb_init_sector_bmarks(fcb_log);
166167
}
@@ -306,18 +307,17 @@ log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
306307

307308
bset = &fcb_log->fl_bset;
308309

309-
bset->lfs_bmarks[bset->lfs_next_sect] = (struct log_fcb_bmark) {
310-
.lfb_entry = *entry,
311-
.lfb_index = index,
312-
};
313-
314310
if (bset->lfs_size < fcb_log->fl_bset.lfs_sect_cap) {
311+
bset->lfs_bmarks[bset->lfs_next_sect] = (struct log_fcb_bmark) {
312+
.lfb_entry = *entry,
313+
.lfb_index = index,
314+
};
315+
315316
bset->lfs_size++;
316317
bset->lfs_next_sect = (bset->lfs_next_sect - 1) %
317318
fcb_log->fl_bset.lfs_sect_cap;
318-
} else {
319-
return -1;
320319
}
320+
321321
return 0;
322322
}
323323
#endif
@@ -337,8 +337,8 @@ log_fcb_replace_non_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry
337337

338338
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
339339
if (bset->lfs_en_sect_bmarks) {
340-
for (i = fcb_log->fl_fcb.f_sector_cnt;
341-
i < (bset->lfs_non_sect_size + fcb_log->fl_fcb.f_sector_cnt);
340+
for (i = bset->lfs_sect_cap;
341+
i < (bset->lfs_non_sect_size + bset->lfs_sect_cap);
342342
i++) {
343343
if (index == bset->lfs_bmarks[i].lfb_index) {
344344
/* If index matches, no need to replace */
@@ -375,28 +375,18 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
375375
#endif
376376
{
377377
struct log_fcb_bset *bset = &fcb_log->fl_bset;
378-
int i = 0;
379-
int pos = 0;
380-
bool en_sect_bmark = false;
381378
int rc = 0;
382379

383-
(void)i;
384-
(void)pos;
385-
386380
if (bset->lfs_cap == 0) {
387381
return SYS_ENOMEM;
388382
}
389383

390-
en_sect_bmark = sect_bmark & bset->lfs_en_sect_bmarks;
391-
(void)en_sect_bmark;
392-
393384
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
394-
if (en_sect_bmark) {
385+
if (sect_bmark & bset->lfs_en_sect_bmarks) {
395386
rc = log_fcb_insert_sect_bmark(fcb_log, entry, index);
396387
if (rc) {
397388
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "insert bmark failure: %u\n",
398389
index);
399-
return rc;
400390
}
401391
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "insert bmark index: %u, pos: %u\n",
402392
index, bset->lfs_next_sect);
@@ -405,11 +395,11 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
405395
rc = log_fcb_replace_non_sect_bmark(fcb_log, entry, index,
406396
bset->lfs_next_non_sect +
407397
(bset->lfs_en_sect_bmarks ?
408-
fcb_log->fl_fcb.f_sector_cnt : 0));
398+
bset->lfs_sect_cap : 0));
409399
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "replace bmark index: %u, pos: %u\n",
410400
index, bset->lfs_next_non_sect +
411401
(bset->lfs_en_sect_bmarks ?
412-
fcb_log->fl_fcb.f_sector_cnt : 0));
402+
bset->lfs_sect_cap : 0));
413403

414404
if (bset->lfs_non_sect_size < MYNEWT_VAL(LOG_FCB_NUM_ABS_BOOKMARKS)) {
415405
bset->lfs_non_sect_size++;

sys/log/full/src/log_shell.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,14 @@ shell_log_dump_cmd(int argc, char **argv)
281281
bmarks = log_fcb_get_bmarks(log, &bmarks_size);
282282
for (i = 0; i < bmarks_size; i++) {
283283
#if MYNEWT_VAL(LOG_FCB)
284-
console_printf("%u: index:%lu entry: %x fa: %x fe_elem_off: %lx\n", i,
284+
console_printf("%u: index:%lu fa: %x fe_elem_off: %lx\n", i,
285285
bmarks[i].lfb_index,
286-
(uintptr_t)&bmarks[i].lfb_entry,
287-
(uintptr_t)bmarks[i].lfb_entry.fe_area,
286+
(uintptr_t)bmarks[i].lfb_entry.fe_area.fa_off,
288287
bmarks[i].lfb_entry.fe_elem_off);
289288
#else
290-
console_printf("%u: index: %lu entry: %x fr: %x fe_sector: %x fe_data_off: %lx\n", i,
289+
console_printf("%u: index: %lu fr: %x fe_sector: %x fe_data_off: %lx\n", i,
291290
bmarks[i].lfb_index,
292-
(uintptr_t)&bmarks[i].lfb_entry,
293-
(uintptr_t)bmarks[i].lfb_entry.fe_range,
291+
(uintptr_t)bmarks[i].lfb_entry.fe_range.fsr_flash_area.fa_off,
294292
(uintptr_t)bmarks[i].lfb_entry.fe_sector,
295293
bmarks[i].lfb_entry.fe_data_off);
296294
#endif

0 commit comments

Comments
 (0)