From patchwork Thu Oct 2 20:36:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 5020451 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DDCC29F3ED for ; Thu, 2 Oct 2014 20:37:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1BCA7201F5 for ; Thu, 2 Oct 2014 20:37:01 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 61F312011B for ; Thu, 2 Oct 2014 20:36:59 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2DDCA26167D; Thu, 2 Oct 2014 22:36:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id CD244261735; Thu, 2 Oct 2014 22:36:46 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 773182617B5; Thu, 2 Oct 2014 22:36:45 +0200 (CEST) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by alsa0.perex.cz (Postfix) with ESMTP id 57F3226167D for ; Thu, 2 Oct 2014 22:36:38 +0200 (CEST) Received: by mail-yh0-f43.google.com with SMTP id f10so993752yha.30 for ; Thu, 02 Oct 2014 13:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=9zR5VLk/zNW1Pcs7/WdFr+zVTy4P/QaZovC3yVWQ8zA=; b=NHvt7M74cQ9/0h4SujqdoG8zdtovjfxQpesihHADDzlE3RpG+Q1SNfbqdq3igQW1Ea K+YhKN+JCTau4LjW+993r3Cr80vZw/zOSUfmZAxQZfTra4ZUGB5ZQXxCfJu+2Ll/j1we WBooJrKyjfm1Y1f9IA/zsmM2nBpAUKfSoLRenkH9dlNXZ2kBAdMmqPLsNfoiwSy3N7zm PXxNhfUhKG0LRJ7xEhWJdzhduqa27sJIqFDB9/cXKoOB5PKSXjmlkTAVsaaecp1ujV1q CZpwK95TA1g4Xgar5kJrvFBWxnZ4jv0+HjdjQ3n4h6oA0j9VIfcjd4YS5vcGhISpiyQi j4QA== X-Received: by 10.236.91.208 with SMTP id h56mr1558057yhf.139.1412282197121; Thu, 02 Oct 2014 13:36:37 -0700 (PDT) Received: from localhost.localdomain ([201.82.52.106]) by mx.google.com with ESMTPSA id s92sm2127052yhp.46.2014.10.02.13.36.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Oct 2014 13:36:36 -0700 (PDT) From: Fabio Estevam To: broonie@kernel.org Date: Thu, 2 Oct 2014 17:36:05 -0300 Message-Id: <1412282165-1500-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.9.1 Cc: Fabio Estevam , alsa-devel@alsa-project.org, shawn.guo@freescale.com Subject: [alsa-devel] [PATCH] ASoC: sgtl5000: Do a sanity check on SYS_MCLK X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam According to the sgtl5000 datasheet the valid range for SYS_MCLK is from 8 to 27 MHz. Add a sanity check prior to enabling SYS_MCLK. Signed-off-by: Fabio Estevam --- sound/soc/codecs/sgtl5000.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index a604a22..1470437 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c @@ -1414,6 +1414,7 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, { struct sgtl5000_priv *sgtl5000; int ret, reg, rev; + unsigned int mclk; sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv), GFP_KERNEL); @@ -1437,6 +1438,14 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, return ret; } + /* SGTL5000 SYS_MCLK should be between 8 and 27 MHz */ + mclk = clk_get_rate(sgtl5000->mclk); + if (mclk < 8000000 || mclk > 27000000) { + dev_err(&client->dev, "Invalid SYS_CLK frequency: %u.%03uMHz\n", + mclk / 1000000, mclk / 1000 % 1000); + return -EINVAL; + } + ret = clk_prepare_enable(sgtl5000->mclk); if (ret) return ret;