From patchwork Wed Nov 9 08:48:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68066C433FE for ; Wed, 9 Nov 2022 08:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbiKII14 (ORCPT ); Wed, 9 Nov 2022 03:27:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbiKII1w (ORCPT ); Wed, 9 Nov 2022 03:27:52 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D646E13D16; Wed, 9 Nov 2022 00:27:50 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPS2L5VzHvg6; Wed, 9 Nov 2022 16:27:24 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:48 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Oleh Kravchenko Subject: [PATCH 01/13] leds: cr0014114: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:02 +0800 Message-ID: <1667983694-15040-2-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 9e50d5fb0d18 ("leds: add LED driver for CR0014114 board") Signed-off-by: Wang Yufen Cc: Oleh Kravchenko --- drivers/leds/leds-cr0014114.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c index c87686b..f3a0320 100644 --- a/drivers/leds/leds-cr0014114.c +++ b/drivers/leds/leds-cr0014114.c @@ -211,6 +211,11 @@ static int cr0014114_probe_dt(struct cr0014114 *priv) return 0; } +static void cr0014114_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int cr0014114_probe(struct spi_device *spi) { struct cr0014114 *priv; @@ -240,6 +245,11 @@ static int cr0014114_probe(struct spi_device *spi) priv->delay = jiffies - msecs_to_jiffies(CR_FW_DELAY_MSEC); + ret = devm_add_action_or_reset(&spi->dev, cr0014114_mutex_destroy, + &priv->lock); + if (ret) + return ret; + priv->do_recount = true; ret = cr0014114_sync(priv); if (ret) { @@ -271,7 +281,6 @@ static void cr0014114_remove(struct spi_device *spi) struct cr0014114 *priv = spi_get_drvdata(spi); cancel_delayed_work_sync(&priv->work); - mutex_destroy(&priv->lock); } static const struct of_device_id cr0014114_dt_ids[] = { From patchwork Wed Nov 9 08:48:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2019EC43219 for ; Wed, 9 Nov 2022 08:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbiKII1y (ORCPT ); Wed, 9 Nov 2022 03:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbiKII1w (ORCPT ); Wed, 9 Nov 2022 03:27:52 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 176FE13D5E; Wed, 9 Nov 2022 00:27:51 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N6dPh2thDzmVjq; Wed, 9 Nov 2022 16:27:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:49 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Oleh Kravchenko Subject: [PATCH 02/13] leds: el15203000: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:03 +0800 Message-ID: <1667983694-15040-3-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: fc19967bcb8f ("leds: add LED driver for EL15203000 board") Signed-off-by: Wang Yufen Cc: Oleh Kravchenko --- drivers/leds/leds-el15203000.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/leds/leds-el15203000.c b/drivers/leds/leds-el15203000.c index 7e7b617..9be934e 100644 --- a/drivers/leds/leds-el15203000.c +++ b/drivers/leds/leds-el15203000.c @@ -287,10 +287,16 @@ static int el15203000_probe_dt(struct el15203000 *priv) return ret; } +static void el15203000_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int el15203000_probe(struct spi_device *spi) { struct el15203000 *priv; size_t count; + int ret; count = device_get_child_node_count(&spi->dev); if (!count) { @@ -312,15 +318,14 @@ static int el15203000_probe(struct spi_device *spi) spi_set_drvdata(spi, priv); + ret = devm_add_action_or_reset(&spi->dev, el15203000_mutex_destroy, + &priv->lock); + if (ret) + return ret; + return el15203000_probe_dt(priv); } -static void el15203000_remove(struct spi_device *spi) -{ - struct el15203000 *priv = spi_get_drvdata(spi); - - mutex_destroy(&priv->lock); -} static const struct of_device_id el15203000_dt_ids[] = { { .compatible = "crane,el15203000", }, @@ -331,7 +336,6 @@ static void el15203000_remove(struct spi_device *spi) static struct spi_driver el15203000_driver = { .probe = el15203000_probe, - .remove = el15203000_remove, .driver = { .name = KBUILD_MODNAME, .of_match_table = el15203000_dt_ids, From patchwork Wed Nov 9 08:48:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6CF4C43217 for ; Wed, 9 Nov 2022 08:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229877AbiKII1z (ORCPT ); Wed, 9 Nov 2022 03:27:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiKII1w (ORCPT ); Wed, 9 Nov 2022 03:27:52 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF61E13D52; Wed, 9 Nov 2022 00:27:51 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPm58J9zRnvt; Wed, 9 Nov 2022 16:27:40 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:49 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Dan Murphy Subject: [PATCH 03/13] leds: lm3532: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:04 +0800 Message-ID: <1667983694-15040-4-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: bc1b8492c764 ("leds: lm3532: Introduce the lm3532 LED driver") Signed-off-by: Wang Yufen Cc: Dan Murphy --- drivers/leds/leds-lm3532.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index db64d44..a052966 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -663,6 +663,11 @@ static int lm3532_parse_node(struct lm3532_data *priv) return ret; } +static void lm3532_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int lm3532_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -693,6 +698,11 @@ static int lm3532_probe(struct i2c_client *client, } mutex_init(&drvdata->lock); + ret = devm_add_action_or_reset(&client->dev, lm3532_mutex_destroy, + &drvdata->lock); + if (ret) + return ret; + i2c_set_clientdata(client, drvdata); ret = lm3532_parse_node(drvdata); From patchwork Wed Nov 9 08:48:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4DC8C4332F for ; Wed, 9 Nov 2022 08:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbiKII14 (ORCPT ); Wed, 9 Nov 2022 03:27:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiKII1x (ORCPT ); Wed, 9 Nov 2022 03:27:53 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D8013D63; Wed, 9 Nov 2022 00:27:52 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N6dPj35N4zmVlR; Wed, 9 Nov 2022 16:27:37 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:49 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Dan Murphy Subject: [PATCH 04/13] leds: lm3692x: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:05 +0800 Message-ID: <1667983694-15040-5-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 9699cb6bbef2 ("leds: lm3692x: Introduce LM3692x dual string driver") Signed-off-by: Wang Yufen Cc: Dan Murphy --- drivers/leds/leds-lm3692x.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c index 54b4662..aa1b0cc 100644 --- a/drivers/leds/leds-lm3692x.c +++ b/drivers/leds/leds-lm3692x.c @@ -456,6 +456,11 @@ static int lm3692x_probe_dt(struct lm3692x_led *led) return ret; } +static void lm3692x_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int lm3692x_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -472,6 +477,11 @@ static int lm3692x_probe(struct i2c_client *client, led->model_id = id->driver_data; i2c_set_clientdata(client, led); + ret = devm_add_action_or_reset(&client->dev, lm3692x_mutex_destroy, + &led->lock); + if (ret) + return ret; + led->regmap = devm_regmap_init_i2c(client, &lm3692x_regmap_config); if (IS_ERR(led->regmap)) { ret = PTR_ERR(led->regmap); @@ -496,7 +506,6 @@ static void lm3692x_remove(struct i2c_client *client) struct lm3692x_led *led = i2c_get_clientdata(client); lm3692x_leds_disable(led); - mutex_destroy(&led->lock); } static const struct i2c_device_id lm3692x_id[] = { From patchwork Wed Nov 9 08:48:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3591C4332F for ; Wed, 9 Nov 2022 08:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbiKII17 (ORCPT ); Wed, 9 Nov 2022 03:27:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbiKII1x (ORCPT ); Wed, 9 Nov 2022 03:27:53 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62B4A13DFC; Wed, 9 Nov 2022 00:27:52 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPn5PQlzRp6f; Wed, 9 Nov 2022 16:27:41 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:50 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Dan Murphy Subject: [PATCH 05/13] leds: lm3697: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:06 +0800 Message-ID: <1667983694-15040-6-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 5c1d824cda9f ("leds: lm3697: Introduce the lm3697 driver") Signed-off-by: Wang Yufen Cc: Dan Murphy --- drivers/leds/leds-lm3697.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c index 71231a6..a345333 100644 --- a/drivers/leds/leds-lm3697.c +++ b/drivers/leds/leds-lm3697.c @@ -299,6 +299,11 @@ static int lm3697_probe_dt(struct lm3697 *priv) return ret; } +static void lm3697_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int lm3697_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -318,8 +323,12 @@ static int lm3697_probe(struct i2c_client *client, return -ENOMEM; mutex_init(&led->lock); - i2c_set_clientdata(client, led); + ret = devm_add_action_or_reset(&client->dev, lm3697_mutex_destroy, + &led->lock); + if (ret) + return ret; + i2c_set_clientdata(client, led); led->client = client; led->dev = dev; led->num_banks = count; @@ -356,8 +365,6 @@ static void lm3697_remove(struct i2c_client *client) if (ret) dev_err(dev, "Failed to disable regulator\n"); } - - mutex_destroy(&led->lock); } static const struct i2c_device_id lm3697_id[] = { From patchwork Wed Nov 9 08:48:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B21CC43217 for ; Wed, 9 Nov 2022 08:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbiKII2D (ORCPT ); Wed, 9 Nov 2022 03:28:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229861AbiKII1y (ORCPT ); Wed, 9 Nov 2022 03:27:54 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCB513E9E; Wed, 9 Nov 2022 00:27:53 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N6dPl0SP1z15MVD; Wed, 9 Nov 2022 16:27:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:51 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Dan Murphy Subject: [PATCH 06/13] leds: lp50xx: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:07 +0800 Message-ID: <1667983694-15040-7-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 242b81170fb8 ("leds: lp50xx: Add the LP50XX family of the RGB LED driver") Signed-off-by: Wang Yufen Cc: Dan Murphy --- drivers/leds/leds-lp50xx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c index 28d6b39..fcec568e 100644 --- a/drivers/leds/leds-lp50xx.c +++ b/drivers/leds/leds-lp50xx.c @@ -521,6 +521,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv) return ret; } +static void lp50xx_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int lp50xx_probe(struct i2c_client *client) { struct lp50xx *led; @@ -539,6 +544,11 @@ static int lp50xx_probe(struct i2c_client *client) return -ENOMEM; mutex_init(&led->lock); + ret = devm_add_action_or_reset(&client->dev, lp50xx_mutex_destroy, + &led->lock); + if (ret) + return ret; + led->client = client; led->dev = &client->dev; led->chip_info = device_get_match_data(&client->dev); @@ -577,8 +587,6 @@ static void lp50xx_remove(struct i2c_client *client) if (ret) dev_err(led->dev, "Failed to disable regulator\n"); } - - mutex_destroy(&led->lock); } static const struct i2c_device_id lp50xx_id[] = { From patchwork Wed Nov 9 08:48:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1733FC433FE for ; Wed, 9 Nov 2022 08:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiKII2F (ORCPT ); Wed, 9 Nov 2022 03:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbiKII1y (ORCPT ); Wed, 9 Nov 2022 03:27:54 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4786B13D16; Wed, 9 Nov 2022 00:27:53 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPW0SvtzHvk6; Wed, 9 Nov 2022 16:27:27 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:51 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Dan Murphy Subject: [PATCH 07/13] leds: lp8860: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:08 +0800 Message-ID: <1667983694-15040-8-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: a2169c9b762a ("leds: lp8860: Various fixes to align with LED framework") Signed-off-by: Wang Yufen Cc: Dan Murphy --- drivers/leds/leds-lp8860.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c index e2b36d3..ca73d91 100644 --- a/drivers/leds/leds-lp8860.c +++ b/drivers/leds/leds-lp8860.c @@ -375,6 +375,11 @@ static int lp8860_init(struct lp8860_led *led) .cache_type = REGCACHE_NONE, }; +static void lp8860_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int lp8860_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -408,6 +413,10 @@ static int lp8860_probe(struct i2c_client *client, led->led_dev.brightness_set_blocking = lp8860_brightness_set; mutex_init(&led->lock); + ret = devm_add_action_or_reset(&client->dev, lp8860_mutex_destroy, + &led->lock); + if (ret) + return ret; i2c_set_clientdata(client, led); @@ -459,8 +468,6 @@ static void lp8860_remove(struct i2c_client *client) dev_err(&led->client->dev, "Failed to disable regulator\n"); } - - mutex_destroy(&led->lock); } static const struct i2c_device_id lp8860_id[] = { From patchwork Wed Nov 9 08:48:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15A1AC43219 for ; Wed, 9 Nov 2022 08:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbiKII2A (ORCPT ); Wed, 9 Nov 2022 03:28:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbiKII1y (ORCPT ); Wed, 9 Nov 2022 03:27:54 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5F0E13D52; Wed, 9 Nov 2022 00:27:53 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N6dPl12WNzmVnl; Wed, 9 Nov 2022 16:27:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:51 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Vadim Pasternak Subject: [PATCH 08/13] leds: mlxreg: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:09 +0800 Message-ID: <1667983694-15040-9-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 386570d76f2f ("leds: add driver for support Mellanox regmap LEDs for BMC and x86 platform") Signed-off-by: Wang Yufen Cc: Vadim Pasternak --- drivers/leds/leds-mlxreg.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/leds/leds-mlxreg.c b/drivers/leds/leds-mlxreg.c index b7855c9..b7c58fb 100644 --- a/drivers/leds/leds-mlxreg.c +++ b/drivers/leds/leds-mlxreg.c @@ -254,10 +254,16 @@ static int mlxreg_led_config(struct mlxreg_led_priv_data *priv) return 0; } +static void mlxreg_led_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int mlxreg_led_probe(struct platform_device *pdev) { struct mlxreg_core_platform_data *led_pdata; struct mlxreg_led_priv_data *priv; + int ret; led_pdata = dev_get_platdata(&pdev->dev); if (!led_pdata) { @@ -273,24 +279,18 @@ static int mlxreg_led_probe(struct platform_device *pdev) priv->pdev = pdev; priv->pdata = led_pdata; + ret = devm_add_action_or_reset(&pdev->dev, mlxreg_led_mutex_destroy, + &priv->access_lock); + if (ret) + return ret; return mlxreg_led_config(priv); } -static int mlxreg_led_remove(struct platform_device *pdev) -{ - struct mlxreg_led_priv_data *priv = dev_get_drvdata(&pdev->dev); - - mutex_destroy(&priv->access_lock); - - return 0; -} - static struct platform_driver mlxreg_led_driver = { .driver = { .name = "leds-mlxreg", }, .probe = mlxreg_led_probe, - .remove = mlxreg_led_remove, }; module_platform_driver(mlxreg_led_driver); From patchwork Wed Nov 9 08:48:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB2DFC4332F for ; Wed, 9 Nov 2022 08:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiKII2F (ORCPT ); Wed, 9 Nov 2022 03:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbiKII1z (ORCPT ); Wed, 9 Nov 2022 03:27:55 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3051E13D5E; Wed, 9 Nov 2022 00:27:54 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N6dPl45LczmVnk; Wed, 9 Nov 2022 16:27:39 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:52 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Sean Wang Subject: [PATCH 09/13] leds: mt6323: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:10 +0800 Message-ID: <1667983694-15040-10-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC") Signed-off-by: Wang Yufen Cc: Sean Wang --- drivers/leds/leds-mt6323.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c index f59e0e8..2dacaca 100644 --- a/drivers/leds/leds-mt6323.c +++ b/drivers/leds/leds-mt6323.c @@ -361,6 +361,11 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev, return ret; } +static void mt6323_led_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int mt6323_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -386,6 +391,10 @@ static int mt6323_led_probe(struct platform_device *pdev) */ leds->hw = hw; mutex_init(&leds->lock); + ret = devm_add_action_or_reset(dev, mt6323_led_mutex_destroy, + &leds->lock); + if (ret) + return ret; status = MT6323_RG_DRV_32K_CK_PDN; ret = regmap_update_bits(leds->hw->regmap, MT6323_TOP_CKPDN0, @@ -464,8 +473,6 @@ static int mt6323_led_remove(struct platform_device *pdev) MT6323_RG_DRV_32K_CK_PDN_MASK, MT6323_RG_DRV_32K_CK_PDN); - mutex_destroy(&leds->lock); - return 0; } From patchwork Wed Nov 9 08:48:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A827C433FE for ; Wed, 9 Nov 2022 08:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbiKII2I (ORCPT ); Wed, 9 Nov 2022 03:28:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiKII1z (ORCPT ); Wed, 9 Nov 2022 03:27:55 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A34013D63; Wed, 9 Nov 2022 00:27:54 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N6dPm5WCCz15MR9; Wed, 9 Nov 2022 16:27:40 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:52 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Vasant Hegde Subject: [PATCH 10/13] leds: powernv: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:11 +0800 Message-ID: <1667983694-15040-11-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: 84ad6e5cd3e8 ("leds/powernv: Add driver for PowerNV platform") Signed-off-by: Wang Yufen Cc: Vasant Hegde --- drivers/leds/leds-powernv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c index 743e2cd..535f295 100644 --- a/drivers/leds/leds-powernv.c +++ b/drivers/leds/leds-powernv.c @@ -275,6 +275,11 @@ static int powernv_led_classdev(struct platform_device *pdev, return rc; } +static void powernv_led_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + /* Platform driver probe */ static int powernv_led_probe(struct platform_device *pdev) { @@ -298,6 +303,10 @@ static int powernv_led_probe(struct platform_device *pdev) } mutex_init(&powernv_led_common->lock); + ret = devm_add_action_or_reset(dev, powernv_led_mutex_destroy, + &powernv_led_common->lock); + if (ret) + return ret; powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX); platform_set_drvdata(pdev, powernv_led_common); @@ -317,9 +326,6 @@ static int powernv_led_remove(struct platform_device *pdev) powernv_led_common = platform_get_drvdata(pdev); powernv_led_common->led_disabled = true; - /* Destroy lock */ - mutex_destroy(&powernv_led_common->lock); - dev_info(&pdev->dev, "PowerNV led module unregistered\n"); return 0; } From patchwork Wed Nov 9 08:48:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3754CC43219 for ; Wed, 9 Nov 2022 08:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbiKII2J (ORCPT ); Wed, 9 Nov 2022 03:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbiKII1z (ORCPT ); Wed, 9 Nov 2022 03:27:55 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F355213DFC; Wed, 9 Nov 2022 00:27:54 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPX5JqSzHvkj; Wed, 9 Nov 2022 16:27:28 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:53 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Baolin Wang Subject: [PATCH 11/13] leds: sc27xx: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:12 +0800 Message-ID: <1667983694-15040-12-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: e081c49e30ec ("leds: Add Spreadtrum SC27xx breathing light controller driver") Signed-off-by: Wang Yufen Cc: Baolin Wang --- drivers/leds/leds-sc27xx-bltc.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c index e199ea1..43a821c 100644 --- a/drivers/leds/leds-sc27xx-bltc.c +++ b/drivers/leds/leds-sc27xx-bltc.c @@ -273,6 +273,11 @@ static int sc27xx_led_register(struct device *dev, struct sc27xx_led_priv *priv) return 0; } +static void sc27xx_led_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int sc27xx_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -297,6 +302,11 @@ static int sc27xx_led_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); mutex_init(&priv->lock); + err = devm_add_action_or_reset(dev, sc27xx_led_mutex_destroy, + &priv->lock); + if (err) + return err; + priv->base = base; priv->regmap = dev_get_regmap(dev->parent, NULL); if (!priv->regmap) { @@ -309,13 +319,11 @@ static int sc27xx_led_probe(struct platform_device *pdev) err = of_property_read_u32(child, "reg", ®); if (err) { of_node_put(child); - mutex_destroy(&priv->lock); return err; } if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) { of_node_put(child); - mutex_destroy(&priv->lock); return -EINVAL; } @@ -323,19 +331,7 @@ static int sc27xx_led_probe(struct platform_device *pdev) priv->leds[reg].active = true; } - err = sc27xx_led_register(dev, priv); - if (err) - mutex_destroy(&priv->lock); - - return err; -} - -static int sc27xx_led_remove(struct platform_device *pdev) -{ - struct sc27xx_led_priv *priv = platform_get_drvdata(pdev); - - mutex_destroy(&priv->lock); - return 0; + return sc27xx_led_register(dev, priv); } static const struct of_device_id sc27xx_led_of_match[] = { @@ -350,7 +346,6 @@ static int sc27xx_led_remove(struct platform_device *pdev) .of_match_table = sc27xx_led_of_match, }, .probe = sc27xx_led_probe, - .remove = sc27xx_led_remove, }; module_platform_driver(sc27xx_led_driver); From patchwork Wed Nov 9 08:48:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5111DC433FE for ; Wed, 9 Nov 2022 08:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiKII2K (ORCPT ); Wed, 9 Nov 2022 03:28:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbiKII14 (ORCPT ); Wed, 9 Nov 2022 03:27:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6522913F99; Wed, 9 Nov 2022 00:27:55 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPr56sDzRnvt; Wed, 9 Nov 2022 16:27:44 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:53 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Christian Mauderer Subject: [PATCH 12/13] leds: spi-byte: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:13 +0800 Message-ID: <1667983694-15040-13-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: e9a804d7a428 ("leds: spi-byte: add single byte SPI LED driver") Signed-off-by: Wang Yufen Cc: Christian Mauderer --- drivers/leds/leds-spi-byte.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c index 2bc5c99..a169780 100644 --- a/drivers/leds/leds-spi-byte.c +++ b/drivers/leds/leds-spi-byte.c @@ -78,6 +78,11 @@ static int spi_byte_brightness_set_blocking(struct led_classdev *dev, return ret; } +static void spi_byte_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int spi_byte_probe(struct spi_device *spi) { struct device_node *child; @@ -101,6 +106,10 @@ static int spi_byte_probe(struct spi_device *spi) strlcpy(led->name, name, sizeof(led->name)); led->spi = spi; mutex_init(&led->mutex); + ret = devm_add_action_or_reset(dev, spi_byte_mutex_destroy, + &led->mutex); + if (ret) + return ret; led->cdef = device_get_match_data(dev); led->ldev.name = led->name; led->ldev.brightness = LED_OFF; @@ -121,25 +130,15 @@ static int spi_byte_probe(struct spi_device *spi) led->ldev.brightness); ret = devm_led_classdev_register(&spi->dev, &led->ldev); - if (ret) { - mutex_destroy(&led->mutex); + if (ret) return ret; - } spi_set_drvdata(spi, led); return 0; } -static void spi_byte_remove(struct spi_device *spi) -{ - struct spi_byte_led *led = spi_get_drvdata(spi); - - mutex_destroy(&led->mutex); -} - static struct spi_driver spi_byte_driver = { .probe = spi_byte_probe, - .remove = spi_byte_remove, .driver = { .name = KBUILD_MODNAME, .of_match_table = spi_byte_dt_ids, From patchwork Wed Nov 9 08:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 623501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90184C4167B for ; Wed, 9 Nov 2022 08:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbiKII2J (ORCPT ); Wed, 9 Nov 2022 03:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiKII14 (ORCPT ); Wed, 9 Nov 2022 03:27:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9DDF1B9F5; Wed, 9 Nov 2022 00:27:55 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPs10w4zRp7v; Wed, 9 Nov 2022 16:27:45 +0800 (CST) Received: from localhost.localdomain (10.175.112.70) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 16:27:53 +0800 From: Wang Yufen To: , CC: , Wang Yufen , Linus Walleij Subject: [PATCH 13/13] leds: rt8515: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:14 +0800 Message-ID: <1667983694-15040-14-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> References: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Fixes: e1c6edcbea13 ("leds: rt8515: Add Richtek RT8515 LED driver") Signed-off-by: Wang Yufen Cc: Linus Walleij --- drivers/leds/flash/leds-rt8515.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/leds/flash/leds-rt8515.c b/drivers/leds/flash/leds-rt8515.c index 44904fde..f2d92ea 100644 --- a/drivers/leds/flash/leds-rt8515.c +++ b/drivers/leds/flash/leds-rt8515.c @@ -273,6 +273,11 @@ static void rt8515_determine_max_intensity(struct rt8515 *rt, *max_intensity_setting = max_intensity; } +static void rt8515_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int rt8515_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -338,13 +343,16 @@ static int rt8515_probe(struct platform_device *pdev) led->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; mutex_init(&rt->lock); + ret = devm_add_action_or_reset(dev, rt8515_mutex_destroy, + &rt->lock); + if (ret) + return ret; platform_set_drvdata(pdev, rt); ret = devm_led_classdev_flash_register_ext(dev, fled, &init_data); if (ret) { fwnode_handle_put(child); - mutex_destroy(&rt->lock); dev_err(dev, "can't register LED %s\n", led->name); return ret; } @@ -373,7 +381,6 @@ static int rt8515_remove(struct platform_device *pdev) rt8515_v4l2_flash_release(rt); del_timer_sync(&rt->powerdown_timer); - mutex_destroy(&rt->lock); return 0; }