Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp196125rwb; Wed, 9 Nov 2022 00:51:05 -0800 (PST) X-Google-Smtp-Source: AMsMyM512+z3wMuUgngFRbhFUDSpbMwKP+7i/ETRYyPsgGEDoPCDKfYu5wvWtkw0joX7IDsy2Sz9 X-Received: by 2002:a05:6402:690:b0:461:9193:7278 with SMTP id f16-20020a056402069000b0046191937278mr1125778edy.220.1667983865216; Wed, 09 Nov 2022 00:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667983865; cv=none; d=google.com; s=arc-20160816; b=yGYC2unXYio/x4Oi8+vY0K6k0kIGQKFrW3JgvcQuU+wLdCiu1efBjh1JViE9B2qRKv UTtnrl2tngHhCzmwwFOvXvNduf2dLHRuDyxhlW3zE4bms1wM+JoEAZTLndN4EXoJ63hY 4bnVPfPRvZvwfnIqJH0e7jL8oj4kCTkoTzTvzGZtP+MMYwQc4KM5NZrZgJWKkmU5L6WP +EghvT65R0AOtSaujPzpkHocwZyUYAt34IGWCBQxCTR9KqrCKapeYfgARx6QPl5OJ6ca 40lkt4sHFb+2XmY/qwauzfwiftt41RGi8KHr4D6mIrcb/ZT5h0X0S54hZEaJMSB3n1BL quTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=zNgjc1HLw5ObxLyV3ckO2dl3MTgKrUWmhIF9RwCK1Xc=; b=pC/EA8gaeBBhUGwrpy+6d2xAxIyfQpwiNLluNATWbNOdTMD2NzaNcnhuNhmC5XvsDE MWNK+SJUZ5BpJT4FNcJq8BzBL+8IezAIUdy8VpOP7VyHhjteyRAxYIBQVBLMaYdIvKNA 44RYAMutRw+CZ4ywIfSntxS/rDVzcBaE9WPfLeF6nBql13NqJjDzn21QjnkrNbguM/zp U5HD8vqaa6cBt95FTRX7cFGteH+ma4k03C7Wdl9gLgkEHu84fo5G+EmV6c7YthdQdM+j 2f/QZfE8QGVo3LOoQz0b5PtSqrt/pvEsZVT6NzlaAGe29LyQx7sFV86VdJRovqblPxbK Gd9g== 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 mp3-20020a1709071b0300b0078d0f57b0e2si15998495ejc.412.2022.11.09.00.50.42; Wed, 09 Nov 2022 00:51:05 -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 S230001AbiKII2t (ORCPT + 93 others); Wed, 9 Nov 2022 03:28:49 -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 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 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, -- 1.8.3.1