diff options
author | Michal Simek <michal.simek@xilinx.com> | 2021-08-12 12:30:36 +0200 |
---|---|---|
committer | Michal Simek <michal.simek@xilinx.com> | 2021-08-26 08:14:43 +0200 |
commit | d9c93c9e2c53e5b624e79b9ba244f84b5c73544b (patch) | |
tree | 6507255f0a054eb767d5f4efc92d75433883ccf9 /board | |
parent | 57f710320fcd18bb5deaa9654dbce4da4de9d987 (diff) | |
download | u-boot-d9c93c9e2c53e5b624e79b9ba244f84b5c73544b.tar.gz u-boot-d9c93c9e2c53e5b624e79b9ba244f84b5c73544b.tar.bz2 u-boot-d9c93c9e2c53e5b624e79b9ba244f84b5c73544b.zip |
xilinx: common: Change board_info[] handling
Origin code was allocating only pointers to struct xilinx_board_description
and there was separate allocation for structure self and freeing in case of
failure.
The code is directly allocating space for all structures by one calloc to
simlify logic.
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Diffstat (limited to 'board')
-rw-r--r-- | board/xilinx/common/board.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index db9705c1b7..44c8aa5eef 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -68,7 +68,7 @@ struct xilinx_board_description { }; static int highest_id = -1; -static struct xilinx_board_description **board_info; +static struct xilinx_board_description *board_info; #define XILINX_I2C_DETECTION_BITS sizeof(struct fru_common_hdr) @@ -280,7 +280,7 @@ static int xilinx_read_eeprom_single(char *name, __maybe_unused int xilinx_read_eeprom(void) { - int id, ret; + int id; char name_buf[8]; /* 8 bytes should be enough for nvmem+number */ struct xilinx_board_description *desc; @@ -289,7 +289,7 @@ __maybe_unused int xilinx_read_eeprom(void) if (highest_id < 0) return -EINVAL; - board_info = calloc(1, sizeof(desc) * highest_id); + board_info = calloc(1, sizeof(*desc) * (highest_id + 1)); if (!board_info) return -ENOMEM; @@ -300,21 +300,10 @@ __maybe_unused int xilinx_read_eeprom(void) snprintf(name_buf, sizeof(name_buf), "nvmem%d", id); /* Alloc structure */ - desc = board_info[id]; - if (!desc) { - desc = calloc(1, sizeof(*desc)); - if (!desc) - return -ENOMEM; - - board_info[id] = desc; - } + desc = &board_info[id]; /* Ignoring return value for supporting multiple chips */ - ret = xilinx_read_eeprom_single(name_buf, desc); - if (ret) { - free(desc); - board_info[id] = NULL; - } + xilinx_read_eeprom_single(name_buf, desc); } /* @@ -400,7 +389,7 @@ int board_late_init_xilinx(void) ret |= env_set_addr("bootm_size", (void *)bootm_size); for (id = 0; id <= highest_id; id++) { - desc = board_info[id]; + desc = &board_info[id]; if (desc && desc->header == EEPROM_HEADER_MAGIC) { if (desc->manufacturer[0]) ret |= env_set_by_index("manufacturer", id, |