From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44DEAC2BB1D for ; Sun, 15 Mar 2020 09:35:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C853206E9 for ; Sun, 15 Mar 2020 09:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584264956; bh=bydZt1msrAZyMXtqxKfMHkV2PUIlKeyA7eIC50CIB/M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=wUydPYKtO+RVl1XQ2bHb6VEIvKizTg9AVhbeuTcd/kQ1RgC61YQGCm2z8kV3iQ7jy whOO5Jzx+0Wc/j1fVU2pMC6f3zMmD+ef/2VsEw+iwJXVldbFPv7/TuYDFUG+wxZskU 72o4t7ShXBLEG/E/IP593I7hAvvB+E8GAZa9Wdbo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728194AbgCOJfz (ORCPT ); Sun, 15 Mar 2020 05:35:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:41870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728128AbgCOJfy (ORCPT ); Sun, 15 Mar 2020 05:35:54 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 52A38206BE; Sun, 15 Mar 2020 09:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584264954; bh=bydZt1msrAZyMXtqxKfMHkV2PUIlKeyA7eIC50CIB/M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TBHxriSWt3P/WyyWLaDJyymqjhCzixdbSC6Kom2zz+dKvOk44zqBI4xFqNgxzw0Wy Ec1OcZMiugGyij6LFyACRIo89VS8P5sckaeq5a0n/cowSIEVh/iA3WeJIKg6KgFvoH Qv81sHhcA288CvhJUJKfSFmqxzysIMSHEP4Ff1Yg= Date: Sun, 15 Mar 2020 09:35:49 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: Olivier Moysan , , , , , , , , , Subject: Re: [PATCH v2] iio: adc: stm32-adc: fix sleep in atomic context Message-ID: <20200315093549.20764470@archlinux> In-Reply-To: <288fb604-16c6-da52-533f-7f1440ed9daa@st.com> References: <20200309100212.16499-1-olivier.moysan@st.com> <288fb604-16c6-da52-533f-7f1440ed9daa@st.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 9 Mar 2020 11:39:17 +0100 Fabrice Gasnier wrote: > On 3/9/20 11:02 AM, Olivier Moysan wrote: > > This commit fixes the following error: > > "BUG: sleeping function called from invalid context at kernel/irq/chip.c" > > > > In DMA mode suppress the trigger irq handler, and make the buffer > > transfers directly in DMA callback, instead. > > > > Fixes: 2763ea0585c9 ("iio: adc: stm32: add optional dma support") > > > > Signed-off-by: Olivier Moysan > > Hi Olivier, > > Acked-by: Fabrice Gasnier Thanks. Queued up locally but not pushed out just yet as I have a pull request out to Greg. Also marked for stable. thanks, Jonathan > > Thanks, > Fabrice > > > --- > > Changes in v2: > > - Add "Fixes" tag in commit message > > > > This solution has been already discussed in the thread > > https://lkml.org/lkml/2019/3/30/171, and applied in STM32 DFSDM driver: > > e19ac9d9a978 ("iio: adc: stm32-dfsdm: fix sleep in atomic context") > > --- > > drivers/iio/adc/stm32-adc.c | 31 ++++++++++++++++++++++++++++--- > > 1 file changed, 28 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c > > index 80c3f963527b..ae622ee6d08c 100644 > > --- a/drivers/iio/adc/stm32-adc.c > > +++ b/drivers/iio/adc/stm32-adc.c > > @@ -1418,8 +1418,30 @@ static unsigned int stm32_adc_dma_residue(struct stm32_adc *adc) > > static void stm32_adc_dma_buffer_done(void *data) > > { > > struct iio_dev *indio_dev = data; > > + struct stm32_adc *adc = iio_priv(indio_dev); > > + int residue = stm32_adc_dma_residue(adc); > > + > > + /* > > + * In DMA mode the trigger services of IIO are not used > > + * (e.g. no call to iio_trigger_poll). > > + * Calling irq handler associated to the hardware trigger is not > > + * relevant as the conversions have already been done. Data > > + * transfers are performed directly in DMA callback instead. > > + * This implementation avoids to call trigger irq handler that > > + * may sleep, in an atomic context (DMA irq handler context). > > + */ > > + dev_dbg(&indio_dev->dev, "%s bufi=%d\n", __func__, adc->bufi); > > > > - iio_trigger_poll_chained(indio_dev->trig); > > + while (residue >= indio_dev->scan_bytes) { > > + u16 *buffer = (u16 *)&adc->rx_buf[adc->bufi]; > > + > > + iio_push_to_buffers(indio_dev, buffer); > > + > > + residue -= indio_dev->scan_bytes; > > + adc->bufi += indio_dev->scan_bytes; > > + if (adc->bufi >= adc->rx_buf_sz) > > + adc->bufi = 0; > > + } > > } > > > > static int stm32_adc_dma_start(struct iio_dev *indio_dev) > > @@ -1845,6 +1867,7 @@ static int stm32_adc_probe(struct platform_device *pdev) > > { > > struct iio_dev *indio_dev; > > struct device *dev = &pdev->dev; > > + irqreturn_t (*handler)(int irq, void *p) = NULL; > > struct stm32_adc *adc; > > int ret; > > > > @@ -1911,9 +1934,11 @@ static int stm32_adc_probe(struct platform_device *pdev) > > if (ret < 0) > > return ret; > > > > + if (!adc->dma_chan) > > + handler = &stm32_adc_trigger_handler; > > + > > ret = iio_triggered_buffer_setup(indio_dev, > > - &iio_pollfunc_store_time, > > - &stm32_adc_trigger_handler, > > + &iio_pollfunc_store_time, handler, > > &stm32_adc_buffer_setup_ops); > > if (ret) { > > dev_err(&pdev->dev, "buffer setup failed\n"); > >