Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp191640rwb; Wed, 9 Nov 2022 00:45:20 -0800 (PST) X-Google-Smtp-Source: AMsMyM6EaHChjfdeG9uvfwAhbbnNDtaIHHfniMNRXaS5XhyRiTc6w/s/2AtnXTHWNdkCb1uMs0wN X-Received: by 2002:aa7:c417:0:b0:463:3f0c:be12 with SMTP id j23-20020aa7c417000000b004633f0cbe12mr51733079edq.35.1667983520137; Wed, 09 Nov 2022 00:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667983520; cv=none; d=google.com; s=arc-20160816; b=JWcqRE5aAVovlYxncFO6JaUlnJYHAdWrYioABycC5aBu7FSBZo67kkYOiY9ucJuqlW TRhHfSkxJZQfWEt/wHzYNsobfUJPE2jmXFt4KmsiE+hVRpiUvcKAfcOwRa9DZ2HOydY/ RYO8oaKHw9Iy3EIzFmROvo468KhGfth/zGuPXR9ysxYkPopMlP6BfyqyiqQ3FO8g7/7+ Hdl1DXsDT26Fbrgd5lo/eflcDpnnFlvZh42wi7N5dHYYFiGQFRx8m4NPqqF1LarJjCQZ SZy9Gn556is5gbjgRr86aFHm+v4K2laNtSma7s0wZTAgoIVB2tgyZIAL1wIz4aih3DqP ULbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=fFscLYX4SrEDH/to1b8oo3BKcePPp2IBYbal9HbrQfk=; b=Ioe0FNdMgX6afmIugM6PSgB0VyI4XH5FksU2vmEjIPlBgH+q6nBXQvJFIcuTdBcQyZ g0Q9JkQkutOJ4gg5rpZ7RRabwpZmm3nOsuNd2yJL5mPhwlc3YJeSreY7r7hzZAfHq78O x1S6WFjWJUuxpWKtrj+F01+jopyZbgVvH5dlPbCdghNaKhqJZb/qecOV3n/E4FVM1Mj0 /nec7Q0rimQgM9+L98rD3BRHJzbP7MdH5wFvJAcVqzXfNX9hCQaL1FeluLl9mj3GjQi8 Lo7tIXUmi0nbfOWM/7JpGLSdJHk2RB/U4Tp2Sne5L/N+7g+D7/+wQ4IuqOgO5exRMkla Pe4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020aa7db4f000000b0046159da6233si12377274edt.145.2022.11.09.00.44.55; Wed, 09 Nov 2022 00:45:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiKII14 (ORCPT + 94 others); Wed, 9 Nov 2022 03:27:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiKII1v (ORCPT ); Wed, 9 Nov 2022 03:27:51 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FD5E13D52; Wed, 9 Nov 2022 00:27:50 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N6dLR2gyvzJnRL; Wed, 9 Nov 2022 16:24:47 +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 Subject: [PATCH 00/13] leds: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:01 +0800 Message-ID: <1667983694-15040-1-git-send-email-wangyufen@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fault-inject tests reports this issue: DEBUG_LOCKS_WARN_ON(lock->magic != lock) WARNING: CPU: 2 PID: 52 at kernel/locking/mutex.c:582 __mutex_lock+0x1366/0x15b0 Call Trace: cr0014114_set_sync+0x2d/0x80 [leds_cr0014114 dbd1de3fefae3e163bcc08f4eeaa6d1b243203a9] set_brightness_delayed+0xc2/0x140 process_one_work+0x651/0xc30 worker_thread+0x30b/0x820 kthread+0x1a0/0x1e0 ret_from_fork+0x1f/0x30 The issue occurs in the following scenarios: .probe() mutex_init() led->brightness_set_blocking = callback <-- e.g. cr0014114_set_sync() devm_led_classdev_register_ext() <-- dr->node.release = devm_led_classdev_release() ... .remove() mutex_destroy(lock) <-- lock destroy worker_thread() set_brightness_work set_brightness_delayed() __led_set_brightness_blocking() led_cdev->brightness_set_blocking() <-- callback, e.g. cr0014114_set_sync() mutex_lock(lock) <-- lock is used after destroy .release() devm_led_classdev_release() led_classdev_unregister() <-- flush set_brightness_work 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(). Wang Yufen (13): leds: cr0014114: Fix devm vs. non-devm ordering leds: el15203000: Fix devm vs. non-devm ordering leds: lm3532: Fix devm vs. non-devm ordering leds: lm3692x: Fix devm vs. non-devm ordering leds: lm3697: Fix devm vs. non-devm ordering leds: lp50xx: Fix devm vs. non-devm ordering leds: lp8860: Fix devm vs. non-devm ordering leds: mlxreg: Fix devm vs. non-devm ordering leds: mt6323: Fix devm vs. non-devm ordering leds: powernv: Fix devm vs. non-devm ordering leds: sc27xx: Fix devm vs. non-devm ordering leds: spi-byte: Fix devm vs. non-devm ordering leds: rt8515: Fix devm vs. non-devm ordering drivers/leds/flash/leds-rt8515.c | 11 +++++++++-- drivers/leds/leds-cr0014114.c | 11 ++++++++++- drivers/leds/leds-el15203000.c | 18 +++++++++++------- drivers/leds/leds-lm3532.c | 10 ++++++++++ drivers/leds/leds-lm3692x.c | 11 ++++++++++- drivers/leds/leds-lm3697.c | 13 ++++++++++--- drivers/leds/leds-lp50xx.c | 12 ++++++++++-- drivers/leds/leds-lp8860.c | 11 +++++++++-- drivers/leds/leds-mlxreg.c | 20 ++++++++++---------- drivers/leds/leds-mt6323.c | 11 +++++++++-- drivers/leds/leds-powernv.c | 12 +++++++++--- drivers/leds/leds-sc27xx-bltc.c | 27 +++++++++++---------------- drivers/leds/leds-spi-byte.c | 21 ++++++++++----------- 13 files changed, 128 insertions(+), 60 deletions(-) -- 1.8.3.1