From patchwork Mon Jul 3 13:09:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106898 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp9378511obb; Mon, 3 Jul 2017 06:10:00 -0700 (PDT) X-Received: by 10.84.129.12 with SMTP id 12mr10409773plb.242.1499087399921; Mon, 03 Jul 2017 06:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499087399; cv=none; d=google.com; s=arc-20160816; b=ud+YI7RThxJYxw+KaH0NkITlGoewZEGmU6itizPAD9VxoSRf+lR7HfXa7RxxubMNHF 6B0Raknq6GQl8lr+Adz82v9dZvkAf0EWf3cYNqQ14EZvXZE9Tnog3Xx9qjyZE1+P3LcN gg8ydnkjW3j6AVKW33p1s2rE1DosJX0FOxRe7PTrW+5ZJwPwEapcAIF+qi0MU6YbFvbg yH24YN60HRNg5tzqyMvTr4lxKT9lChNFjibq8ygfpUj55kuxFzvQLAsmZNVw5SU8YY9b N7a/C9ns+/iu5VVX3mXh8hfosxd6zDxpxmiRKKWo5vfv8AT4Qll3eXOx6unQReTqVY3Q 81tQ== 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 :message-id:date:subject:cc:to:from:arc-authentication-results; bh=64vdKVpDrCk4lW9nDXaqqOFV87Yu1uhK30wOFV91Es4=; b=LZwaCpUn6Xa71KVWn0cTeXzcW4KzxspA2+N2Vd2hPDYO42wYPRD419cqU0BExQg0fK i+t7oH65RMQaeQkMmskMiBM7OE2df7lFN3kxVxAdr9z1hSdvwFc2JQ/dAFU5p0/xRcAR vVl4mlLlQToBrwgOSdj9ZddO2DMCgAviYnUIP3mlLDxuay6Nh4qouJ4hMSBP9gmyA5td BGaLk+jgYI0Kwee6UeP0QtRsxtkIfTNxhXTUOB7WYRudLp9tg4SHm1sfefpFOCBb/Jji SzS6ojKCE4wAzGUa4DctryvsM25gLwH6SpVOJEs4hlFyaTD79CrJshIgB4SeK7zT6uL5 9C4g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si11570358pgk.398.2017.07.03.06.09.58; Mon, 03 Jul 2017 06:09:59 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754350AbdGCNJ4 (ORCPT + 25 others); Mon, 3 Jul 2017 09:09:56 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:45721 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752229AbdGCNJw (ORCPT ); Mon, 3 Jul 2017 09:09:52 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 7F88620863; Mon, 3 Jul 2017 15:09:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 37DEC207F1; Mon, 3 Jul 2017 15:09:39 +0200 (CEST) From: Quentin Schulz To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, maxime.ripard@free-electrons.com, wens@csie.org Cc: Quentin Schulz , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, thomas.petazzoni@free-electrons.com Subject: [PATCH] iio: adc: sun4i-gpadc-iio: fix unbalanced irq enable/disable Date: Mon, 3 Jul 2017 15:09:26 +0200 Message-Id: <20170703130926.32315-1-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When initializing interrupts, the devm_request_any_context_irq will enable them right away. An atomic flag was set in sun4i_irq_init and read in the interrupt handler to make sure no unwanted interrupts were handled. If an unwanted interrupt occurred, the handler would disable the irq and return IRQ_HANDLED. However, at the end of sun4i_irq_init, the irq would be disabled as well, resulting in an unbalanced enable (since there are more disables than enables, the code enabling the interrupt would never be called). When reading the ADC or the temperature, the respective irq would be enabled in the read function and disabled in the irq handler. In the read function, we would wait for a completion (with a timeout) that will be set in the irq handler. However, if the completion is never set or if the wait for completion times out, the irq would not be disabled in the read function resulting in an unbalanced enable once the read function is called again (since there are 2+ enables for no disable). Moving disable_irq from the irq handler to the read function get rid of these two cases of unbalanced enable. Fixes: d1caa9905538 ("iio: adc: add support for Allwinner SoCs ADC") Reported-by: Andreas Färber Signed-off-by: Quentin Schulz --- drivers/iio/adc/sun4i-gpadc-iio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.11.0 Acked-by: Maxime Ripard diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 81d4c39e414a..137f577d9432 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -256,6 +256,7 @@ static int sun4i_gpadc_read(struct iio_dev *indio_dev, int channel, int *val, err: pm_runtime_put_autosuspend(indio_dev->dev.parent); + disable_irq(irq); mutex_unlock(&info->mutex); return ret; @@ -365,7 +366,6 @@ static irqreturn_t sun4i_gpadc_temp_data_irq_handler(int irq, void *dev_id) complete(&info->completion); out: - disable_irq_nosync(info->temp_data_irq); return IRQ_HANDLED; } @@ -380,7 +380,6 @@ static irqreturn_t sun4i_gpadc_fifo_data_irq_handler(int irq, void *dev_id) complete(&info->completion); out: - disable_irq_nosync(info->fifo_data_irq); return IRQ_HANDLED; }