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 C26B3C4332F for ; Wed, 23 Nov 2022 14:34:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CC5BB8551C; Wed, 23 Nov 2022 15:34:53 +0100 (CET) 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="jD7ODz8y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1814D852CC; Wed, 23 Nov 2022 15:34:52 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 9EECD854B4 for ; Wed, 23 Nov 2022 15:34:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=jitloonl@ecsmtp.png.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669214089; x=1700750089; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=lJPLXoxCpqOY1pQwbJWfcNBm27hOoR+cvYyZ1z2mWHc=; b=jD7ODz8y4vezvwc4Dq4Fpy75ECDA80qW7oKCPuZk1tboLAdK9xWZOzaY hBc00v2TgbLkzBC6gwOeVpWgdhB7bDBmOvUfPw3N19nZSAIrA6zB34Jo+ QsIlBkdIxB8UgJthXA+sq4shvty1iql9Z4dcB9YJw3fLWiHP1+pX8+djt 0iesQvFBGjWgTyzaFWB6MvD5adWLd1ow15lMGnqEqt9spTzyiijlIFyNn o/TXRoNPVwCI5HEKBFIt+09T5zc/aaNG0QhkgFlhcrhgaYI/+TgXU5ctt iCf/FeXzR8APu70tiKH40hjP0fMXrbDJiJV7cXi+5t+LJKrOaVE6LDfN5 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="294466122" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="294466122" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2022 06:34:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="970879754" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="970879754" Received: from pglmail07.png.intel.com ([10.221.193.207]) by fmsmga005.fm.intel.com with ESMTP; 23 Nov 2022 06:34:43 -0800 Received: from localhost (pgli0028.png.intel.com [10.221.84.177]) by pglmail07.png.intel.com (Postfix) with ESMTP id 4E76D482B; Wed, 23 Nov 2022 22:34:43 +0800 (+08) Received: by localhost (Postfix, from userid 12048045) id 4AC34E0095B; Wed, 23 Nov 2022 22:34:43 +0800 (+08) From: Jit Loon Lim To: u-boot@lists.denx.de Cc: Jagan Teki , Vignesh R , Marek , Simon , Tien Fong , Kok Kiang , Siew Chin , Sin Hui , Raaj , Dinesh , Boon Khai , Alif , Teik Heng , Hazim , Jit Loon Lim , Sieu Mun Tang Subject: [PATCH] ddr: altera: n5x: Ensure correct size of result for correct type casting Date: Wed, 23 Nov 2022 22:34:42 +0800 Message-Id: <20221123143442.19128-1-jit.loon.lim@intel.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean From: Tien Fong Chee Klockwork reported there is potential value overflow with incorrect typecast, but this is not valid in this arithmetic implementation because result is never over 32-bit size. The code is improved to ensure correct size of result returned with correct type casting for the sake of good coding practice. Signed-off-by: Tien Fong Chee Signed-off-by: Jit Loon Lim --- drivers/ddr/altera/sdram_n5x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ddr/altera/sdram_n5x.c b/drivers/ddr/altera/sdram_n5x.c index 72c231b3f1..0e944b7a15 100644 --- a/drivers/ddr/altera/sdram_n5x.c +++ b/drivers/ddr/altera/sdram_n5x.c @@ -2898,9 +2898,9 @@ int sdram_mmr_init_full(struct udevice *dev) * subsystem in complete reset state before init DDR clock * and DDR controller */ - ret = wait_for_bit_le32((const void *)((uintptr_t)(readl + ret = wait_for_bit_le32((const void *)((uintptr_t)readl (ddr_handoff_info.mem_reset_base) + - MEM_RST_MGR_STATUS)), + MEM_RST_MGR_STATUS), MEM_RST_MGR_STATUS_RESET_COMPLETE, true, TIMEOUT_200MS, false); if (ret) { @@ -2923,8 +2923,8 @@ int sdram_mmr_init_full(struct udevice *dev) /* Release the controller from reset */ setbits_le32((uintptr_t) - (readl(ddr_handoff_info.mem_reset_base) + - MEM_RST_MGR_STATUS), MEM_RST_MGR_STATUS_AXI_RST | + readl(ddr_handoff_info.mem_reset_base) + + MEM_RST_MGR_STATUS, MEM_RST_MGR_STATUS_AXI_RST | MEM_RST_MGR_STATUS_CONTROLLER_RST | MEM_RST_MGR_STATUS_RESET_COMPLETE); -- 2.26.2