Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2246536imm; Thu, 7 Jun 2018 07:39:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKiuhkglTNp3HWTcfwT8kQSEP4T6RbabdI9VSUKIaL7EofMTyRiD0OlSKxM0W6Sn7ZipD67 X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr2268321plq.215.1528382356568; Thu, 07 Jun 2018 07:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382356; cv=none; d=google.com; s=arc-20160816; b=TlEnRCx0LAauyKp2NcgwtmwpvuMA0LwlDRJAfGSzAVlbgpCmBQEeLGid9GUvCMOd05 34MJBU6A8i5ZSWR1j2u110UAy+qMNHmA3wj3wzCxTPwGWkqls59Kduj4FfvSUUk5SWsv pW6RXymjQVoWm/4gB/I1OJrlDb7Q3EMPl84FaqaSTcoXuGZm+nVpyyKtX1jaemPQDbyZ KY3c0TJma6SkwZUQEy7OyOgnyeAxn6JT36jME1Anfa2FeUTrMrZQxlULGC4f+R4Q5Tmw GH4RKibb61e9W0S7K4C9YXsKldoVuw5q0cPRN2fMQzw+4QUtcyKwbgEXxLLVEH1h3T0L aSvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Id0xKXdGPeQzkyuXIfCzyQGb53VoBpiAPETEYmKuHoI=; b=su+DDOzFsuzS6zu3JDNF1OQVJrqJnyi4jwf3nRKa1+2irIaNtdAlf0iqIuY4J13NBn KmX6Mvp+twMvS0U/QZSu8oGbpU5GrBHUrxNhEM4rwVluTEpfbew14Yphje9a4k2FjYlO PnpBAzTxw95IANHjiPre8u5xsUQky7C7CbP3XN5ptM/wE5UUbV/uH+f0AZwHwLq6fDbW NCFpNDu6LfS2ivuPPuiw83DLSzLjTL9fCpYBMs0wzlllREIzxhQnnCwORtTNR2K6KGDq rn4twrxD9ZhNgiq4eH29Hu2WYkcojySQe9sjGKqc4WydO4YlsHHOiU48BHCZspFf2sEt DiGA== 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 e72-v6si10168854pfd.352.2018.06.07.07.39.02; Thu, 07 Jun 2018 07:39:16 -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 S934208AbeFGOiC (ORCPT + 99 others); Thu, 7 Jun 2018 10:38:02 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40458 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934152AbeFGOhw (ORCPT ); Thu, 7 Jun 2018 10:37:52 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbm-0005Zp-17; Thu, 07 Jun 2018 15:09:46 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb4-0002xH-IG; Thu, 07 Jun 2018 15:09:02 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jonathan Cameron" , "Alexandru Ardelean" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 173/410] staging: iio: adc: ad7192: fix external frequency setting In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Alexandru Ardelean commit e31b617d0a63c6558485aaa730fd162faa95a766 upstream. The external clock frequency was set only when selecting the internal clock, which is fixed at 4.9152 Mhz. This is incorrect, since it should be set when any of the external clock or crystal settings is selected. Added range validation for the external (crystal/clock) frequency setting. Valid values are between 2.4576 and 5.12 Mhz. Signed-off-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Ben Hutchings --- drivers/staging/iio/adc/ad7192.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -125,6 +125,8 @@ #define AD7192_GPOCON_P1DAT (1 << 1) /* P1 state */ #define AD7192_GPOCON_P0DAT (1 << 0) /* P0 state */ +#define AD7192_EXT_FREQ_MHZ_MIN 2457600 +#define AD7192_EXT_FREQ_MHZ_MAX 5120000 #define AD7192_INT_FREQ_MHZ 4915200 /* NOTE: @@ -200,6 +202,12 @@ static int ad7192_calibrate_all(struct a ARRAY_SIZE(ad7192_calib_arr)); } +static inline bool ad7192_valid_external_frequency(u32 freq) +{ + return (freq >= AD7192_EXT_FREQ_MHZ_MIN && + freq <= AD7192_EXT_FREQ_MHZ_MAX); +} + static int ad7192_setup(struct ad7192_state *st, const struct ad7192_platform_data *pdata) { @@ -224,17 +232,20 @@ static int ad7192_setup(struct ad7192_st dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n", id); switch (pdata->clock_source_sel) { - case AD7192_CLK_EXT_MCLK1_2: - case AD7192_CLK_EXT_MCLK2: - st->mclk = AD7192_INT_FREQ_MHZ; - break; case AD7192_CLK_INT: case AD7192_CLK_INT_CO: - if (pdata->ext_clk_hz) - st->mclk = pdata->ext_clk_hz; - else - st->mclk = AD7192_INT_FREQ_MHZ; + st->mclk = AD7192_INT_FREQ_MHZ; break; + case AD7192_CLK_EXT_MCLK1_2: + case AD7192_CLK_EXT_MCLK2: + if (ad7192_valid_external_frequency(pdata->ext_clk_hz)) { + st->mclk = pdata->ext_clk_hz; + break; + } + dev_err(&st->sd.spi->dev, "Invalid frequency setting %u\n", + pdata->ext_clk_hz); + ret = -EINVAL; + goto out; default: ret = -EINVAL; goto out;