Received: by 10.223.185.116 with SMTP id b49csp1141674wrg; Fri, 23 Feb 2018 12:40:47 -0800 (PST) X-Google-Smtp-Source: AH8x227IALbfWh+drBq99zL2o8DhSXc3zEqdf5u5MoWdx4gakrkkwwKOZNvl6Nrm9D2N545CVI9i X-Received: by 10.99.177.72 with SMTP id g8mr2289012pgp.99.1519418447422; Fri, 23 Feb 2018 12:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418447; cv=none; d=google.com; s=arc-20160816; b=myrrxzWzOmZmCq3dxbZwJKgxm11Qd1ZfSGpL2I3rff+fTV+a56gAOqNuYD+dfNP0uI sOCOl7Nav6WE94I753U0jcap9r3CTf1vOM5E44nPHS3k5lqRot1fIoAwuvYjsKE6K8lz Jxu9Rkg3cRajKz2VA+Ui1dwuhqcy0wFXZhk9uEkCV2mDp6p4sKhSJ+5Q//jhcNxxLDsQ zSzAm1Ulz+XAYfMGrVHHguwmwQUPnyAYfmJy3ydrqfIkufcnaQtxpMmB4vlUq0qP7gPj kV6yEwD+ohgBhZ8l992/MEQlptl+D+UfqhsH2e2xN6cT/6BMgx/2kekgxxCBdGUbVulG pnjw== 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=JWG8BGv1gyKh3rlQg7TGrWsh19Oaj18E3+ex3Y+RJNM=; b=DC5RsD2NPnpzsP+sJ0Mm3Hi5eM9ObysM5fobjjtSWhGKAjeoDqkGupMQ9rzNqdKfOa UV5FyH4Yo65jz9Rf3S809rnnEXFHvLtsGCWQON6Lf93pHZn+EUKLG38gKg7KOVyxRUEV FI2EX18elThV+cDMf4m2oHQ8PI+K+ujvzjlKGd/qDcBUNqnsBnODAqYiNgQVoYt3fXSZ Mf0qsMptXPt91W9wZoatxxFGKmPHtovYmdoPpA7PZ3la0JP2H3cKhJowU9LGNKCoPRtA Ob2TPQhWq3p7G89b0LxnoK4Xoce5FLg/jEIxkUQzOjay1Mv2ZIjOc1cgbes/nB2MzI/Y V7Qw== 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 y23-v6si2276482pli.633.2018.02.23.12.40.33; Fri, 23 Feb 2018 12:40:47 -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 S1753379AbeBWSdy (ORCPT + 99 others); Fri, 23 Feb 2018 13:33:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36686 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753358AbeBWSdv (ORCPT ); Fri, 23 Feb 2018 13:33:51 -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 78EB7121B; Fri, 23 Feb 2018 18:33:50 +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.4 028/193] staging: iio: adc: ad7192: fix external frequency setting Date: Fri, 23 Feb 2018 19:24:21 +0100 Message-Id: <20180223170330.452883580@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@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.4-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 @@ -124,6 +124,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: @@ -199,6 +201,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 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;