This is an automated email from Gerrit.

"Jan Matyas <jan.mat...@codasip.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/8023

-- gerrit

commit 9ebd67e5a889ac7741f0a633539a6efd21c8e4b5
Author: Jan Matyas <jan.mat...@codasip.com>
Date:   Wed Nov 29 10:31:31 2023 +0100

    breakpoints: Remove dead code - two "if" blocks
    
    Removed two "if" blocks from breakpoint.c whose condition could
    never be true (dead code) and replaced them by assertions.
    
    Also added few related comments.
    
    Change-Id: Iec7ef4288c6bfe7cf9778b93960fdfddb350df11
    Signed-off-by: Jan Matyas <jan.mat...@codasip.com>

diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c
index c39a980570..340254cc04 100644
--- a/src/target/breakpoints.c
+++ b/src/target/breakpoints.c
@@ -280,6 +280,8 @@ static int breakpoint_free(struct target *target, struct 
breakpoint *breakpoint_
        struct breakpoint **breakpoint_p = &target->breakpoints;
        int retval;
 
+       /* Locate the breakpoint and the preceding pointer to it.
+        * This is needed for deletion of the item from the linked list. */
        while (breakpoint) {
                if (breakpoint == breakpoint_to_remove)
                        break;
@@ -287,8 +289,9 @@ static int breakpoint_free(struct target *target, struct 
breakpoint *breakpoint_
                breakpoint = breakpoint->next;
        }
 
-       if (!breakpoint)
-               return ERROR_OK;
+       /* The item must be found, otherwise it is a bug in the caller:
+        * mismatch between "target" and "breakpoint_to_remove". */
+       assert(breakpoint);
 
        retval = target_remove_breakpoint(target, breakpoint);
        if (retval != ERROR_OK) {
@@ -387,6 +390,8 @@ static int watchpoint_free(struct target *target, struct 
watchpoint *watchpoint_
        struct watchpoint **watchpoint_p = &target->watchpoints;
        int retval;
 
+       /* Locate the watchpoint and the preceding pointer to it.
+        * This is needed for deletion of the item from the linked list. */
        while (watchpoint) {
                if (watchpoint == watchpoint_to_remove)
                        break;
@@ -394,8 +399,10 @@ static int watchpoint_free(struct target *target, struct 
watchpoint *watchpoint_
                watchpoint = watchpoint->next;
        }
 
-       if (!watchpoint)
-               return ERROR_OK;
+       /* The item must be found, otherwise it is a bug in the caller:
+        * mismatch between "target" and "watchpoint_to_remove". */
+       assert(watchpoint);
+
        retval = target_remove_watchpoint(target, watchpoint);
        if (retval != ERROR_OK) {
                LOG_TARGET_ERROR(target, "could not remove watchpoint #%d on 
this target",

-- 

Reply via email to