All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: u-boot@lists.denx.de, git@xilinx.com
Cc: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>,
	Michal Simek <monstr@monstr.eu>,
	T Karthik Reddy <t.karthik.reddy@xilinx.com>
Subject: [PATCH 03/10] xilinx: common: Change board_info[] handling
Date: Thu, 19 Aug 2021 13:19:42 +0200	[thread overview]
Message-ID: <00adc89800a60b092cddabc38c8321be60c099b8.1629371983.git.michal.simek@xilinx.com> (raw)
In-Reply-To: <cover.1629371983.git.michal.simek@xilinx.com>

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>
---

 board/xilinx/common/board.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index db9705c1b7e4..44c8aa5eefbb 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,
-- 
2.32.0


  parent reply	other threads:[~2021-08-19 11:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 11:19 [PATCH 00/10] xilinx: Add support for DTB reselection Michal Simek
2021-08-19 11:19 ` [PATCH 01/10] xilinx: fru: Replace spaces with \0 in detected name Michal Simek
2021-08-19 11:19 ` [PATCH 02/10] xilinx: Use variable for passing board_name Michal Simek
2021-08-19 11:19 ` Michal Simek [this message]
2021-08-19 11:19 ` [PATCH 04/10] xilinx: common: Free allocated structure Michal Simek
2021-08-19 11:19 ` [PATCH 05/10] xilinx: Add support for generic board detection Michal Simek
2021-08-19 11:19 ` [PATCH 06/10] xilinx: zynqmp: Check that DT is 64bit aligned Michal Simek
2021-08-19 11:19 ` [PATCH 07/10] Makefile: Align fit-dtb.blob and u-boot.itb by 64bits for 64bit systems Michal Simek
2021-08-19 15:56   ` Andre Przywara
2021-08-19 16:01     ` Michal Simek
2021-08-19 16:18       ` Tom Rini
2021-08-19 16:31         ` Michal Simek
2021-08-19 16:44           ` Tom Rini
2021-08-19 11:19 ` [PATCH 08/10] arm64: dts: Make sure that all DTBs are 64bit aligned " Michal Simek
2021-08-19 16:10   ` Andre Przywara
2021-08-19 16:34     ` Michal Simek
2021-08-19 11:19 ` [PATCH 09/10] xilinx: zynqmp: Generate different u-boot.itb for MULTI_DTB_FIT Michal Simek
2021-08-19 11:19 ` [PATCH 10/10] xilinx: common: Enabling generic function for DT reselection Michal Simek
2021-08-23  7:37 [PATCH 00/10] xilinx: Add support for DTB reselection Michal Simek
2021-08-23  7:37 ` [PATCH 03/10] xilinx: common: Change board_info[] handling Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00adc89800a60b092cddabc38c8321be60c099b8.1629371983.git.michal.simek@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=ashok.reddy.soma@xilinx.com \
    --cc=git@xilinx.com \
    --cc=monstr@monstr.eu \
    --cc=t.karthik.reddy@xilinx.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.