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 03A95CCA468 for ; Wed, 1 Jun 2022 13:52:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AE927842C3; Wed, 1 Jun 2022 15:51:33 +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="aGXa+4/S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1DD2084288; Wed, 1 Jun 2022 12:49:22 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 B78B183E81 for ; Wed, 1 Jun 2022 12:49:18 +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=1654080558; x=1685616558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9+lNmGJzt0PCBD5f/PAFXdSi7zMCH+HS4LiUCVDjCDs=; b=aGXa+4/SOgv5nfHv16s9aAukcLAjXz1IJde1flMIm87TvwakHHzxsR1E dqZ6l6Qmc/2IUtvWmzKl9niViE0pLLI2DgtXWyZkuuGPTQ0B8S1T8yi8N U0iD4tf1tIiAHI+VMbjfMDAuoFzWAJYQ1114DJHqSk5DO0qrpR/avkNM7 fQJIZ3MPJKSELysdq8imDTxSCbvKW+TDRd4NlCIltHnXA4BKIqmGBpPuK MN500juuMD/wwaDiTyG90EHV2iGNAC6I/N6UK9V798IPxPBSStjg9/Crg NDp+zXDnoYsbZ1fAgtpKV9lRRqK6hhxOZT3i0Uwsfhf3wTZqgYa8dXhoZ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="275556135" X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="275556135" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2022 03:49:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="633477765" Received: from pglc00514.png.intel.com ([10.221.239.206]) by fmsmga008.fm.intel.com with ESMTP; 01 Jun 2022 03:49:14 -0700 From: dinesh.maniyam@intel.com To: u-boot@lists.denx.de Cc: Marek Vasut , Simon Goldschmidt , Siew Chin Lim , Tien Fong Chee , Kok Kiang , Yau Wai , Sin Hui , Raaj , Dinesh Maniyam Subject: [PATCH v3] ddr: altera: soc64: Integer fix overflow that caused DDR size mismatched Date: Wed, 1 Jun 2022 18:49:02 +0800 Message-Id: <20220601104902.32240-1-dinesh.maniyam@intel.com> X-Mailer: git-send-email 2.19.0 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: Wed, 01 Jun 2022 15:51:12 +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 --- v3->v2 - copyright year updated and alignment updated. v2->v1 - add space in title --- drivers/ddr/altera/sdram_soc64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ddr/altera/sdram_soc64.c b/drivers/ddr/altera/sdram_soc64.c index d6baac2410..9b1710c135 100644 --- a/drivers/ddr/altera/sdram_soc64.c +++ b/drivers/ddr/altera/sdram_soc64.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (C) 2016-2021 Intel Corporation + * Copyright (C) 2016-2022 Intel Corporation * */ @@ -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.25.1