Received: by 10.223.176.46 with SMTP id f43csp4347805wra; Tue, 23 Jan 2018 08:06:52 -0800 (PST) X-Google-Smtp-Source: AH8x227XDWkXuf9/eO9rBiE5FGVRs3PJXgKYevI9VL8EPD8lzyqvGlnMYWb6jaOv1OzGG5V1XlX6 X-Received: by 10.107.15.143 with SMTP id 15mr4137903iop.118.1516723612153; Tue, 23 Jan 2018 08:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516723612; cv=none; d=google.com; s=arc-20160816; b=vmFyIpDuzDQMyDV69JnEiWLv3YAmc2PnCIldxNuTtHD9zbMyoL1n5vubn+Va75K6CB KlwpWYfL8qfX39xTzfrhuXBPK7jICTTg4tmT7gB3oooZ4ovNplXnL/35zAFY7qEI5Mpn BxYX1+4u7D2v3fi3OquB4iiLlUEbRp6yONAZU1GNItgmGHOjpz1AzWiFfcuIL5AQGbfk r+1GujBmwAw4dCMI9VnCd19wHo+WPcXFaBM+O9P9FISp5xbiWXzpbVI9N9zXQP+Rn5k0 opCMawKuL/IsrAWftjhTDQubG+EizjUlS8ZhNqTbV0mSyQXZZX9R3dJNB+tmhIE415Oc JTPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=+ITNj8X+lT0L84JGFX4ZtgYY6C3nC5R5B4ESDjwLtoY=; b=awd6wxew40oALlMaK7VqyAl1b+rXZ7/OKKM8JXkYrOM6FZZWANigf4SMNENz/hjWdY SUiA4+FdXYKxFCYAZYjVjIxuVDi7MdDPxHW/9YjG8TAkPqiLlrfPrWLWES4R4KvYfqqT K9aHyIaEHx3OUil9fiAGWsYW7ktvx6yZOcg+6DO4Bd0gqsBxG1atph9zQj3bvpcvi1f4 Wq9sAHbB+AIs+Ypw7aepusb0hS7IdDUmB5quTRwwWFFUFELhWA2SUG9ZY9+0rmEABKFs vXUoegcG73VpiPaRD3E8QiTT20C5CSNEbJ+mJoEkXu74Pl6vU4DEdjw4HKR7eeaDMF3a 9/Pw== 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 n93si15673479ioe.108.2018.01.23.08.06.39; Tue, 23 Jan 2018 08:06:52 -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; 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 S1751693AbeAWQGD (ORCPT + 99 others); Tue, 23 Jan 2018 11:06:03 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:23872 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbeAWQGA (ORCPT ); Tue, 23 Jan 2018 11:06:00 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w0NG4NZJ012646; Tue, 23 Jan 2018 17:05:27 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2fnauwyh62-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 23 Jan 2018 17:05:27 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8777E34; Tue, 23 Jan 2018 16:05:26 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5E18A2CA9; Tue, 23 Jan 2018 16:05:26 +0000 (GMT) Received: from localhost (10.75.127.45) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 23 Jan 2018 17:05:26 +0100 From: Fabrice Gasnier To: CC: , , , , , , , , Subject: [PATCH] iio: adc: stm32: fix stm32h7_adc_enable error handling Date: Tue, 23 Jan 2018 17:04:56 +0100 Message-ID: <1516723497-9018-1-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG7NODE1.st.com (10.75.127.19) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-23_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Error handling in stm32h7_adc_enable routine doesn't unwind enable sequence correctly. ADEN can only be cleared by hardware (e.g. by writing one to ADDIS). It's also better to clear ADRDY just after it's been set by hardware. Fixes: 95e339b6e85d ("iio: adc: stm32: add support for STM32H7") Signed-off-by: Fabrice Gasnier --- drivers/iio/adc/stm32-adc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index ca3b865..8177a92 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -735,8 +735,6 @@ static int stm32h7_adc_enable(struct stm32_adc *adc) int ret; u32 val; - /* Clear ADRDY by writing one, then enable ADC */ - stm32_adc_set_bits(adc, STM32H7_ADC_ISR, STM32H7_ADRDY); stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADEN); /* Poll for ADRDY to be set (after adc startup time) */ @@ -744,8 +742,11 @@ static int stm32h7_adc_enable(struct stm32_adc *adc) val & STM32H7_ADRDY, 100, STM32_ADC_TIMEOUT_US); if (ret) { - stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_ADEN); + stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADDIS); dev_err(&indio_dev->dev, "Failed to enable ADC\n"); + } else { + /* Clear ADRDY by writing one */ + stm32_adc_set_bits(adc, STM32H7_ADC_ISR, STM32H7_ADRDY); } return ret; -- 1.9.1