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; }