You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@mynewt.apache.org by "vrahane (via GitHub)" <gi...@apache.org> on 2025/04/16 20:56:49 UTC

[PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

vrahane opened a new pull request, #3413:
URL: https://github.com/apache/mynewt-core/pull/3413

   - Reboot was crash on rotate because the `l_arg` which points to the `fcb_log` was actually getting set to the `fcb`, thereby causing a crash. This fixes it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane commented on PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#issuecomment-2829043163

   Thanks @kasjer 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane merged PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane commented on code in PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#discussion_r2059357198


##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +933,21 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
-    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    /* Cache fcb_log pointer */
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings
+     */
+    memcpy(&fcb_log_tmp, log->l_arg, sizeof(struct fcb_log));
+    fcb_log_tmp.fl_fcb = *dst_fcb;

Review Comment:
   changed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "kasjer (via GitHub)" <gi...@apache.org>.
kasjer commented on code in PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#discussion_r2048347464


##########
sys/log/full/src/log_fcb.c:
##########
@@ -914,6 +914,8 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
     uint16_t hdr_len;
     int dlen;
     int rc;
+    struct fcb_log fcb_log_tmp = {0};

Review Comment:
   Initialization is not needed whole buffer will be overwritten later



##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +934,22 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
+    /* Cache fcb_log pointer */
     fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings
+     */
+    memcpy(&fcb_log_tmp, log->l_arg, sizeof(struct fcb_log));
+    fcb_log_tmp.fl_fcb = *dst_fcb;
+    log->l_arg = &fcb_log_tmp;
     rc = log_fcb_append(log, data, dlen);
-    log->l_arg = fcb_tmp;
+
+    /* Restore the original fcb_log pointer */
+    log->l_arg = fcb_log_ptr;
+    ((struct fcb_log *)log->l_arg)->fl_fcb = *fcb_tmp;

Review Comment:
   In current form `fcb_tmp` is not used for anything compiler will detect that this line is equivalent to
   ```c
     *fcb_tmp = *fcb_tmp;
   ```
   and will not generate code for assignment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane commented on code in PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#discussion_r2059357722


##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +933,21 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
-    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    /* Cache fcb_log pointer */
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings

Review Comment:
   The bookmarks do get rotated later on or re-inited incase of sector bookmarks. so, it is fine I think. I just removed the comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane commented on PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#issuecomment-2819191779

   @kasjer  Somehow, it worked on our board but was still crashing on the Nordic, but definitely a problem. I fixed it. Please review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "kasjer (via GitHub)" <gi...@apache.org>.
kasjer commented on code in PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#discussion_r2056797865


##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +933,21 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
-    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    /* Cache fcb_log pointer */
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings

Review Comment:
   Comment suggest that bookmark settings need to be preserved.
   It bookmarks can be affected by log_fcb_append() only part of bookmark data is preserved.
   log_fcb_bset as part of fcb_log would be preserved while elements of lfs_bmarks array could be modified.
   Finally fcl_log would have data intact but not in sync with bookmark array that could have pointer(s) to scratch area.



##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +933,21 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
-    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    /* Cache fcb_log pointer */
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings
+     */
+    memcpy(&fcb_log_tmp, log->l_arg, sizeof(struct fcb_log));
+    fcb_log_tmp.fl_fcb = *dst_fcb;

Review Comment:
   Those  two lines copy structures first line uses `memcpy()` second is using operator `=`
   More consistent would be to have
   ```c
   fcb_log_tmp = *fcb_log_ptr;
   fcb_log_tmp.fl_fcb = *dst_fcb;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "kasjer (via GitHub)" <gi...@apache.org>.
kasjer commented on PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#issuecomment-2812263899

   Test on **nucleo-f411re** and **noridic_pca10056**, application **slinky** with following syscfg.yml
   ```yml
   syscfg.vals:
       OS_DEBUG_MODE: 1
   ```
   
   When reboot log is filled boards end up in reboot loop (log from nucleo)
   ```
   000011 [ts=11000us, mod=6 level=4 ]{_ "rsn": "SOFT", "cnt": 1, "img": "25.4.17.105426", "hash": "909aca5b47e55e4feb81deee1afd01ede4aaaceb730f7361139bd01055b76c11", "flags": "active bootable confirmed"}
   000062 Assert @ 0x802fbf5
   000062 Unhandled interrupt (2), exception sp 0x20001368
   000062  r0:0x0000001a  r1:0x00000000  r2:0x80000000  r3:0xe000ed00
   000062  r4:0x00000000  r5:0x0802fbf5  r6:0x00000000  r7:0x0803241c
   000062  r8:0x200013dc  r9:0x20001454 r10:0x0000000f r11:0x00000000
   000062 r12:0x80000000  lr:0x080211f7  pc:0x080211ea psr:0x61000000
   000062 ICSR:0x0440f802 HFSR:0x00000000 CFSR:0x00000000
   000062 BFAR:0xe000ed38 MMFAR:0xe000ed34
   000062 task:main
   000062  0x2000138c: 0x0802fbf5
   000062  0x200013a4: 0x0802736f
   000062  0x200013ac: 0x0802f2f1
   000062  0x200013bc: 0x0803146b
   000062  0x20001434: 0x080314b7
   000062  0x20001444: 0x0803117b
   000062  0x2000153c: 0x0802fb67
   000062  0x20001554: 0x08027347
   000062  0x20001584: 0x0802fb67
   000062  0x2000159c: 0x08027347
   000062  0x200015a4: 0x0802f54f
   000062  0x200015dc: 0x080311b7
   000062  0x2000160c: 0x08031247
   000062  0x20001638: 0x08033950
   000062  0x20001684: 0x08031283
   000062  0x2000169c: 0x08031413
   000062  0x200016cc: 0x080228af
   000062  0x200016e4: 0x0802776b
   000062  0x200016f8: 0x080313d5
   000062  0x20001714: 0x08027905
   000062  0x2000171c: 0x08025bfb
   000062  0x20001734: 0x080328ac
   000062  0x20001754: 0x080284bb
   000062  0x20001764: 0x08028505
   000011 [ts=11000us, mod=6 level=4 ]{_ "rsn": "SOFT", "cnt": 1, "img": "25.4.17.105426", "hash": "909aca5b47e55e4feb81deee1afd01ede4aaaceb730f7361139bd01055b76c11", "flags": "active bootable confirmed"}
   000062 Assert @ 0x802fbf5
   000062 Unhandled interrupt (2), exception sp 0x20001368
   000062  r0:0x0000001a  r1:0x00000000  r2:0x80000000  r3:0xe000ed00
   000062  r4:0x00000000  r5:0x0802fbf5  r6:0x00000000  r7:0x0803241c
   000062  r8:0x200013dc  r9:0x20001454 r10:0x0000000f r11:0x00000000
   000062 r12:0x80000000  lr:0x080211f7  pc:0x080211ea psr:0x61000000
   000062 ICSR:0x0440f802 HFSR:0x00000000 CFSR:0x00000000
   000062 BFAR:0xe000ed38 MMFAR:0xe000ed34
   000062 task:main
   000062  0x2000138c: 0x0802fbf5
   000062  0x200013a4: 0x0802736f
   000062  0x200013ac: 0x0802f2f1
   000062  0x200013bc: 0x0803146b
   000062  0x20001434: 0x080314b7
   000062  0x20001444: 0x0803117b
   000062  0x2000153c: 0x0802fb67
   000062  0x20001554: 0x08027347
   000062  0x20001584: 0x0802fb67
   000062  0x2000159c: 0x08027347
   000062  0x200015a4: 0x0802f54f
   000062  0x200015dc: 0x080311b7
   000062  0x2000160c: 0x08031247
   000062  0x20001638: 0x08033950
   000062  0x20001684: 0x08031283
   000062  0x2000169c: 0x08031413
   000062  0x200016cc: 0x080228af
   000062  0x200016e4: 0x0802776b
   000062  0x200016f8: 0x080313d5
   000062  0x20001714: 0x08027905
   000062  0x2000171c: 0x08025bfb
   000062  0x20001734: 0x080328ac
   000062  0x20001754: 0x080284bb
   000062  0x20001764: 0x08028505
   000011 [ts=11000us, mod=6 level=4 ]{_ "rsn": "SOFT", "cnt": 1, "img": "25.4.17.105426", "hash": "909aca5b47e55e4feb81deee1afd01ede4aaaceb730f7361139bd01055b76c11", "flags": "active bootable confirmed"}
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "apc067 (via GitHub)" <gi...@apache.org>.
apc067 commented on PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#issuecomment-2810873445

   Seems to have worked for me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sys/reboot_log: Fix crash on rotate [mynewt-core]

Posted by "vrahane (via GitHub)" <gi...@apache.org>.
vrahane commented on code in PR #3413:
URL: https://github.com/apache/mynewt-core/pull/3413#discussion_r2052816168


##########
sys/log/full/src/log_fcb.c:
##########
@@ -932,12 +934,22 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
+    /* Cache fcb_log pointer */
     fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer and
+     * bookmark settings
+     */
+    memcpy(&fcb_log_tmp, log->l_arg, sizeof(struct fcb_log));
+    fcb_log_tmp.fl_fcb = *dst_fcb;
+    log->l_arg = &fcb_log_tmp;
     rc = log_fcb_append(log, data, dlen);
-    log->l_arg = fcb_tmp;
+
+    /* Restore the original fcb_log pointer */
+    log->l_arg = fcb_log_ptr;
+    ((struct fcb_log *)log->l_arg)->fl_fcb = *fcb_tmp;

Review Comment:
   Changed.



##########
sys/log/full/src/log_fcb.c:
##########
@@ -914,6 +914,8 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
     uint16_t hdr_len;
     int dlen;
     int rc;
+    struct fcb_log fcb_log_tmp = {0};

Review Comment:
   Removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org