From patchwork Wed Sep 23 12:17:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 11794941 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 082CA92C for ; Wed, 23 Sep 2020 12:19:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC69421D92 for ; Wed, 23 Sep 2020 12:19:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="il40ckuR"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="jddCJg5m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC69421D92 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=E/emGp4x0P7Fh4k2s89OcfdXi8tNzLrESFdGWDA5zfs=; b=il40ckuRiv77n+BCv8kjmv2HE+ cxOdTYgBMt0dEK2d8KSImIYjh13D6bZ2ysA/VTuId8pCzgrQsLTPCk+jTvU5/vAKYcivRBOLi6l0T WqKaI/nNT5LttsB9y1MCKDmvg95lKLb+OSvL4S7cUCpv1CDoudOIrJ1jshmU22gt5/00wGcQLAM3z KNaeH0FEOW3xFP5v4zHbLBvkrKwoqjwAnfpnfOq/k66bDsDhz8SXTi8kszhhjiAhX5iPKbZvYNFgw Qfwx4JJbtgdNznzImja++cLvhLhgrPBEUBQ6RSiSwu98DUpZ72/RopHSLHxmZNX+Xt5Ss19MVyDWv CC5/XwDg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL3il-00026d-Of; Wed, 23 Sep 2020 12:18:03 +0000 Received: from esa5.microchip.iphmx.com ([216.71.150.166]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL3ih-00025p-UY for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 12:18:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1600863480; x=1632399480; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=QmuxF1k6JrlZgiNhVt0KMHpx0TS8HpqXkv0zvHy4YP4=; b=jddCJg5mGfsUHWZNb4O2+0OV/95reML0ghH83GdOucau3gVA63daopcb MZW20+FSDWP6hvKj8QonojbfaShHb7mF31osZ+naTJJPzn4qY9lhzfd0d ITB7nbzB+ysbSdaKhwSvAr8DKJxeIWCQkmo+9for1gds5nfwk2DOMlS4G LOLsx1f3C+AARuivARCrgVZf/UuRoO4Q2WEikHQIMdKyMYMRjtCEZrrPQ kWUp55pCQJNDRo849kc0M1fqmlU0a4zyFMqDJmnzMUhmEwtQCCdBXV+ju k+HxgBGeYgqqudxhx/Vc9C8OZeTQtXuW8DUs9hwlUj2yMYo1j6RQcUBXu A==; IronPort-SDR: fjcb6KWeS9NeUAPNPl/nN/NLjSpbTnZei5ymP1HDxx6lRKrG50OQTwp2KgNaRbf8CSfPsgkybx Eam5i78MzduCr8RtPKel9XAkI+uO1vBdNaBLG8JfDI6wfOMEV5E4EwyC6qTzcJ2yQv/XCx1PqK h6/Guf524PLoA83Fnl62A3Nl9NjBVNmetZObd69J8Op8Pg+a2ROBOLHu+Vdoiu0Yf6IV3fKYMk oKl87jXDwYFaV3I33jQGs//NJ0DcgqE/oKxOa7fZmvjr1wapdwkjbIeRtsTvcI/cvJHVatYFw2 sPg= X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="92080952" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 23 Sep 2020 05:17:57 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 23 Sep 2020 05:17:37 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 23 Sep 2020 05:17:52 -0700 From: Eugen Hristev To: , Subject: [PATCH v2] iio: adc: at91-sama5d2_adc: fix DMA conversion crash Date: Wed, 23 Sep 2020 15:17:48 +0300 Message-ID: <20200923121748.49384-1-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_081800_191669_93052836 X-CRM114-Status: GOOD ( 17.99 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.150.166 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [216.71.150.166 listed in wl.mailspike.net] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, Eugen Hristev , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org After the move of the postenable code to preenable, the DMA start was done before the DMA init, which is not correct. The DMA is initialized in set_watermark. Because of this, we need to call the DMA start functions in set_watermark, after the DMA init, instead of preenable hook, when the DMA is not properly setup yet. Fixes: f3c034f61775 ("iio: at91-sama5d2_adc: adjust iio_triggered_buffer_{predisable,postenable} positions") Signed-off-by: Eugen Hristev --- Changes in v2: - check return value of buffer prepare, and in case of error, unwind DMA - validated by trying to force an error : # echo 100 > /sys/bus/iio/devices/iio\:device0/buffer/length # echo 100 > /sys/bus/iio/devices/iio\:device0/buffer/watermark # iio_generic_buffer -n fc030000.adc -t fc030000.adc-dev0-external_rising -c 5 iio device number being used is 0 iio trigger number being used is 0 /sys/bus/iio/deviciio io:device0 fc030000.adc-dev0-external_risingiio:device0: using dma0chan10 for rx DMA transfers iio iio:device0: continuing without DMA support 505.151367 983.715820 1352.709961 1485.644531 Original patch message: Hi, This crash is in the kernel since 5.8-rc1 Please have a look at discussion here: https://lore.kernel.org/linux-iio/CA+U=DsqRUtjjoe5nevP_wNxTgr27+O2V1h9w7d3QijBQ+5f3XA@mail.gmail.com/T/#t Thanks ! drivers/iio/adc/at91-sama5d2_adc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index de9583d6cddd..f94641193b98 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -884,7 +884,7 @@ static bool at91_adc_current_chan_is_touch(struct iio_dev *indio_dev) AT91_SAMA5D2_MAX_CHAN_IDX + 1); } -static int at91_adc_buffer_preenable(struct iio_dev *indio_dev) +static int at91_adc_buffer_prepare(struct iio_dev *indio_dev) { int ret; u8 bit; @@ -901,7 +901,7 @@ static int at91_adc_buffer_preenable(struct iio_dev *indio_dev) /* we continue with the triggered buffer */ ret = at91_adc_dma_start(indio_dev); if (ret) { - dev_err(&indio_dev->dev, "buffer postenable failed\n"); + dev_err(&indio_dev->dev, "buffer prepare failed\n"); return ret; } @@ -989,7 +989,6 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev) } static const struct iio_buffer_setup_ops at91_buffer_setup_ops = { - .preenable = &at91_adc_buffer_preenable, .postdisable = &at91_adc_buffer_postdisable, }; @@ -1563,6 +1562,7 @@ static void at91_adc_dma_disable(struct platform_device *pdev) static int at91_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val) { struct at91_adc_state *st = iio_priv(indio_dev); + int ret; if (val > AT91_HWFIFO_MAX_SIZE) return -EINVAL; @@ -1586,7 +1586,15 @@ static int at91_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val) else if (val > 1) at91_adc_dma_init(to_platform_device(&indio_dev->dev)); - return 0; + /* + * We can start the DMA only after setting the watermark and + * having the DMA initialization completed + */ + ret = at91_adc_buffer_prepare(indio_dev); + if (ret) + at91_adc_dma_disable(to_platform_device(&indio_dev->dev)); + + return ret; } static int at91_adc_update_scan_mode(struct iio_dev *indio_dev,