Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20030C678D5 for ; Wed, 8 Mar 2023 15:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbjCHPci (ORCPT ); Wed, 8 Mar 2023 10:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbjCHPcW (ORCPT ); Wed, 8 Mar 2023 10:32:22 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2243D6E90; Wed, 8 Mar 2023 07:32:14 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0F9CEFF811; Wed, 8 Mar 2023 15:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289533; 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=qSIaLowzQOIsdvJKYrUeSvZLlLef3hpg/zogwF151qc=; b=jjiE7Y9mibAmaq9V923vzVBEc+jLOeK2Tq4IM56MhMTpU+O1HQbiNMAqIwySROQPValvvm +6yf07XU5n9z/JcLm2qUGbIMV+qtC7Y9xI29SCaZdK9s7Tt9eqY3c/qgSFIr39FAMtIkwT ldRUp786l0VI0Hj77w7eDGCCeq7NJJW9ZiGg0tzATXv8lBftQldzULD92fMF/4vzp7BbrC Jr2jSkabfdYmujBQSwn5ISurJfBb6Rx/+vN88OOCMDw5c/99NWkRxJ7sn8OMeZlps1NixO DytCnuTMVk6Z+DO676KxbrLZnqg2B6XTaUUcDDzmCvvJonveOC7e15vKfPrAVg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Rob Herring Subject: [PATCH v3 05/20] of: Move the request module helper logic to module.c Date: Wed, 8 Mar 2023 16:31:45 +0100 Message-Id: <20230308153200.682248-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 7183cfd754db..874a2e1f6308 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 4c59752bc8d6..0e8aa974f0f2 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -4,6 +4,7 @@ */ #include +#include #include #include @@ -42,3 +43,32 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) return tsize; } + +int of_request_module(const 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 be26c7e8ef9e..9b7a99499ef3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -387,6 +387,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, /* module functions */ extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); +extern int of_request_module(const struct device_node *np); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -751,6 +752,11 @@ static inline ssize_t of_modalias(const struct device_node *np, char *str, return -ENODEV; } +static inline int of_request_module(const 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, -- 2.34.1