From patchwork Tue Nov 8 03:28:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 16840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2459001wru; Mon, 7 Nov 2022 19:34:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM6SlaAwq6UqNGAiRkb3BuWZq/QXuKW6mKGFF5Y/mOCpjAyWC9hHLCeHe6ibzCj+WCCuz0uq X-Received: by 2002:a17:906:9bd5:b0:7ae:2964:72c8 with SMTP id de21-20020a1709069bd500b007ae296472c8mr20957129ejc.494.1667878443263; Mon, 07 Nov 2022 19:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667878443; cv=none; d=google.com; s=arc-20160816; b=CL/5BdAqHFm94uCqlOpbZbVNP8WyXN+GybtI+izfSS0F/UcLd9gqJsdJpmrLIbE/R+ nbdi9mGyJiRiHRa5TS/mqcqQSb/fFLtgVhnxAaK+5CpPbq6gvwdm5dGWH8VkpldXX2+c 9MJQdeJfPuiITQliZw6shWJUcN6+6tv9hXcQjj3oxcNMgFaLowt0O6iCiMzMRNy0svIx YXFGzumR038a3T7ynBibpNOc0Wk/UzotkJkvnronVMJnAgnbYRR2zE+nYLW9FW7jJ85I mJsBkc3FaKGHTPjizvwOirLqfgYtQSVf81vvEpzpBuuZ8Qizq5aN+pad0Tg+DyKyDhFK Xnlw== 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=VgN006i01hHnPCyCEgTMMmUhG1bGax6M0Qi/YYdKSZU=; b=w5ddQF58BCnW7deYQAP4Zf99hElDMjYB6gsch+/fQsOaYyX3lDoP++QfsvIHHTJ7hk 4UZO2FolNh8sc+ldlKrTLE2x5PSLr66EXrmxzyW5zLiARh4NqWsgS1D/8oti61qGOo12 W757wPQL10YYv/iv0zcpdHvRRQC1c/eQ1KkpYUGI4OvkZyyzGjruVGvahPU0Ot4S7HLW zv9xPV/G87Wnglgizvs8StaWkl9NrHkiLBMhzN3h6/whOYb6yo3xo9CTIZgB/ye0gWYz ba+Jhh/wjz/uGVTB7A0SkcD2nr8yg20IAGYeKTav0TL4gt0l+Nayu4anSARIdNNoMgYH Np6g== 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 y11-20020a056402170b00b0046154f0f866si10201791edu.159.2022.11.07.19.33.38; Mon, 07 Nov 2022 19:34:03 -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 S232307AbiKHDbU (ORCPT + 99 others); Mon, 7 Nov 2022 22:31:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbiKHDbT (ORCPT ); Mon, 7 Nov 2022 22:31:19 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CC7C2F397; Mon, 7 Nov 2022 19:31:18 -0800 (PST) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N5tt20sn1z15MTB; Tue, 8 Nov 2022 11:31:06 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:31:16 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:31:16 +0800 From: Chen Zhongjin To: , CC: , , , Subject: [PATCH] iio: core: Fix entry not deleted when iio_register_sw_trigger_type() fails Date: Tue, 8 Nov 2022 11:28:02 +0800 Message-ID: <20221108032802.168623-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) 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?1748897306448634955?= X-GMAIL-MSGID: =?utf-8?q?1748897306448634955?= In iio_register_sw_trigger_type(), configfs_register_default_group() is possible to fail, but the entry add to iio_trigger_types_list is not deleted. This leaves wild in iio_trigger_types_list, which can cause page fault when module is loading again. So fix this by list_del(&t->list) in error path. BUG: unable to handle page fault for address: fffffbfff81d7400 RIP: 0010:__iio_find_sw_trigger_type.isra.3+0x62/0xb0 [industrialio_sw_trigger] Call Trace: iio_register_sw_trigger_type+0x65/0x1f0 [industrialio_sw_trigger] do_one_initcall+0xd0/0x4e0 do_init_module+0x1cf/0x6b0 load_module+0x65c2/0x7820 ... Fixes: b662f809d410 ("iio: core: Introduce IIO software triggers") Signed-off-by: Chen Zhongjin --- drivers/iio/industrialio-sw-trigger.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-sw-trigger.c b/drivers/iio/industrialio-sw-trigger.c index 994f03a71520..d86a3305d9e8 100644 --- a/drivers/iio/industrialio-sw-trigger.c +++ b/drivers/iio/industrialio-sw-trigger.c @@ -58,8 +58,12 @@ int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t) t->group = configfs_register_default_group(iio_triggers_group, t->name, &iio_trigger_type_group_type); - if (IS_ERR(t->group)) + if (IS_ERR(t->group)) { + mutex_lock(&iio_trigger_types_lock); + list_del(&t->list); + mutex_unlock(&iio_trigger_types_lock); ret = PTR_ERR(t->group); + } return ret; }