platform/mellanox: mlxreg-lc: fix error code in mlxreg_lc_create_static_devices()
PATCH 1/1 platform/mellanox: mlxreg-lc: fix error code in mlxreg_lc_create_static_devices()
This code should be using PTR_ERR() instead of IS_ERR(). And because it's using the wrong "dev->client" pointer, the IS_ERR() check will be false, meaning the function returns success.
--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/mellanox/mlxreg-lc.c +3 -2
@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ for (i =0 ; i < size; i++, dev++) {
@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo->addr); dev->adapter =NULL ; + ret =PTR_ERR (dev->client); goto fail_create_static_devices; } }
@@ -435,7 +436,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpli2c_unregister_device (dev->client); dev->client =NULL ; } -return IS_ERR (dev->client); +return ret; } static void
Signature · 1 line
2.20.1
Quoted 13 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, November 10, 2021 9:44 AM
To: Hans de Goede <[email protected]>; Vadim Pasternak <[email protected]>
Cc: Mark Gross <[email protected]>; Michael Shych <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH] platform/mellanox: mlxreg-lc: fix error code inmlxreg_lc_create_static_devices()
Quoted 7 lines
This code should be using
PTR_ERR()instead ofIS_ERR(). And because it's using the wrong "dev->client" pointer, theIS_ERR()check will be false, meaning the function returns success.Fixes 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support forNvidia line card devices")
Signed-off-by Dan Carpenter <[email protected]>
Quoted 41 lines
--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-lc.c +1
-1@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ drivers/platform/mellanox/mlxreg-lc.c +1
-0for (i =0 ; i < size; i++, dev++) {@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo- >addr); dev->adapter =NULL ; + ret =PTR_ERR (dev->client); goto fail_create_static_devices;drivers/platform/mellanox/mlxreg-lc.c +1
-1} }@@ -435,7 +436,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpli2c_unregister_device (dev->client); dev->client =NULL ; } -return IS_ERR (dev->client); +return ret; }static void
--
2.20.1
Quoted 24 lines · Dan Carpenter
This code should be using
PTR_ERR()instead ofIS_ERR(). And because it's using the wrong "dev->client" pointer, theIS_ERR()check will be false, meaning the function returns success.Fixes 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-lc.c +1
-1@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ for (i =0 ; i < size; i++, dev++) {
drivers/platform/mellanox/mlxreg-lc.c mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl · line 426
Quoted 4 lines
drivers/platform/mellanox/mlxreg-lc.c +1
-0@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo->addr); dev->adapter =NULL ; + ret =PTR_ERR (dev->client);
ret is only set on this error path.
can we get to the return without setting ret?
--mark
Quoted 15 lines
drivers/platform/mellanox/mlxreg-lc.c +1
-1goto fail_create_static_devices; } }@@ -435,7 +436,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpli2c_unregister_device (dev->client); dev->client =NULL ; } -return IS_ERR (dev->client); +return ret; } static voidSignature · 1 line
2.20.1
Quoted 27 lines · Mark Gross
Quoted 26 lines · Dan Carpenter
This code should be using
PTR_ERR()instead ofIS_ERR(). And because it's using the wrong "dev->client" pointer, theIS_ERR()check will be false, meaning the function returns success.Fixes 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-lc.c +1
-1@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ for (i =0 ; i < size; i++, dev++) {@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo->addr);
Quoted 5 lines
drivers/platform/mellanox/mlxreg-lc.c mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl · line 426
Quoted 2 lines
drivers/platform/mellanox/mlxreg-lc.c +1
-0dev->adapter =NULL ; + ret =PTR_ERR (dev->client);ret is only set on this error path.
can we get to the return without setting ret?
No.
:P
There two ways to read that question is if the patch introduces an uninitialized variable bug and I would be super embarrassed if I did something like that with all the QC scripts that I have to prevent it. The other way to read that question is if it's possible to not introduce the "ret" variable but instead figure it out at the end. But the error code needs to be preserved at this point because we change change the "dev" pointer and set "dev->adapter" to NULL.
regards,
dan carpenter
Quoted 38 lines · Dan Carpenter
Quoted 27 lines · Mark Gross
Quoted 26 lines · Dan Carpenter
This code should be using
PTR_ERR()instead ofIS_ERR(). And because it's using the wrong "dev->client" pointer, theIS_ERR()check will be false, meaning the function returns success.Fixes 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-lc.c +1
-1@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ for (i =0 ; i < size; i++, dev++) {@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo->addr);Quoted 5 lines
drivers/platform/mellanox/mlxreg-lc.c mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl · line 426
Quoted 2 lines
drivers/platform/mellanox/mlxreg-lc.c +1
-0dev->adapter =NULL ; + ret =PTR_ERR (dev->client);ret is only set on this error path.
can we get to the return without setting ret?No.
:P
Quoted 7 lines
There two ways to read that question is if the patch introduces an uninitialized variable bug and I would be super embarrassed if I did something like that with all the QC scripts that I have to prevent it. The other way to read that question is if it's possible to not introduce the "ret" variable but instead figure it out at the end. But the error code needs to be preserved at this point because we change change the "dev" pointer and set "
dev->adapter" to NULL.
^^^^^^^^^^^^
I meant "dev->client" not "dev->adapter".
regards,
dan carpenter
Hi,
Quoted 6 lines · Dan Carpenter
This code should be using
PTR_ERR()instead ofIS_ERR(). And because it's using the wrong "dev->client" pointer, theIS_ERR()check will be false, meaning the function returns success.Fixes 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")Signed-off-by Dan Carpenter <[email protected]>
Thanks, patch looks good to me:
I will add this fix to my tree once 5.16-rc1 is out and I will include this fix in my first pdx86 fixes pull-req for 5.16.
Regards,
Hans
Quoted 35 lines
--- drivers/platform/mellanox/mlxreg-lc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/mellanox/mlxreg-lc.c +3
-2@@ -413,7 +413,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl int size) {struct mlxreg_hotplug_device *dev = devs; -int i; +int i, ret;/* Create static I2C device feeding by auxiliary or main power. */ for (i =0 ; i < size; i++, dev++) {@@ -423,6 +423,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpl dev->brdinfo->type, dev->nr, dev->brdinfo->addr); dev->adapter =NULL ; + ret =PTR_ERR (dev->client); goto fail_create_static_devices; } }@@ -435,7 +436,7 @@ mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotpli2c_unregister_device (dev->client); dev->client =NULL ; } -return IS_ERR (dev->client); +return ret; } static void