From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A59C4338F for ; Thu, 19 Aug 2021 11:20:16 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17652610D2 for ; Thu, 19 Aug 2021 11:20:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 17652610D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6D1D82ECC; Thu, 19 Aug 2021 13:20:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="lYeMaK5p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 07B808312A; Thu, 19 Aug 2021 13:20:06 +0200 (CEST) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 81AE282C39 for ; Thu, 19 Aug 2021 13:19:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-wr1-x431.google.com with SMTP id l11so8555853wrx.4 for ; Thu, 19 Aug 2021 04:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rreRs7Fj/CMic/fizzfPpBJD6IcXNKbGilPh+ECeZLc=; b=lYeMaK5p0MHE1ULpfq1I//1JsLY6XUD4wYwgm3QlPtwyOHxApRiJweika8TOMSocRI hZO/kRR4lQWWS7x7oLmCNn3eBUTqXRnj5hVrD2zF+5G9NVPdClhi4bgGlYM7kImSu+MV EAMpD5/UVUXuJsFdKDIXoAg66V/lVrCJ1pYfy/E82cUynaw+xGBNCKOys5VldwQ1Dtmr X0fctziFkLDRa9yksZFcWe9r9tM4jc9QdZRlIN809zHVWZocl0V1cvMJGo9pnnmLMPP2 CbN38DlXtfzhx48xRdYt1cJmnfDdlfs0p3z5OBeN30X+WR4R9uWXAGESV/oM0ZRzPpMQ 3slg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rreRs7Fj/CMic/fizzfPpBJD6IcXNKbGilPh+ECeZLc=; b=UdvTPkpcntsYUtGtt7j/CQP4+kvyRrD7y7HQK/Fld54SCVod61cGMI6CyFL/LYIg7v nD1Te4YcTcdE8rp2XaEhcdacmihR/qG9U8tbEf5f8/YwgradqDTcy9DNFQkmIq20oAtA ZQiKAHErzvia8cV4OeYr6VYFe0pF309gkH45N6eRaCby+BJzk8d8LADR3DKa+ui+KxoQ +wB9jtemXHBZvfVOi75Yn903uBo3u1McHDwRLU2nBXDQDQoEMe//Kw3LyLqjTywQ4m4G YKbDFJUAq2Hkqo/tEFUTtTKLmF5T/g+YwD9W4RUMDArtxwba1+r8MN2Edi/YcTgyZogN KgIQ== X-Gm-Message-State: AOAM531C4twHeb+V0cm03LQjdfbkXoPnkqa4yFpY/ojLZqnf/NX+cxPF 4mRXKcBL4h9ZbyT8Rb2Jg4n2NKoNh7AFNWfl X-Google-Smtp-Source: ABdhPJwwWg9TBfG8PBI7/NYfLhjAAJhWJeM87JotdhJm2L0o/8OadFGd0PKe9FyUsv8w+nA6cUjgfQ== X-Received: by 2002:adf:fb8f:: with SMTP id a15mr3220156wrr.92.1629371998874; Thu, 19 Aug 2021 04:19:58 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6:f666:9af6:3fed:e53b]) by smtp.gmail.com with ESMTPSA id p14sm7450673wmi.42.2021.08.19.04.19.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Aug 2021 04:19:58 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Ashok Reddy Soma , Michal Simek , T Karthik Reddy Subject: [PATCH 03/10] xilinx: common: Change board_info[] handling Date: Thu, 19 Aug 2021 13:19:42 +0200 Message-Id: <00adc89800a60b092cddabc38c8321be60c099b8.1629371983.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 --- 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