From patchwork Wed Nov 9 08:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyufen X-Patchwork-Id: 17390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp216407wru; Wed, 9 Nov 2022 00:30:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM4+TwOFkDKhE+5OvVzieqwhT9CkMwAiESANqjpzWhMglcOKNgpc3zlMIrYoPhO6xmuUMJD/ X-Received: by 2002:a17:907:7250:b0:791:9093:47f7 with SMTP id ds16-20020a170907725000b00791909347f7mr56169191ejc.278.1667982625144; Wed, 09 Nov 2022 00:30:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667982625; cv=none; d=google.com; s=arc-20160816; b=hLpQaGjGgBsRvGNjNKPBZ7WErnh2bq0TJYXn2BMmGYApsBiA5zlVqMrdwQPCKfjsRE i5bIgxPzkJjurO+H4bEZrXCXVz82CXeqqWqZXwogflJ6KNNplHWLi4XEDPMeoT3aidO2 4UcmK0x3XZrbcG2cfHXg4KSeEdPwss/MADtAvVvMk1G1NTk4mbNDAKz4dYsg+zCxoI6D sX0jDUmGRdpeqw6JTJf9BAg8lqqYw2m9DyqxCiGl6kfIF1k/IJ3hwd/9laThvWGnzkLc 7JQ+P47viZjgsXqjrMNGxc4ZJXXup3RavBYk4rzAJzhttaovhHrWI3/7wxfelVopoEVS c72w== 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=sQcnbJ0+uPaSqOl6ygyqwBv++idbM8JHHLMzSmGnF30=; b=0uWBVIUvg66OJ5wytvZPaQkGBKmeh88Ws+ebqFG5xhpXBUaHn0dpdvT+4aJzKqgB4K Z88mFgTJZeleKV8Ea7ABNJeEj9zNGbbt4oM13qHJLPjtsI5Nwf7v0L+SHHKr51iDtHa+ xq50FHm57EdsUjrEd8BUCAvA7BIeP/sPWK/eEizvZR2ioc/xjmYLz3WMu/AGBHumX1Me gCCAoM3KTz9Xm+FTWC7T2GnMfakXwKlhUYHnQcs7eh3NfIPDH4jgYDUnMZdHEtz5nMDk p56m73Y5f1BQtMhcj+QM1c+COyruNPS/tnrw/eskgudhY4xR8WMd1oXGJ4vUQM4sUHHc ANxw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uz13-20020a170907118d00b00730936657d1si11798419ejb.552.2022.11.09.00.30.00; Wed, 09 Nov 2022 00:30:25 -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 S230043AbiKII2q (ORCPT + 99 others); Wed, 9 Nov 2022 03:28:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiKII14 (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 C9DDF1B9F5; Wed, 9 Nov 2022 00:27:55 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6dPs10w4zRp7v; Wed, 9 Nov 2022 16:27:45 +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 , Linus Walleij Subject: [PATCH 13/13] leds: rt8515: Fix devm vs. non-devm ordering Date: Wed, 9 Nov 2022 16:48:14 +0800 Message-ID: <1667983694-15040-14-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749006549155837339?= X-GMAIL-MSGID: =?utf-8?q?1749006549155837339?= 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: e1c6edcbea13 ("leds: rt8515: Add Richtek RT8515 LED driver") Signed-off-by: Wang Yufen Cc: Linus Walleij --- drivers/leds/flash/leds-rt8515.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/leds/flash/leds-rt8515.c b/drivers/leds/flash/leds-rt8515.c index 44904fde..f2d92ea 100644 --- a/drivers/leds/flash/leds-rt8515.c +++ b/drivers/leds/flash/leds-rt8515.c @@ -273,6 +273,11 @@ static void rt8515_determine_max_intensity(struct rt8515 *rt, *max_intensity_setting = max_intensity; } +static void rt8515_mutex_destroy(void *lock) +{ + mutex_destroy(lock); +} + static int rt8515_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -338,13 +343,16 @@ static int rt8515_probe(struct platform_device *pdev) led->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; mutex_init(&rt->lock); + ret = devm_add_action_or_reset(dev, rt8515_mutex_destroy, + &rt->lock); + if (ret) + return ret; platform_set_drvdata(pdev, rt); ret = devm_led_classdev_flash_register_ext(dev, fled, &init_data); if (ret) { fwnode_handle_put(child); - mutex_destroy(&rt->lock); dev_err(dev, "can't register LED %s\n", led->name); return ret; } @@ -373,7 +381,6 @@ static int rt8515_remove(struct platform_device *pdev) rt8515_v4l2_flash_release(rt); del_timer_sync(&rt->powerdown_timer); - mutex_destroy(&rt->lock); return 0; }