Received: by 10.223.185.116 with SMTP id b49csp1054479wrg; Fri, 23 Feb 2018 11:04:40 -0800 (PST) X-Google-Smtp-Source: AH8x227wJ0sE0duUwSfgd+CsLZSygFx1RUZKlHmINH31fTmSVai1eRTzGxLHmNjICLix5VzmldRU X-Received: by 10.98.73.4 with SMTP id w4mr2682218pfa.227.1519412680676; Fri, 23 Feb 2018 11:04:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412680; cv=none; d=google.com; s=arc-20160816; b=OOnvEdwkcoZiGJ3nURH5Wga5pl31aHNVyXdCzVFbknEkbofBE7ncNhsI9gvpOatSv7 oPTOA/4eWFhVlWgPVULvIirLE1c4tiku+KvPzygO78qvC/kuYYOseIJBwH3VgRz4KhxE FsMFRR0RwyyM54QIX2XGOy/bULeChKum8FzG7E/z54lZf2QGPupo2Nl8ORbeTRX+J0FB W5GnxcOwVO6aWhnVwUcehYT+0gaKSGP064IpJu1BeuAZHeno8xUdxwjXbfvSNA64ivEg m1SO1tlJvcWQooT/zxLqwd+Dm/FR1oot4XccVzDrvJX4L3Ph80cgIOuU/CdEwF1UoxYZ yhhQ== 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=D5jqqtaTbYyN57tVg1XyiiELB7zBDAVSgMNTN0UK4CI=; b=MyPQi7txPMIAGfC9KtoNV+IFmV2wfhPNY6qugNhbt8D+D1a7oZlfbp5cOrPb+KMLuk dDffXWs8v79+f/fACxCxhYeQ+OIZwuugqoVuBfB2QBz9MrXVkP3KTZ9O07+ZItm/rPA/ iRag7/g5dTiGZwqJ+Azq1P8BRsu4/ePar8nSagDXP2OTBqx6BlQAFZX8LQHvViBAU7us Af5ViPzYP/cqkrI4e13Xx/3sogmWlNCjzxwh0FDp3I7m6VYBIdGv2+K/WhqUw+pLf3y7 L1GVCYUp7W+EHxv5Wb/9VcBpe47T0Fsbk+HD+tkcSlVLX0UdNBuGP/14aCwmBro13nRk hFdw== 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 75si2208066pfp.353.2018.02.23.11.04.24; Fri, 23 Feb 2018 11:04:40 -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 S965612AbeBWS6b (ORCPT + 99 others); Fri, 23 Feb 2018 13:58:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50556 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965596AbeBWS61 (ORCPT ); Fri, 23 Feb 2018 13:58:27 -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 D649010ED; Fri, 23 Feb 2018 18:58:26 +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.15 35/45] staging: iio: adc: ad7192: fix external frequency setting Date: Fri, 23 Feb 2018 19:29:14 +0100 Message-Id: <20180223170720.902262954@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@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.15-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: @@ -218,6 +220,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) { @@ -243,17 +251,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;