From patchwork Wed Apr 24 05:21:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ley Foon Tan X-Patchwork-Id: 1089930 X-Patchwork-Delegate: marek.vasut@gmail.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=intel.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44ppbG0Wgmz9s3Z for ; Wed, 24 Apr 2019 15:22:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CAE6BC21DA1; Wed, 24 Apr 2019 05:21:57 +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=none 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 EE1FAC21D65; Wed, 24 Apr 2019 05:21:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 34E68C21D65; Wed, 24 Apr 2019 05:21:55 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lists.denx.de (Postfix) with ESMTPS id 54766C21C57 for ; Wed, 24 Apr 2019 05:21:54 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2019 22:21:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,388,1549958400"; d="scan'208";a="226164951" Received: from lftan-mobl.gar.corp.intel.com (HELO ubuntu) ([10.226.248.116]) by orsmga001.jf.intel.com with SMTP; 23 Apr 2019 22:21:48 -0700 Received: by ubuntu (sSMTP sendmail emulation); Wed, 24 Apr 2019 13:21:47 +0800 From: Ley Foon Tan To: u-boot@lists.denx.de Date: Wed, 24 Apr 2019 13:21:47 +0800 Message-Id: <1556083307-13117-1-git-send-email-ley.foon.tan@intel.com> X-Mailer: git-send-email 2.7.4 Cc: Marek Vasut , Chin Liang See , Chee Hong Ang Subject: [U-Boot] [PATCH v4] arm: socfpga: mailbox: Fix off-by-one error on command length checking 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" A mailbox command contains 1-u32 header + arguments. The "len" variable only contains the length of the arguments, but not the 1-u32 header. Include the length of header when checking the ring buffer space to prevent off-by-one error. Signed-off-by: Ley Foon Tan Signed-off-by: Chee Hong Ang Reviewed-by: Simon Goldschmidt --- v3->v4: - Change DWORD to u32 in commit message - Add note len is in u32 unit in code v2->v3: - Update commit description. --- arch/arm/mach-socfpga/mailbox_s10.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-socfpga/mailbox_s10.c b/arch/arm/mach-socfpga/mailbox_s10.c index 3c33223936..4498ab55df 100644 --- a/arch/arm/mach-socfpga/mailbox_s10.c +++ b/arch/arm/mach-socfpga/mailbox_s10.c @@ -55,11 +55,11 @@ static __always_inline int mbox_fill_cmd_circular_buff(u32 header, u32 len, cout = MBOX_READL(MBOX_COUT) % MBOX_CMD_BUFFER_SIZE; /* if command buffer is full or not enough free space - * to fit the data + * to fit the data. Note, len is in u32 unit. */ if (((cin + 1) % MBOX_CMD_BUFFER_SIZE) == cout || ((MBOX_CMD_BUFFER_SIZE - cin + cout - 1) % - MBOX_CMD_BUFFER_SIZE) < len) + MBOX_CMD_BUFFER_SIZE) < (len + 1)) return -ENOMEM; /* write header to circular buffer */