Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4240870rwb; Sun, 13 Nov 2022 01:46:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4f78M0zPKOpwBzBn81xN3qdCvScLtmuhy0Bw+gkPvf5dYi2RxUu1ba3z9BxjeXKxM+/8Ng X-Received: by 2002:a17:902:6b0b:b0:188:5698:6b69 with SMTP id o11-20020a1709026b0b00b0018856986b69mr9308743plk.142.1668332802796; Sun, 13 Nov 2022 01:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668332802; cv=none; d=google.com; s=arc-20160816; b=Duv/w8BOwmQbiBl0CLs/PFJjrrdALWVhH+7/IXGSckEGzKxjaWMffaIKLN+wG1aYeA 4yMrFgCRiWDYS2YG5HyV7X5ZFwsFwOnjxVIz5dXewWo1B6ijdi87n9am5NZhoPXR5M7F Mo+o8lxWlM5yFz1zos4MjA25dq5ZjErhJYsnmlaATHbIv3qdBYjDJIlH58PgueREDU49 RW5WW+jQDd/LKPKldMC8tdTy282srS4L6lNY0+V9B55zlwbgxnMICbLiMVDuQz11fg4M GPVktNNpDqf5yG78jDSDoRjN+xuWuRfwyfdS1inMVYAxkU5hxiRPbvi14Q1SaAUbW81I pG3Q== 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=ZaPV9Y2G/6l2+rdOcKaK/SwV6JT8bRuapZ8sG6iTplk=; b=v0caTiEUivoIqOxuidX4pl3vk1GuKRO0XTvAJBF3WDpIZ9je/ehpsrwD8+3unWGSiB H+xHURTbupaYu6bTegWwCPIfRsvKjCgHKrpmmO0Wj50ycV1vy7DCL3ODiJ51IMG2oQvo WD7IOlqiEn9+xLfUm7hMmUh2eilsqYruUU8MLnN0QT+4qHi9sH6iRuGnGidoDKK6mJ9J FtR0iLf7vu7IbVQYwOkai/k2GFJGKCVoICHDoSltDz/7zGpj2h2prN/iansnmbSQstOX TpAr+RnnpLGTE2DZp3MC5vitikTj+icSdQeJb2Qz3uiGDazI123D2KV21ze47MAhe1li MrJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 pv8-20020a17090b3c8800b0021330e6afdfsi11624720pjb.146.2022.11.13.01.46.17; Sun, 13 Nov 2022 01:46:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S235153AbiKMJdV (ORCPT + 99 others); Sun, 13 Nov 2022 04:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbiKMJdV (ORCPT ); Sun, 13 Nov 2022 04:33:21 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868C012A8C for ; Sun, 13 Nov 2022 01:33:20 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N96gM3bpnzRp1W; Sun, 13 Nov 2022 17:33:03 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 13 Nov 2022 17:33:18 +0800 From: Yuan Can To: , , , CC: Subject: [PATCH] crypto: ccree - Fix error handling in ccree_init() Date: Sun, 13 Nov 2022 09:31:37 +0000 Message-ID: <20221113093137.20178-1-yuancan@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500024.china.huawei.com (7.185.36.10) 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-crypto@vger.kernel.org A problem about ccree create debugfs failed is triggered with the following log given: [ 398.049333] debugfs: Directory 'ccree' with parent '/' already present! The reason is that ccree_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without remove debugfs of ccree, resulting the debugfs of ccree can never be created later. A simple call graph is shown as below: ccree_init() cc_debugfs_global_init() # create debugfs ccree platform_driver_register() driver_register() bus_add_driver() dev = kzalloc(...) # OOM happened # return without destroy debugfs ccree Fix by removing debugfs when platform_driver_register() returns error. Fixes: 4c3f97276e15 ("crypto: ccree - introduce CryptoCell driver") Signed-off-by: Yuan Can --- drivers/crypto/ccree/cc_debugfs.c | 2 +- drivers/crypto/ccree/cc_driver.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccree/cc_debugfs.c b/drivers/crypto/ccree/cc_debugfs.c index 7083767602fc..8f008f024f8f 100644 --- a/drivers/crypto/ccree/cc_debugfs.c +++ b/drivers/crypto/ccree/cc_debugfs.c @@ -55,7 +55,7 @@ void __init cc_debugfs_global_init(void) cc_debugfs_dir = debugfs_create_dir("ccree", NULL); } -void __exit cc_debugfs_global_fini(void) +void cc_debugfs_global_fini(void) { debugfs_remove(cc_debugfs_dir); } diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index cadead18b59e..1969d1e6df40 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -651,9 +651,15 @@ static struct platform_driver ccree_driver = { static int __init ccree_init(void) { + int ret; + cc_debugfs_global_init(); - return platform_driver_register(&ccree_driver); + ret = platform_driver_register(&ccree_driver); + if (ret) + cc_debugfs_global_fini(); + + return ret; } module_init(ccree_init); -- 2.17.1