From patchwork Tue Mar 7 16:53:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542679wrd; Tue, 7 Mar 2023 09:01:59 -0800 (PST) X-Google-Smtp-Source: AK7set/p46GZ04b5LMhXs0LPPRsBI87Or/gdw0eMj5LcS/QKxeAlveLnUxq9gMgAwr7OFv4DVsbp X-Received: by 2002:a17:906:a882:b0:8aa:a802:adcd with SMTP id ha2-20020a170906a88200b008aaa802adcdmr13880774ejb.30.1678208519709; Tue, 07 Mar 2023 09:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208519; cv=none; d=google.com; s=arc-20160816; b=oJloDzQwqmZXEE1HZhPryEwt8ISeSHPRXpwVRaUYaC/CLExubXB40ph+BvUOHk97Di WEB4AlGOiD8hdl6JaxZrz4HhI0U6b7SPFOgYsw3p3Pj0k0kChpXy5qRY2eqUyQuIp5IY TmycZsRVr+8JwleG7qgPPXxDEncHRyGhlDDNoLh4oJdK4zHm8CbZU6hDtSLv9SjC77Gx d1e+Ps642z7yr/TwF7SYWX8ZDopbq1GKYsafbbVsMBtg45Z+BkjlDsstwhxLugWyIA3h QIZG+1ucPgI/KpU5OF4yqcB7MyfOk4LBeTsT5fLke2RJMDyjSCDb7aWgAWzTp4Zmc/Ta T0yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u1BxK7lQ9engNEKcMZlaGSCrOyuJ60v/1lMB8qEqy60=; b=nSqsWRcBNAIVFSWM7FA/wqO4zRmucnNgys0IPOBudBn2LyaFXNvmcWd0MYZ45K+N+9 5+6/WWp1W2G/PanuOs0T5KlW6YR14LCftgNFLe0h0bfhUqFXG78U0DKZ8qXGJMcUoqsG vy9PfN5rXM0/4hF9tzzXrO8F85KdRTQWFCa4A6u2Cv31Tma42XXkppEF7yKxjd2z0Zs9 gaT7NL64C2i3Bfw0MeCvw14GcDfgW5Z1onVI7HmIhLzKPTUgPEiHMT7M4wqjUd+Tn/xn f/ax0vlj9MVlE9o4noSAXwajrbR3xvBh0E5k7/U3x8qdWU7yRXm436B0D3w4ARtgn956 YZEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=c6i2mro1; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be5-20020a1709070a4500b008b7eed5fa1bsi992757ejc.737.2023.03.07.09.01.32; Tue, 07 Mar 2023 09:01:59 -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; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=c6i2mro1; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbjCGQ6x (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjCGQ6E (ORCPT ); Tue, 7 Mar 2023 11:58:04 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A9F93122; Tue, 7 Mar 2023 08:54:26 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 12640C0008; Tue, 7 Mar 2023 16:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u1BxK7lQ9engNEKcMZlaGSCrOyuJ60v/1lMB8qEqy60=; b=c6i2mro1rqAAHI+67wZ1IUXXHxhvHB2uvzuaqeZqBxOurdJPS1Sd7ix9uiyADZ0VzGddGR i9FJfvr4UekAat2PUquaF0AKXkAplOpbF0R+L+22i+1xzgTmOtp9+MVSsGXSf7WmASXyyX oh1TIVd7vAwD8osamNFZZwceHF4mw50DStIrZEHD94daF48bnGvRR4h+dIu84KmlLGDOnz p73YD3P57BAvCSpofJ1WtoxxiAjSh+v31GmSN8SW3Ce1JM9TZOP6mHUQVdTpOOT7urIM6q SKrXe/6b7um8rOBvOLqZzaExX/+jZROqSt6anM7R5h7f5/tVdi6TmuWf6ujbYQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 05/21] of: Move the request module helper logic to module.c Date: Tue, 7 Mar 2023 17:53:43 +0100 Message-Id: <20230307165359.225361-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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?1759729177180265773?= X-GMAIL-MSGID: =?utf-8?q?1759729177180265773?= Depending on device.c for pure OF handling is considered backwards. Let's extract the content of of_device_request_module() to have the real logic under module.c. The next step will be to convert users of of_device_request_module() to use the new helper. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 25 ++----------------------- drivers/of/module.c | 30 ++++++++++++++++++++++++++++++ include/linux/of.h | 6 ++++++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 44f1f2ef12b7..4bbb6e6388a9 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -8,7 +8,6 @@ #include /* for bus_dma_region */ #include #include -#include #include #include #include @@ -249,30 +248,10 @@ EXPORT_SYMBOL(of_device_get_match_data); int of_device_request_module(struct device *dev) { - char *str; - ssize_t size; - int ret; - - if (!dev || !dev->of_node) + if (!dev) return -ENODEV; - size = of_modalias(dev->of_node, NULL, 0); - if (size < 0) - return size; - - /* Reserve an additional byte for the trailing '\0' */ - size++; - - str = kmalloc(size, GFP_KERNEL); - if (!str) - return -ENOMEM; - - of_modalias(dev->of_node, str, size); - str[size - 1] = '\0'; - ret = request_module(str); - kfree(str); - - return ret; + return of_request_module(dev->of_node); } EXPORT_SYMBOL_GPL(of_device_request_module); diff --git a/drivers/of/module.c b/drivers/of/module.c index 9c6a53f32c0f..0cb3bb83b700 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -4,6 +4,7 @@ */ #include +#include #include ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) @@ -41,3 +42,32 @@ ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) return tsize; } + +int of_request_module(struct device_node *np) +{ + char *str; + ssize_t size; + int ret; + + if (!np) + return -ENODEV; + + size = of_modalias(np, NULL, 0); + if (size < 0) + return size; + + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str = kmalloc(size, GFP_KERNEL); + if (!str) + return -ENOMEM; + + of_modalias(np, str, size); + str[size - 1] = '\0'; + ret = request_module(str); + kfree(str); + + return ret; +} +EXPORT_SYMBOL_GPL(of_request_module); diff --git a/include/linux/of.h b/include/linux/of.h index 1372f8647272..692581486403 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -375,6 +375,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, /* module functions */ extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len); +extern int of_request_module(struct device_node *np); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -738,6 +739,11 @@ static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len return -ENODEV; } +static inline int of_request_module(struct device_node *np) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name,