From patchwork Fri Aug 30 07:21:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iru Cai X-Patchwork-Id: 1155856 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aKROXl51"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46Kbvm0YJbz9sBp for ; Fri, 30 Aug 2019 20:54:25 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 55010C21D9A; Fri, 30 Aug 2019 10:54:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C9F44C21C3F; Fri, 30 Aug 2019 10:54:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0BD95C21C2F; Fri, 30 Aug 2019 07:21:51 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id 6E3C1C21C27 for ; Fri, 30 Aug 2019 07:21:50 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id u17so3079915pgi.6 for ; Fri, 30 Aug 2019 00:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=vaaJNRZIVoESTzss26YR9chRRWPLgUr+vH53Tdta8wY=; b=aKROXl51FwZWokL2cz3Q+gCiVQp+eVmEdYCGrw6xpH7DOChj5ba89cOeGgqOi45cwy k/8i6bX5cQrsjyJbin+e6rjwwTpJOOf2vGuG80RmrNyFMSoU9VZMJdrihsWFTNTGNM6N QJva7mmSezrqCh4uXq8PrtFLGBgR6MC5ELM1+1ELp50axWJMLbQwupxJUz2GAUO3Rqgj pR8HZ8g/EFfCNPkTjTRs+eF453FU5ngsOO1/LgbId28wA29nIUNfr1uOWJcqJPay9Xzg g7dHiXxJJGdLxGszrGU/uWLfYgI8AreUD3AKtz+0G+nV+f2oDQI4yHhAHEewbAXPkDTz /sJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=vaaJNRZIVoESTzss26YR9chRRWPLgUr+vH53Tdta8wY=; b=cSl/5hmDIAbcfnPfRVZpBa2wYwFvi72uwAluV8ikwaUA6nw+c9tRZkj8G/wA0R5+o7 s4w/AR/FBy/LlIBCDlJ/0wTU+dTp/N02deCRgUQi8VLY0mPFJyGwmq+RaH+0OsFXNza3 +rBy058pHhPdDWnM6FM2ODrB8fY1Nok2PTnYWmDsDKbKLEV/WJ0ptGW3t3XKnftIfTEf 46eab4u05vpBR+Iog96rbZoY19vLf8IJdvTscDELd2A+IwmG7fZkwVOlztFsxJwSifJ7 lMz/R6Qb+6GVjvaitoyGscOz3kLs7s++xBcj7lfLTB1U9JCN9RfmIZQJcIE3Acd45V5D 3J2g== X-Gm-Message-State: APjAAAWSRbyHxvDvi9W9yF66SWhpJbn6oFP3EvcLd/yOYivZOdWk5XMh eUl2yeLnpyZbWjKzDAWTb/DVyqS7 X-Google-Smtp-Source: APXvYqzg1jhSZHQJXEJe/iLqDxUdlCeFCEjg+bnBZdZd4ffSVZWifwOC3hD2BKdUE3nZqs97IMF1CA== X-Received: by 2002:aa7:9393:: with SMTP id t19mr15863752pfe.12.1567149708301; Fri, 30 Aug 2019 00:21:48 -0700 (PDT) Received: from localhost ([2408:84e1:106:7e72:b0b5:74e1:d671:ebbe]) by smtp.gmail.com with ESMTPSA id u1sm3667197pgi.28.2019.08.30.00.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2019 00:21:47 -0700 (PDT) Date: Fri, 30 Aug 2019 15:21:40 +0800 From: Iru Cai To: U-Boot@lists.denx.de Message-ID: <20190830072140.GA21544@mylaptop> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) X-Mailman-Approved-At: Fri, 30 Aug 2019 10:54:16 +0000 Subject: [U-Boot] [PATCH] common/memsize: panic if maxsize is not power of two X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The memory write and recover loop in get_ram_size() work correctly only if maxsize is power of two, otherwise the function will return a small size. Signed-off-by: Iru Cai --- common/memsize.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/memsize.c b/common/memsize.c index 13b0047786..f627149a05 100644 --- a/common/memsize.c +++ b/common/memsize.c @@ -33,6 +33,10 @@ long get_ram_size(long *base, long maxsize) long size; int i = 0; + if ((maxsize & (maxsize - 1)) != 0) { + panic("maxsize must be power of 2!"); + } + for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { addr = base + cnt; /* pointer arith! */ sync();