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 76B32C3524C for ; Sun, 2 Feb 2020 14:08:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F30C206E6 for ; Sun, 2 Feb 2020 14:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580652511; bh=1gYVSw87cV5telUJWyrU4zFFINerB9YY8C8irZlxApA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=A+EXbillGdzaqJq0Phcw5L1daXlildNfZ2h7p3XZFVhvFYZYkpxvV1Ru96YP8t8xo tJ6g/eIRfAk9Fr+VqPpSxTHzQgawNL3HaeeKS60C7NqqHGbM/XuHsvzR+BfXJeC0Ty LRQonHG2fBLG9ojN40a9XFW03K/OEK4kmoGYzcFo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgBBOIa (ORCPT ); Sun, 2 Feb 2020 09:08:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:56368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgBBOIa (ORCPT ); Sun, 2 Feb 2020 09:08:30 -0500 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 74D3B20643; Sun, 2 Feb 2020 14:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580652509; bh=1gYVSw87cV5telUJWyrU4zFFINerB9YY8C8irZlxApA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ess6qBFo/F1BcnkklY0GwQ0BaBxBJsuYomqCrB30q1vmmC6dsjDMoKMpqMIUUZZUK znJl3Dr37+R4USh1jUHGRUCdUaetljWY9diwl/hUxmdeR5wFzc/oo3d2k8GxHsPJkz IPULSo+/5Rx0OTexcH3P9lIQTNvyGSRSCguT0AxY= Date: Sun, 2 Feb 2020 14:08:23 +0000 From: Jonathan Cameron To: Olivier Moysan Cc: , , , , , , , , , Subject: Re: [PATCH] iio: adc: stm32-dfsdm: fix sleep in atomic context Message-ID: <20200202140823.531aad39@archlinux> In-Reply-To: <20200121110256.12415-1-olivier.moysan@st.com> References: <20200121110256.12415-1-olivier.moysan@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 Tue, 21 Jan 2020 12:02:56 +0100 Olivier Moysan wrote: > This commit fixes the error message: > "BUG: sleeping function called from invalid context at kernel/irq/chip.c" > Suppress the trigger irq handler. Make the buffer transfers directly > in DMA callback, instead. > Push buffers without timestamps, as timestamps are not supported > in DFSDM driver. > > Fixes: 11646e81d775 ("iio: adc: stm32-dfsdm: add support for buffer modes") > > Signed-off-by: Olivier Moysan Applied to the fixes-togreg branch of iio.git and marked for stable. Thanks, Jonathan > --- > There is the same issue on STM32 ADC driver. > The solution for ADC driver has been already discussed in the thread > https://lkml.org/lkml/2019/3/30/171 > The current patch for STM32 DFSDM driver, bypasses the IIO IRQ trigger > handler, as proposed in this thread. > --- > drivers/iio/adc/stm32-dfsdm-adc.c | 43 +++++++------------------------ > 1 file changed, 10 insertions(+), 33 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > index 2aad2cda6943..76a60d93fe23 100644 > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > @@ -842,31 +842,6 @@ static inline void stm32_dfsdm_process_data(struct stm32_dfsdm_adc *adc, > } > } > > -static irqreturn_t stm32_dfsdm_adc_trigger_handler(int irq, void *p) > -{ > - struct iio_poll_func *pf = p; > - struct iio_dev *indio_dev = pf->indio_dev; > - struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); > - int available = stm32_dfsdm_adc_dma_residue(adc); > - > - while (available >= indio_dev->scan_bytes) { > - s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi]; > - > - stm32_dfsdm_process_data(adc, buffer); > - > - iio_push_to_buffers_with_timestamp(indio_dev, buffer, > - pf->timestamp); > - available -= indio_dev->scan_bytes; > - adc->bufi += indio_dev->scan_bytes; > - if (adc->bufi >= adc->buf_sz) > - adc->bufi = 0; > - } > - > - iio_trigger_notify_done(indio_dev->trig); > - > - return IRQ_HANDLED; > -} > - > static void stm32_dfsdm_dma_buffer_done(void *data) > { > struct iio_dev *indio_dev = data; > @@ -874,11 +849,6 @@ static void stm32_dfsdm_dma_buffer_done(void *data) > int available = stm32_dfsdm_adc_dma_residue(adc); > size_t old_pos; > > - if (indio_dev->currentmode & INDIO_BUFFER_TRIGGERED) { > - iio_trigger_poll_chained(indio_dev->trig); > - return; > - } > - > /* > * FIXME: In Kernel interface does not support cyclic DMA buffer,and > * offers only an interface to push data samples per samples. > @@ -906,7 +876,15 @@ static void stm32_dfsdm_dma_buffer_done(void *data) > adc->bufi = 0; > old_pos = 0; > } > - /* regular iio buffer without trigger */ > + /* > + * 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). > + */ > if (adc->dev_data->type == DFSDM_IIO) > iio_push_to_buffers(indio_dev, buffer); > } > @@ -1536,8 +1514,7 @@ static int stm32_dfsdm_adc_init(struct iio_dev *indio_dev) > } > > ret = iio_triggered_buffer_setup(indio_dev, > - &iio_pollfunc_store_time, > - &stm32_dfsdm_adc_trigger_handler, > + &iio_pollfunc_store_time, NULL, > &stm32_dfsdm_buffer_setup_ops); > if (ret) { > stm32_dfsdm_dma_release(indio_dev);