From patchwork Tue Jun 30 07:30:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 6694351 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C31E7C05AC for ; Tue, 30 Jun 2015 07:31:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7BFF20502 for ; Tue, 30 Jun 2015 07:31:20 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 0E061203AB for ; Tue, 30 Jun 2015 07:31:19 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 82E5E260444; Tue, 30 Jun 2015 09:31:17 +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_SIGNED, 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 296A9260422; Tue, 30 Jun 2015 09:31:09 +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 DECD3260423; Tue, 30 Jun 2015 09:31:06 +0200 (CEST) Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by alsa0.perex.cz (Postfix) with ESMTP id 75B5C260412 for ; Tue, 30 Jun 2015 09:31:01 +0200 (CEST) Received: by pdjd13 with SMTP id d13so1373502pdj.0 for ; Tue, 30 Jun 2015 00:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=htTr8lT7bKiUTsFqRMQpJZjxwYfxq7I0hni4khEC7r4=; b=GCBW1bXVfycxzXcYhzlzj3skUwdwtjFRN99fuHP01uRPzZL43sXQJ99dIqoe2LKH3n 4B1USpSPBG48E3rcsD/V+4QlQ72sHFfD2TKHn8HV+0hxyASBixJBg2ZzUYlmRmOdH5Kn BXZkEu8WbzOV4runvBuuY8L3S1E7bvkT6cHfA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=htTr8lT7bKiUTsFqRMQpJZjxwYfxq7I0hni4khEC7r4=; b=YRaRil2dCmij43PSLosrXg6sgrPRclSpbqINEtKaW3k3xz3J4Jwb6YWtCZ22L01NgM sJDXa0aLZWPzTZ6wpu6O4m+8298MycNhCMuTdhVHkIQSIUNH1n73R5A3aE7rH/I6dIZg yHhEPizQcxgpvlSOXpPsTpB7sbOFZUx+zN5TeSeHkNDEqH8cREUYurcyZklvsQ0xUPZb XKU6dbHtRGzr2dG9w+QbPitCB6AB7fB5Yv5kZ9jS6SOm4JhznZ1/bL4z0/CcAUsD0WF+ +T9g1iAYjwsLEkElcXSH7Cf/6aswPoctJc+Tu9d74pvLhyw1ft7vWFsoopNRliY2ZDdB rSoA== X-Gm-Message-State: ALoCoQnGvGz9nCCIEY0vOyCkYIzjP9YtniZ5OB1g4KWH+PPtz/l3N8h/yf4bsA2CPZfN95A8H1ot X-Received: by 10.66.54.233 with SMTP id m9mr41168788pap.33.1435649456192; Tue, 30 Jun 2015 00:30:56 -0700 (PDT) Received: from drinkcat.tpe.corp.google.com ([172.30.210.53]) by mx.google.com with ESMTPSA id sc1sm44803310pac.36.2015.06.30.00.30.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jun 2015 00:30:55 -0700 (PDT) From: Nicolas Boichat To: Mark Brown Date: Tue, 30 Jun 2015 15:30:41 +0800 Message-Id: <1435649441-1941-1-git-send-email-drinkcat@chromium.org> X-Mailer: git-send-email 2.4.3.573.g4eafbef Cc: Oder Chiou , alsa-devel@alsa-project.org, Takashi Iwai , Liam Girdwood , koro.chen@mediatek.com, Bard Liao Subject: [alsa-devel] [PATCH] ASoC: rt5645: Move irq request to rt5645_probe 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 rt5645_jack_detect_work (the workqueue called by rt5645_irq), needs to access rt5645->codec. However, this field is only initialized in rt5645_probe. This can obviously lead to kernel panics. Fix that by moving the irq request from rt5645_i2c_probe to rt5645_probe. Also, fail if the IRQ cannot be requested, and move irq_free from rt5645_i2c_remove to rt5645_remove. Signed-off-by: Nicolas Boichat --- sound/soc/codecs/rt5645.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 9ce311e..7f84f21 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3044,6 +3044,7 @@ static int rt5645_irq_detection(struct rt5645_priv *rt5645) static int rt5645_probe(struct snd_soc_codec *codec) { struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); + int ret; rt5645->codec = codec; @@ -3072,12 +3073,32 @@ static int rt5645_probe(struct snd_soc_codec *codec) snd_soc_dapm_sync(&codec->dapm); } + INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); + + if (rt5645->i2c->irq) { + ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING + | IRQF_ONESHOT, "rt5645", rt5645); + if (ret) { + dev_err(codec->dev, "Failed to request IRQ: %d\n", ret); + return ret; + } + } + return 0; } static int rt5645_remove(struct snd_soc_codec *codec) { + struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); + + if (rt5645->i2c->irq) + free_irq(rt5645->i2c->irq, rt5645); + + cancel_delayed_work_sync(&rt5645->jack_detect_work); + rt5645_reset(codec); + return 0; } @@ -3428,29 +3449,12 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, } } - INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); - - if (rt5645->i2c->irq) { - ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING - | IRQF_ONESHOT, "rt5645", rt5645); - if (ret) - dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); - } - return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645, rt5645_dai, ARRAY_SIZE(rt5645_dai)); } static int rt5645_i2c_remove(struct i2c_client *i2c) { - struct rt5645_priv *rt5645 = i2c_get_clientdata(i2c); - - if (i2c->irq) - free_irq(i2c->irq, rt5645); - - cancel_delayed_work_sync(&rt5645->jack_detect_work); - snd_soc_unregister_codec(&i2c->dev); return 0;