mirror of
https://github.com/openocd-org/openocd.git
synced 2025-10-15 04:28:44 +08:00
flash: nand: use array size to constraint the loop
Instead of using NULL terminated arrays to determine the last element of the array, use the size of the array. Change-Id: I532a51a223061348e57bae3bd66ee6b346c1b070 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8949 Tested-by: jenkins Reviewed-by: Brandon Martin
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <helper/types.h>
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
|
|
||||||
@@ -29,12 +31,11 @@ static struct nand_flash_controller *nand_flash_controllers[] = {
|
|||||||
&s3c2440_nand_controller,
|
&s3c2440_nand_controller,
|
||||||
&s3c2443_nand_controller,
|
&s3c2443_nand_controller,
|
||||||
&s3c6400_nand_controller,
|
&s3c6400_nand_controller,
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nand_flash_controller *nand_driver_find_by_name(const char *name)
|
struct nand_flash_controller *nand_driver_find_by_name(const char *name)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; nand_flash_controllers[i]; i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(nand_flash_controllers); i++) {
|
||||||
struct nand_flash_controller *controller = nand_flash_controllers[i];
|
struct nand_flash_controller *controller = nand_flash_controllers[i];
|
||||||
if (strcmp(name, controller->name) == 0)
|
if (strcmp(name, controller->name) == 0)
|
||||||
return controller;
|
return controller;
|
||||||
@@ -43,7 +44,7 @@ struct nand_flash_controller *nand_driver_find_by_name(const char *name)
|
|||||||
}
|
}
|
||||||
int nand_driver_walk(nand_driver_walker_t f, void *x)
|
int nand_driver_walk(nand_driver_walker_t f, void *x)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; nand_flash_controllers[i]; i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(nand_flash_controllers); i++) {
|
||||||
int retval = (*f)(nand_flash_controllers[i], x);
|
int retval = (*f)(nand_flash_controllers[i], x);
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
Reference in New Issue
Block a user