From patchwork Fri Jul 27 08:44:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10546743 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F025112B for ; Fri, 27 Jul 2018 08:44:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 911972B6D3 for ; Fri, 27 Jul 2018 08:44:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 857522B6E1; Fri, 27 Jul 2018 08:44:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F08392B6D3 for ; Fri, 27 Jul 2018 08:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730291AbeG0KFs (ORCPT ); Fri, 27 Jul 2018 06:05:48 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:34316 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730290AbeG0KFr (ORCPT ); Fri, 27 Jul 2018 06:05:47 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by baptiste.telenet-ops.be with bizsmtp id Fkkr1y00c3XaVaC01kkrJ9; Fri, 27 Jul 2018 10:44:53 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1fiyMl-0000f8-F9; Fri, 27 Jul 2018 10:44:51 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1fiyMl-0003eM-Cu; Fri, 27 Jul 2018 10:44:51 +0200 From: Geert Uytterhoeven To: Dan Williams , Vinod Koul Cc: Laurent Pinchart , Yoshihiro Shimoda , dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] dmaengine: rcar-dmac: Make rcar_dmac_of_xlate() more robust Date: Fri, 27 Jul 2018 10:44:47 +0200 Message-Id: <20180727084447.13984-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an upper bound check for the MID/RID value passed from DT via the DMA spec. This avoids writing to reserved bits in the DMARS registers in case of an out-of-range value in DT. Suggested-by: Renesas BSP team via Yoshihiro Shimoda Signed-off-by: Geert Uytterhoeven --- drivers/dma/sh/rcar-dmac.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 72572320208dbb9a..73cf1053bed90244 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1644,8 +1644,11 @@ static struct dma_chan *rcar_dmac_of_xlate(struct of_phandle_args *dma_spec, struct dma_chan *chan; dma_cap_mask_t mask; - if (dma_spec->args_count != 1) + if (dma_spec->args_count != 1 || dma_spec->args[0] > 0xff) { + pr_info("%s: invalid MID/RID 0x%x... for %pOF\n", __func__, + dma_spec->args[0], dma_spec->np); return NULL; + } /* Only slave DMA channels can be allocated via DT */ dma_cap_zero(mask);