Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp655471ybh; Sat, 7 Mar 2020 07:08:42 -0800 (PST) X-Google-Smtp-Source: ADFU+vtjciO4bAjSIlbf5o+ndyxicaqZikJeSbSFP9VvGSNDddSGsAoF6LJoQgVi+ZUBant6ufse X-Received: by 2002:a9d:76c9:: with SMTP id p9mr6717929otl.135.1583593722252; Sat, 07 Mar 2020 07:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583593722; cv=none; d=google.com; s=arc-20160816; b=HUmAjFTByz+yLn7KO7Rbp+3JRHQEzOy/LD4gBi4Olym6SDB+kJO0sjenb5z9LbY/XF 6+nIm5aVglQxAFf64DpbhljLWOzxPJyi//fgGDf9DJ5GK3snhXA35kwYZM6pWSiU4mnh G2NffGEp8CL4alWbsqE7y/RmMXaIbE0ZHlYnkBAjXZRaUJlm2p+7MEIVtYZVtlG3HC7c n6S+0ZGUqjeZ8zsbRAmv0EyU/rmMtZOUbNyDp7gQApLItT8cBkCCL8hWtIpIuAMh5ouw KLWKwTXUqp8uU2vjy2b3JM8ITB6cXSHm5WwqmW02M3XZFTKggTFkTZB87Jzr22j3ke/j Fj6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=tw6Q9ONLib/FDbsqbL4bEWZ9guiLNFY34OwSDWMQua0=; b=XvbGA2//DFpZX5gmSoKr8BBKwf58tekKh2KMYrQqhSeKpA512BsLEtygBpE8enX0YG 5ya7v4HihvQnMh8gbUp1rhp7ANmRmQPIvU6nUzpBLlTBZDRIzYKDiUcQfDXhn55TZGl1 IYxSYoBeLW7hkJA9wraXhG5OyLbcqbAQmN1govaorAeQjNdeXN9M8H9QVpfAkPmu1qHp WG5uaI3E45Gq+vZmhYjj0ly4KqALhLYcYyl3Aw2BvnEyYRLmgwrooAvTimHJQe1bLxWJ xnFEnXdrx/K8oCwv2f5pT5mSo8f1qeMCXd89+FVPh72LIim89k6fnZBdo9p0C84ct6ZT DGkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QRgraDd5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si3446550otn.100.2020.03.07.07.08.29; Sat, 07 Mar 2020 07:08:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QRgraDd5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726154AbgCGPIH (ORCPT + 99 others); Sat, 7 Mar 2020 10:08:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:47734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgCGPIH (ORCPT ); Sat, 7 Mar 2020 10:08:07 -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 91AEB20675; Sat, 7 Mar 2020 15:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583593686; bh=RQpDqkyyxmFg9c3rc/jOhh1yQA+Hq7TSDoK7PRzgQ0I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QRgraDd5g2lyhqe/VHYJfWH8Kx0++0nF5g8fRF/GUXbIuEPV9DQEEa1eot9plToWK vpMZCqgUDGZG+77uAOPhuyjJUC1uClW+UBh0S8S+YKoo8YF15uRlT08pYMHJjPDCJJ PsQvSvEBfJGiP17xk+Yba/GFY1PuY6mHGdbrQqAI= Date: Sat, 7 Mar 2020 15:08:01 +0000 From: Jonathan Cameron To: Olivier Moysan Cc: , , , , , , , , , Subject: Re: [PATCH] iio: adc: stm32-adc: fix sleep in atomic context Message-ID: <20200307150801.011f35b2@archlinux> In-Reply-To: <20200306155335.6019-1-olivier.moysan@st.com> References: <20200306155335.6019-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 Fri, 6 Mar 2020 16:53:35 +0100 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. > > Signed-off-by: Olivier Moysan looks good to me, but... fixes tag? We probably want to backport this so good to know when we introduced the issue. Thanks, Jonathan > --- > 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");