From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757373AbcEENcS (ORCPT ); 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 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 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(+) 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); -- 2.8.0