Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2514702imm; Mon, 24 Sep 2018 05:45:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV618D8gE6p2c5exo6vpe0MoDz/ElfVexaCP43kk+T2ALyFpLahXw8J6WyFodv0FDpSx+L4FR X-Received: by 2002:a17:902:9b98:: with SMTP id y24-v6mr2059896plp.239.1537793151572; Mon, 24 Sep 2018 05:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537793151; cv=none; d=google.com; s=arc-20160816; b=OvbX1vHiIV5tTu2uTQY6ZR76qxmijzrrI1kNYFW1uZ01YnQE7h35XgJyJDML1gZuUc N1U9n/Ppla+Jo80oNb7Dlf+CmNNk8+epTHiDYdggWAdmjgIUv+9MdEJ4RxqVaAk4cMxY CnCEG4WDsUdsrYotbK0JWpkff1MbxZM+m4cA3k5qwgHJWfwT01mK5l/sE8jjek3OUjde AblD5q4FdIf1if4tNwA/V/Kv1SXLrzKDT5Z4YLTzhpwnklHImCAxXYqBqkKAxRd2uoK4 nuyIKyjsMg5lhveJ+YKTYSALmYCUjH7NuVc8wr0MwWTnk3tYFNfHKzYFiiDEqY190Z4/ kwoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=gl5MKJvX2eEpdaqVq4mNgBkFEq0mOSPevW/ak1n5hn4=; b=BbSdDezYizlc57XcmsfmjpZx0K3AkxQYs0RmFTuKeKkpTjyT0uWQIYReAdJuQozDD+ e77aWNpsm7p3mx4PxTTGZ3dCa/XrGbJXhvpbayUQ4cujohfhy16q95B73CfCzQSkQ50s KWCbbilaL03ozoEA0Eu54XiCyv5B1uK0RwBEYZkHDI41SGnYhsQKDzrmhJBKretDhlRC kq2kUDV5ySbOof9+w6Q8UlIHKKV9eEySb7lbRYM/gBSzaHH+k8L3j9Xt/8gHvoiWnZuT XtHHi8t9eZCvXcfOBlWq6oJ++kMXt9VYBVZOq9DGcM5/4U2xj6snpGqaFbr+SWmwX1qD prcw== 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 c24-v6si5521068pls.211.2018.09.24.05.45.36; Mon, 24 Sep 2018 05:45:51 -0700 (PDT) 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 S2389171AbeIXSqd (ORCPT + 99 others); Mon, 24 Sep 2018 14:46:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59634 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388717AbeIXSqd (ORCPT ); Mon, 24 Sep 2018 14:46:33 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 34109109A; Mon, 24 Sep 2018 12:44:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carlo Caione , Hans de Goede , Mark Brown , Sasha Levin Subject: [PATCH 4.18 219/235] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Date: Mon, 24 Sep 2018 13:53:25 +0200 Message-Id: <20180924113125.312769220@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hans de Goede [ Upstream commit 8d2d7bcdc1645dc243f7735278675b083c0e506c ] On removal we must free the IRQ *before* cancelling the jack-detect work, so that the jack-detect work cannot be rescheduled by the IRQ. Before this commit we were cancelling the jack-detect work from the driver remove callback, while relying on devm to free the IRQ, which happens after the remove callback. This is the wrong order. This commit uses a devm-action to register a devm callback which cancels the work, before requesting the IRQ (devm tears things down in reverse order). This also allows us to remove the now empty remove driver callback. Cc: Carlo Caione Signed-off-by: Hans de Goede Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- sound/soc/codecs/rt5651.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) --- a/sound/soc/codecs/rt5651.c +++ b/sound/soc/codecs/rt5651.c @@ -1696,6 +1696,13 @@ static irqreturn_t rt5651_irq(int irq, v return IRQ_HANDLED; } +static void rt5651_cancel_work(void *data) +{ + struct rt5651_priv *rt5651 = data; + + cancel_work_sync(&rt5651->jack_detect_work); +} + static int rt5651_set_jack(struct snd_soc_component *component, struct snd_soc_jack *hp_jack, void *data) { @@ -2036,6 +2043,11 @@ static int rt5651_i2c_probe(struct i2c_c INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work); + /* Make sure work is stopped on probe-error / remove */ + ret = devm_add_action_or_reset(&i2c->dev, rt5651_cancel_work, rt5651); + if (ret) + return ret; + ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5651, rt5651_dai, ARRAY_SIZE(rt5651_dai)); @@ -2043,15 +2055,6 @@ static int rt5651_i2c_probe(struct i2c_c return ret; } -static int rt5651_i2c_remove(struct i2c_client *i2c) -{ - struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c); - - cancel_work_sync(&rt5651->jack_detect_work); - - return 0; -} - static struct i2c_driver rt5651_i2c_driver = { .driver = { .name = "rt5651", @@ -2059,7 +2062,6 @@ static struct i2c_driver rt5651_i2c_driv .of_match_table = of_match_ptr(rt5651_of_match), }, .probe = rt5651_i2c_probe, - .remove = rt5651_i2c_remove, .id_table = rt5651_i2c_id, }; module_i2c_driver(rt5651_i2c_driver);