Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 798A7C433F5 for ; Fri, 13 May 2022 12:13:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3911780818; Fri, 13 May 2022 14:13:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="B0+8Ac3v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7750B8058A; Fri, 13 May 2022 09:06:32 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 422CD82A57 for ; Fri, 13 May 2022 09:05:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dinesh.maniyam@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652425558; x=1683961558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YGvMqtQ4xWZ4ve2+rW2ed9e7h+EH74gko4+eYOXU7Cs=; b=B0+8Ac3vhF8qobi2Vjc3LJkQotFzexuHw1k2ps2RVIqN5Eu23uWv3SqF +QxTDwiUgw5g6+aoFfa0jSzpFcffe7OQwwnGWuBynTzFxW3MKB6uAiy3x 2iJ49MRgswiCSplickuPGTycNfEmpXBjD3ZFwjl7LrO/JJ9H7CtIgJIsk FGeTVTBMBb5wHiBHIlll36dGdTNB21NdQgqiwvEsUf3v+oJrHaISf5qAp ByYg0fiEiG5mxVFy9ZNEMDJ2eNzkteX2PmRUUrmS+b9qe71pgEOSgzmZR aqQBLosjZJUIRROvYSz9/FpQFnbXvoDwibhJM0hVKnm8jcWxTdtxf/lHX g==; X-IronPort-AV: E=McAfee;i="6400,9594,10345"; a="257782539" X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="257782539" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2022 00:05:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="567074075" Received: from pglc1230.png.intel.com ([10.221.139.25]) by orsmga007.jf.intel.com with ESMTP; 13 May 2022 00:05:49 -0700 From: dinesh.maniyam@intel.com To: u-boot@lists.denx.de Cc: Siew Chin Lim , Tien Fong Chee , Kok Kiang , Yau Wai , Sin Hui , Raaj , Dinesh Maniyam Subject: [PATCH v2] ddr: altera: soc64: Integer fix overflow that caused DDR size mismatched Date: Fri, 13 May 2022 15:05:24 +0800 Message-Id: <20220513070524.3642-1-dinesh.maniyam@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220510061533.22726-1-dinesh.maniyam@intel.com> References: <20220510061533.22726-1-dinesh.maniyam@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 13 May 2022 14:13:10 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean From: Dinesh Maniyam Convert the constant integer to 'phys_size_t' to avoid overflow when calculating the SDRAM size. Signed-off-by: Dinesh Maniyam --- v1->v2 - Add space in title --- drivers/ddr/altera/sdram_soc64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ddr/altera/sdram_soc64.c b/drivers/ddr/altera/sdram_soc64.c index d6baac2410..1f479c514d 100644 --- a/drivers/ddr/altera/sdram_soc64.c +++ b/drivers/ddr/altera/sdram_soc64.c @@ -239,7 +239,8 @@ phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat) { u32 dramaddrw = hmc_readl(plat, DRAMADDRW); - phys_size_t size = 1 << (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) + + phys_size_t size = (phys_size_t)1 << + (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_BANK_GRP_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_BANK_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) + -- 2.26.2