Received: by 10.223.185.116 with SMTP id b49csp1102981wrg; Fri, 23 Feb 2018 12:00:41 -0800 (PST) X-Google-Smtp-Source: AH8x226mkgSGpH9PB3kC4EwNtXn6E1wxD42AVjXL3Y4NLF5is74RP8kgdKXpOKbU0nhB4DSVRTf9 X-Received: by 10.98.157.18 with SMTP id i18mr2856857pfd.62.1519416041475; Fri, 23 Feb 2018 12:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416041; cv=none; d=google.com; s=arc-20160816; b=ecfCOt1oBa2oHsk2IqlUQqT40qfL2aJmo/zJTiFSdtKyM3z/67lvyl2QRnWKB3yAr2 8mRfFO8uML6WEdtrE9G0Wkp8JgVYjHqC0x7eysrb5Fh+6+x5o/l2WvkMwX7Z3aVdlFkz B61Q65yYxUBIozuaqzm34kyUdWj6UCNOE6Uz2jSIDbwWrqxDD+SzIrwmopwDB3J8IXDk tzHmUJq5WD3MmDgHpyjaTaszYrAneimEzylj2O8J12olgp5UdKNaC19VprLKROzAhlZK IOqTvhmqFhOulnJvtfmg/PYJS0mda3FQqWiRXVZjQ/Cl7gAmKkVe4bmCL7lnDt1dDM1T g3+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=CGDaxHCLofWkY8w9PrcriRmiXkxqtsf69JtATwJLMNE=; b=JXCUnXA7CV18uTyAr+tn8FCnsc5rBBL/9kc8BC4ZvFKgCoSv9Rhx7kZWzemGOQ28Fs 2FfbYnKYR8w2nBk+T5F1/nMfL3mewh6e2kh5qu/A0SBloo1j7X8HFMKgsSvMFOl9Npbb 0zLFA6llXuyT3xffSHIgVtX3iTIYFU2AtWjt6exi9adiTM8A/ed2yBLRQ79RM50PpLEB nmsErQuOZHdpaARYibc8PdW2SSFF2O+YGAr+Axs/PzY5NuqgMSoT0jIUJ50NDZJzjkjP FlCjadq2X+eWRcUCh/5ydOw2Ajw8BYJE02B+B52SXlSBTC/DRGgY31abBZ+JHMEPjIvJ MowA== 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 h13si1863779pgn.782.2018.02.23.12.00.26; Fri, 23 Feb 2018 12:00:41 -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 S933056AbeBWSnz (ORCPT + 99 others); Fri, 23 Feb 2018 13:43:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42372 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933413AbeBWSnw (ORCPT ); Fri, 23 Feb 2018 13:43:52 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8EAC9120B; Fri, 23 Feb 2018 18:43:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandru Ardelean , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.9 039/145] staging: iio: adc: ad7192: fix external frequency setting Date: Fri, 23 Feb 2018 19:25:45 +0100 Message-Id: <20180223170730.008524296@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable 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 Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- 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 @@ -141,6 +141,8 @@ #define AD7192_GPOCON_P1DAT BIT(1) /* P1 state */ #define AD7192_GPOCON_P0DAT BIT(0) /* P0 state */ +#define AD7192_EXT_FREQ_MHZ_MIN 2457600 +#define AD7192_EXT_FREQ_MHZ_MAX 5120000 #define AD7192_INT_FREQ_MHZ 4915200 /* NOTE: @@ -216,6 +218,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) { @@ -241,17 +249,20 @@ static int ad7192_setup(struct ad7192_st 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;