Received: by 10.223.185.116 with SMTP id b49csp1078805wrg; Fri, 23 Feb 2018 11:32:03 -0800 (PST) X-Google-Smtp-Source: AH8x227XJOKWorfn8auHq2YhtjKWiU+ddjIL/arPUdaTAgYM9f6XjcHT3b8U9G/Dye3iMja7tqTh X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr2627974plj.390.1519414323038; Fri, 23 Feb 2018 11:32:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519414323; cv=none; d=google.com; s=arc-20160816; b=CdSFD8JTWePoVhiJvbxo8QFqMLt4NqFJYiA0Dpi9FgU8u5rGIB5kVjL2pdp/Ntufff f4oaIaGtLxBBWZlEIu1Xo+Tqo/NGoTIwV3JL0ryaU1RvxznTgDfJNxLEmRMKm5geJ1Bp /3d0BaF3HoYmqMBck1sjQjCnDur0DTuwItmgmEuJP2q90HudU+paxdAq1Hh5/y+kxXq+ Y1GZahM/pufBw4Z7kSfsKS2HEqnQZoBMt50WY7njiyHFLtovY1cOtnogLs8+W8tbj6Vv RU32FGtoBYnVDGh3YylxkxA4PIxyDioedRTWGbWxhXekkw8rl3AhF+u/3/lDjdl9rPWY xkVg== 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=yd4xr3SFQ7NcQXGLkLH+zxm/jLj6jW9Z804xRk4XXAw=; b=G36wWfAVyuprWSJD+dgt6mGnql3zLhHq9JhT/+NpoLDdHLOoXK1k0hUQthXT3cGiuu B2rUKLax6/0Ezl324v7rgnlnDmBGrGh0vFMX4JZPx+m4nQAj1bXkY/xV6Qcrv+m7WSno 461rt3JniKk4JMne+cuCPkEjGlz6++siZNPqCTHqciFLKCweOf5dXyBMHDKEBzj9zH5r QCpVi7WhPfDsdcu+hkLE7bTSK5vh63KmH12JaNVwTrpAFIBQ6CjaOtYXgXLdgW4lvcll vA9rSR47U3FvPOiJRh8hH8bF4kG8hOKW5ZqOiwCZmulgTGdsmJ6O//27Fj+pX504QrY5 yh2w== 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 e2si1867798pgr.242.2018.02.23.11.31.48; Fri, 23 Feb 2018 11:32:02 -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 S935022AbeBWSvq (ORCPT + 99 others); Fri, 23 Feb 2018 13:51:46 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:46082 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934995AbeBWSvn (ORCPT ); Fri, 23 Feb 2018 13:51:43 -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 249A312E2; Fri, 23 Feb 2018 18:51:42 +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.14 056/159] staging: iio: adc: ad7192: fix external frequency setting Date: Fri, 23 Feb 2018 19:26:04 +0100 Message-Id: <20180223170750.391348328@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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: @@ -217,6 +219,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) { @@ -242,17 +250,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;