of: Move the request module helper logic to module.c

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 <miquel.raynal@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-11-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Miquel Raynal 2023-04-04 18:21:18 +01:00 committed by Greg Kroah-Hartman
parent bd7a7ed774
commit e6506f06d5
3 changed files with 38 additions and 23 deletions

View File

@ -8,7 +8,6 @@
#include <linux/dma-direct.h> /* for bus_dma_region */ #include <linux/dma-direct.h> /* for bus_dma_region */
#include <linux/dma-map-ops.h> #include <linux/dma-map-ops.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
@ -249,30 +248,10 @@ EXPORT_SYMBOL(of_device_get_match_data);
int of_device_request_module(struct device *dev) int of_device_request_module(struct device *dev)
{ {
char *str; if (!dev)
ssize_t size;
int ret;
if (!dev || !dev->of_node)
return -ENODEV; return -ENODEV;
size = of_modalias(dev->of_node, NULL, 0); return of_request_module(dev->of_node);
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;
} }
EXPORT_SYMBOL_GPL(of_device_request_module); EXPORT_SYMBOL_GPL(of_device_request_module);

View File

@ -4,6 +4,7 @@
*/ */
#include <linux/of.h> #include <linux/of.h>
#include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
@ -42,3 +43,32 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
return tsize; 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);

View File

@ -387,6 +387,7 @@ extern int of_count_phandle_with_args(const struct device_node *np,
/* module functions */ /* module functions */
extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); 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 */ /* phandle iterator functions */
extern int of_phandle_iterator_init(struct of_phandle_iterator *it, 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; 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, static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
const struct device_node *np, const struct device_node *np,
const char *list_name, const char *list_name,