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