From patchwork Mon Jun 24 12:38:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 11012993 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 A4A541580 for ; Mon, 24 Jun 2019 12:38:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96CF628968 for ; Mon, 24 Jun 2019 12:38:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B35F289AD; Mon, 24 Jun 2019 12:38:28 +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=unavailable 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 3D73A28968 for ; Mon, 24 Jun 2019 12:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726453AbfFXMi2 (ORCPT ); Mon, 24 Jun 2019 08:38:28 -0400 Received: from andre.telenet-ops.be ([195.130.132.53]:56744 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728051AbfFXMi1 (ORCPT ); Mon, 24 Jun 2019 08:38:27 -0400 Received: from ramsan ([84.194.111.163]) by andre.telenet-ops.be with bizsmtp id UceQ2000M3XaVaC01ceQZz; Mon, 24 Jun 2019 14:38:25 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1hfOEq-0003kT-Gn; Mon, 24 Jun 2019 14:38:24 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1hfOEq-0005SP-Fh; Mon, 24 Jun 2019 14:38:24 +0200 From: Geert Uytterhoeven To: Vinod Koul , Dan Williams , Eugeniu Rosca Cc: Greg Kroah-Hartman , Jiri Slaby , Yoshihiro Shimoda , Wolfram Sang , linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, dmaengine@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] dmaengine: rcar-dmac: Reject zero-length slave DMA requests Date: Mon, 24 Jun 2019 14:38:18 +0200 Message-Id: <20190624123818.20919-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While the .device_prep_slave_sg() callback rejects empty scatterlists, it still accepts single-entry scatterlists with a zero-length segment. These may happen if a driver calls dmaengine_prep_slave_single() with a zero len parameter. The corresponding DMA request will never complete, leading to messages like: rcar-dmac e7300000.dma-controller: Channel Address Error happen and DMA timeouts. Although requesting a zero-length DMA request is a driver bug, rejecting it early eases debugging. Note that the .device_prep_dma_memcpy() callback already rejects requests to copy zero bytes. Reported-by: Eugeniu Rosca Analyzed-by: Yoshihiro Shimoda Signed-off-by: Geert Uytterhoeven --- See "[PATCH 0/2] serial: sh-sci: Fix .flush_buffer() issues" (https://lore.kernel.org/linux-renesas-soc/20190624123540.20629-1-geert+renesas@glider.be/) for the driver fix. drivers/dma/sh/rcar-dmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 67df54ac329400b7..9c41a4e425759fcc 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1165,7 +1165,7 @@ rcar_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); /* Someone calling slave DMA on a generic channel? */ - if (rchan->mid_rid < 0 || !sg_len) { + if (rchan->mid_rid < 0 || !sg_len || !sg_dma_len(sgl)) { dev_warn(chan->device->dev, "%s: bad parameter: len=%d, id=%d\n", __func__, sg_len, rchan->mid_rid);