]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
flash: nor: use array size to constraint the loop
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 14 Jun 2025 12:02:25 +0000 (14:02 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 29 Jun 2025 07:31:37 +0000 (07:31 +0000)
Instead of using NULL terminated arrays to determine the last
element of the array, use the size of the array.

Change-Id: Ia3d739b0a9f201ba2e7b1d1244d60c8e5546c9c1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8947
Reviewed-by: Brandon Martin
Tested-by: jenkins
src/flash/nor/drivers.c

index 4f468848bca73615e0447b41e708882df21ae006..cb807ec62512b0c02c08ef959b4d23719fcb312f 100644 (file)
@@ -7,6 +7,8 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+
+#include <helper/types.h>
 #include "imp.h"
 
 /**
@@ -89,12 +91,11 @@ static const struct flash_driver * const flash_drivers[] = {
        &xcf_flash,
        &xmc1xxx_flash,
        &xmc4xxx_flash,
-       NULL,
 };
 
 const struct flash_driver *flash_driver_find_by_name(const char *name)
 {
-       for (unsigned int i = 0; flash_drivers[i]; i++) {
+       for (size_t i = 0; i < ARRAY_SIZE(flash_drivers); i++) {
                if (strcmp(name, flash_drivers[i]->name) == 0)
                        return flash_drivers[i];
        }