From patchwork Thu May 5 13:29:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 67207 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp752058qge; Thu, 5 May 2016 06:32:29 -0700 (PDT) X-Received: by 10.98.49.133 with SMTP id x127mr18951902pfx.36.1462455148511; Thu, 05 May 2016 06:32:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xo3si11432674pac.215.2016.05.05.06.32.28; Thu, 05 May 2016 06:32:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757376AbcEENcS (ORCPT + 29 others); Thu, 5 May 2016 09:32:18 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35291 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756931AbcEENbr (ORCPT ); Thu, 5 May 2016 09:31:47 -0400 Received: by mail-wm0-f51.google.com with SMTP id e201so20715500wme.0 for ; Thu, 05 May 2016 06:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xjgWoOgznKI4jFN8lsn4qFFFLI30OKlkL7XcCJnWCHU=; b=B4Lp1BYYx0b2vyoOF9Q7miLrkXiKeCFniZcBxDqwG88UILv5yo0wOnk9k3JQPc0QIa Sr1yGNYPdDZkDS16x6Q+iFEvfq09srz/LYT6tu+b++I0HCJFWRQDooT7LIcvGpoiV7y/ 1I2yfkRGjmu2MomLN58Z5+9mQa9rGsyiZsdcE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xjgWoOgznKI4jFN8lsn4qFFFLI30OKlkL7XcCJnWCHU=; b=d/RPMOxQYCjyAe26M4nU0JL9m4fjZo0WGFy854ewZaiVl+qnWb49rkqNyI81issNaY DZ0IdYlGVl58gGcjpZjhskD7bz1igke2TDjKI8h8RIw46aBO0sEdA1SFluz9ji8PDOfZ aJszWRtxH1ayxO79wiacsCdPQcgTGlMRJZ6hraHBkGE9Ut2WcKI28cUVLw4gO+64coFk ILu2O0MOJe5XLtEk1Eo4J47Ie4RRWU9jVTxRaO9nxAB/HT44lc6uvfLvjMxsEftuawKz Z9AEeos3lAvAv0XYXpHZJQ17wlww/DgpDsbUWLd9Grik4sj0x8fG8og5PDfsVCQA648b RElA== X-Gm-Message-State: AOPr4FUbNMZQ3t5tLfiDHJFPN7l5RDMhzabuwgI2aCQsUGekwVtVb8YPYaW/l6p/FxM9Oeih X-Received: by 10.28.139.137 with SMTP id n131mr3416061wmd.13.1462455106216; Thu, 05 May 2016 06:31:46 -0700 (PDT) Received: from localhost.localdomain (host81-129-173-198.range81-129.btcentralplus.com. [81.129.173.198]) by smtp.gmail.com with ESMTPSA id lf9sm9776868wjc.44.2016.05.05.06.31.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 May 2016 06:31:45 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, ohad@wizery.com, bjorn.andersson@linaro.org, linux-remoteproc@vger.kernel.org, Lee Jones Subject: [PATCH 5/5] remoteproc: core: Clip carveout if it's too big Date: Thu, 5 May 2016 14:29:43 +0100 Message-Id: <1462454983-13168-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> References: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Carveout size is primarily extracted from the firmware binary. However, DT can over-ride this by providing a different (smaller) size. We're adding protection here to ensure the we only allocate the smaller of the two provided sizes in order to decrease the risk of clashes. Signed-off-by: Lee Jones --- drivers/remoteproc/remoteproc_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.8.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3d9798c..c3cad708 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -577,6 +577,7 @@ static int rproc_handle_carveout(struct rproc *rproc, struct rproc_mem_entry *carveout, *mapping; struct device *dev = &rproc->dev; struct device *dma_dev; + struct rproc_subdev *sub; dma_addr_t dma; void *va; int ret; @@ -600,6 +601,14 @@ static int rproc_handle_carveout(struct rproc *rproc, return -ENOMEM; dma_dev = rproc_subdev_lookup(rproc, "carveout"); + sub = dev_get_drvdata(dma_dev); + + if (rsc->len > resource_size(sub->res)) { + dev_warn(dev, "carveout too big (0x%x): clipping to 0x%x\n", + rsc->len, resource_size(sub->res)); + rsc->len = resource_size(sub->res); + } + va = dma_alloc_coherent(dma_dev, rsc->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, "dma_alloc_coherent err: %d\n", rsc->len);