ida_simple_get on failure can return an error. The patch ensures that
the dev_set_name is set on non failure cases.
Signed-off-by: Aditya Pakki <[email protected]>
---
drivers/thunderbolt/xdomain.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index e27dd8beb94b..b1768f595259 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -772,7 +772,9 @@ static void enumerate_services(struct tb_xdomain *xd)
svc->dev.bus = &tb_bus_type;
svc->dev.type = &tb_service_type;
svc->dev.parent = &xd->dev;
- dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
+ if (svc->id >= 0)
+ dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev),
+ svc->id);
if (device_register(&svc->dev)) {
put_device(&svc->dev);
--
2.17.1
On Tue, Mar 19, 2019 at 12:22:59PM -0500, Aditya Pakki wrote:
> ida_simple_get on failure can return an error. The patch ensures that
> the dev_set_name is set on non failure cases.
>
> Signed-off-by: Aditya Pakki <[email protected]>
> ---
> drivers/thunderbolt/xdomain.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
> index e27dd8beb94b..b1768f595259 100644
> --- a/drivers/thunderbolt/xdomain.c
> +++ b/drivers/thunderbolt/xdomain.c
> @@ -772,7 +772,9 @@ static void enumerate_services(struct tb_xdomain *xd)
> svc->dev.bus = &tb_bus_type;
> svc->dev.type = &tb_service_type;
> svc->dev.parent = &xd->dev;
> - dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
> + if (svc->id >= 0)
> + dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev),
> + svc->id);
I think the correct way to handle this case is to cleanup svc right
after the allocation fails and then break out without enumerating more
services.
On 3/19/2019 10:52 PM, Aditya Pakki wrote:
> ida_simple_get on failure can return an error. The patch ensures that
> the dev_set_name is set on non failure cases.
>
> Signed-off-by: Aditya Pakki <[email protected]>
> ---
We should add check against `ida_simple_get` instead of svc->id >= 0 and
clean upĀ svc.
Also, It seems clean up is missing when device_register fails and it is
leaking svc.
Cheers,
Mukesh
> drivers/thunderbolt/xdomain.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
> index e27dd8beb94b..b1768f595259 100644
> --- a/drivers/thunderbolt/xdomain.c
> +++ b/drivers/thunderbolt/xdomain.c
> @@ -772,7 +772,9 @@ static void enumerate_services(struct tb_xdomain *xd)
> svc->dev.bus = &tb_bus_type;
> svc->dev.type = &tb_service_type;
> svc->dev.parent = &xd->dev;
> - dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
> + if (svc->id >= 0)
> + dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev),
> + svc->id);
>
> if (device_register(&svc->dev)) {
> put_device(&svc->dev);