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,