Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1933674img; Wed, 27 Feb 2019 07:54:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IZE2DQPxIrssuoQU9Zb3aVKtQLetPhHMi0T9r1z5Wl9CrBk0ja2wbzgZI4RqhfmcOMRsVpk X-Received: by 2002:a17:902:b60c:: with SMTP id b12mr2762718pls.261.1551282892902; Wed, 27 Feb 2019 07:54:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551282892; cv=none; d=google.com; s=arc-20160816; b=Y8d1dEjdKXAsNcUPxT6jmViJJqfNrOn6CVSm37eAIq56ahcR00jGv7B+TeVRGa3G7r vRdOtqbUyTLxFsVnZXiZMFUCQ3oSNNd/RwuwpMInAYswcYjfx+9gvTm35QZ5OvqRI7Gh uNKIeJGueiGkOAWRFRxz9cfbeJTtNAaTtK0uW+WUA8htADJqLc/d5ZYYfe+9uGoKvXUd Eko61ten0p4j+LpzZW2KZVD3e5VgOR97BMRnkP6i++y1rGzHs47KwnDJaM4cVbmK6NMN ERoRoXX9219aQIsAVXMO7V7Y3bsqQAa/hsZMfuS+msyTl5bWHkz94k1z/XIpj2jL9UvR jMTA== 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 :message-id:date:subject:cc:to:from; bh=Z7X8khpCLqk2OzAGTcVt+9dqhA6hCmDmuK1Bef4woFw=; b=ZqYnWD2b3TqJt+Wmn8Q6BQ7qcWrMfYp65bUhkJvVJ7JtqnCXpxR+OJLH4BrRMubKS7 EkjTnta0w93ak3Ns4pk1jVplNqsSKAJzerNlEP164VDrri/Fx/RCo6QuNb2bDATCrCEN eqXhUE5gYXybSm7xEWJjb9rpKDVev8npzBqJKxQt76phV8wLfoLpsWJcHyA9Hwz3A+Gu ivUBzRRaNbzy3E2Zn8PF4ImU6nC986NWr7OmXPvF7lk8Cnoz6jSlqrNbPhRB4CMQV5iL 9KePubFBCq071EiChYhVRkVHUFgyvBG0+6rCHOXhFfMifsEUTVDnNc69EByhuzQxdwUN pBFw== 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 l3si15928512pld.233.2019.02.27.07.54.24; Wed, 27 Feb 2019 07:54:52 -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 S1730037AbfB0PRi (ORCPT + 99 others); Wed, 27 Feb 2019 10:17:38 -0500 Received: from mx1.emlix.com ([188.40.240.192]:59294 "EHLO mx1.emlix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730028AbfB0PRh (ORCPT ); Wed, 27 Feb 2019 10:17:37 -0500 Received: from mailer.emlix.com (unknown [81.20.119.6]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 18FF36095C; Wed, 27 Feb 2019 16:17:35 +0100 (CET) From: Philipp Puschmann To: perex@perex.cz, tiwai@suse.com Cc: lgirdwood@gmail.com, broonie@kernel.org, peter.ujfalusi@ti.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Philipp Puschmann Subject: [PATCH v2] ASoC: tlv320aic3x: fix reset gpio reference counting Date: Wed, 27 Feb 2019 16:17:33 +0100 Message-Id: <20190227151733.4419-1-philipp.puschmann@emlix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes a bug that prevents freeing the reset gpio on unloading the module. aic3x_i2c_probe is called when loading the module and it calls list_add with a probably uninitialized list entry aic3x->list (next = prev = NULL)). So even if list_del is called it does nothing and in the end the gpio_reset is not freed. Then a repeated module probing fails silently because gpio_request fails. When moving INIT_LIST_HEAD to aic3x_i2c_probe we also have to move list_del to aic3x_i2c_remove because aic3x_remove may be called multiple times without aic3x_i2c_remove being called which leads to a NULL pointer dereference. Signed-off-by: Philipp Puschmann --- Changes in v2: Fix typo in title tlv320aix3x -> tlv320aic3x sound/soc/codecs/tlv320aic3x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index 6aa0edf8c5ef..cea3ebecdb12 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c @@ -1609,7 +1609,6 @@ static int aic3x_probe(struct snd_soc_component *component) struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); int ret, i; - INIT_LIST_HEAD(&aic3x->list); aic3x->component = component; for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) { @@ -1692,7 +1691,6 @@ static void aic3x_remove(struct snd_soc_component *component) struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); int i; - list_del(&aic3x->list); for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) regulator_unregister_notifier(aic3x->supplies[i].consumer, &aic3x->disable_nb[i].nb); @@ -1890,6 +1888,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c, if (ret != 0) goto err_gpio; + INIT_LIST_HEAD(&aic3x->list); list_add(&aic3x->list, &reset_list); return 0; @@ -1906,6 +1905,8 @@ static int aic3x_i2c_remove(struct i2c_client *client) { struct aic3x_priv *aic3x = i2c_get_clientdata(client); + list_del(&aic3x->list); + if (gpio_is_valid(aic3x->gpio_reset) && !aic3x_is_shared_reset(aic3x)) { gpio_set_value(aic3x->gpio_reset, 0); -- 2.20.1