From 553bd29700145e1849698985e9800f14e967da49 Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Tue, 7 Feb 2023 12:05:29 +0100 Subject: of: device: Ignore modalias of reused nodes If of_node is reused, do not use that node's modalias. This will hide the name of the actual device. This is rather prominent in USB glue drivers creating a platform device for the host controller. Signed-off-by: Alexander Stein Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20230207110531.1060252-2-alexander.stein@ew.tq-group.com Signed-off-by: Greg Kroah-Hartman --- drivers/of/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/device.c b/drivers/of/device.c index c674a13c3055..3caaaf107076 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -256,7 +256,7 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len ssize_t csize; ssize_t tsize; - if ((!dev) || (!dev->of_node)) + if ((!dev) || (!dev->of_node) || dev->of_node_reused) return -ENODEV; /* Name & Type */ @@ -376,7 +376,7 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) { int sl; - if ((!dev) || (!dev->of_node)) + if ((!dev) || (!dev->of_node) || dev->of_node_reused) return -ENODEV; /* Devicetree modalias is tricky, we add it in 2 steps */ -- cgit v1.2.3-58-ga151 From 2295bed9bebe8d1eef276194fed5b5fbe89c5363 Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Tue, 7 Feb 2023 12:05:30 +0100 Subject: of: device: Do not ignore error code in of_device_uevent_modalias of_device_get_modalias might return an error code, propagate that one. Otherwise the negative, signed integer is propagated to unsigned integer for the comparison resulting in a huge 'sl' size. Signed-off-by: Alexander Stein Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20230207110531.1060252-3-alexander.stein@ew.tq-group.com Signed-off-by: Greg Kroah-Hartman --- drivers/of/device.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/device.c b/drivers/of/device.c index 3caaaf107076..8271793ef379 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -385,6 +385,8 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], sizeof(env->buf) - env->buflen); + if (sl < 0) + return sl; if (sl >= (sizeof(env->buf) - env->buflen)) return -ENOMEM; env->buflen += sl; -- cgit v1.2.3-58-ga151