platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR
PATCH 1/1 platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR
i2c_acpi_new_device() never returns NULL, it either returns an i2c_client or a PTR_ERR. Adjust the mshw0011_probe() error handling to take this into account.
Note the goto out_err will cause i2c_unregister_device() to get called even though the i2c_acpi_new_device() fails, this is ok as it accepts a NULL pointer argument (and treats it as a no-op).
--- drivers/platform/x86/surface3_power.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/platform/x86/surface3_power.c +4 -2
@@ -522,8 +522,10 @@ static int mshw0011_probe(struct i2c_client *client)strlcpy (board_info.type,"MSHW0011-bat0" ,I2C_NAME_SIZE ); bat0 =i2c_acpi_new_device (dev,1 , &board_info); -if (!bat0) -return -ENOMEM ; +if (IS_ERR (bat0)) { + error =PTR_ERR (bat0); + goto out_err; + } data->bat0 = bat0;i2c_set_clientdata (bat0, data);
Signature · 1 line
2.26.0
Quoted 9 lines · Hans de Goede
i2c_acpi_new_device()never returns NULL, it either returns ani2c_clientor aPTR_ERR. Adjust themshw0011_probe()error handling to take this into account.Note the goto
out_errwill causei2c_unregister_device()to get called even though thei2c_acpi_new_device()fails, this is ok as it accepts a NULL pointer argument (and treats it as a no-op).
Thanks, I guess it repeats [1].
Quoted 25 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/surface3_power.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/platform/x86/surface3_power.c +4
-3@@ -522,8 +522,10 @@ static int mshw0011_probe(struct i2c_client *client)strlcpy (board_info.type,"MSHW0011-bat0" ,I2C_NAME_SIZE ); bat0 =i2c_acpi_new_device (dev,1 , &board_info); -if (!bat0) -return -ENOMEM ; +if (IS_ERR (bat0)) { + error =PTR_ERR (bat0); + goto out_err; + } data->bat0 = bat0;i2c_set_clientdata (bat0, data); --2.26.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Hans de Goede
i2c_acpi_new_device()never returns NULL, it either returns ani2c_clientor aPTR_ERR. Adjust themshw0011_probe()error handling to take this into account.
Quoted 8 lines
Quoted 4 lines
Note the goto
out_errwill causei2c_unregister_device()to get called even though thei2c_acpi_new_device()fails, this is ok as it accepts a NULL pointer argument (and treats it as a no-op).Thanks, I guess it repeats [1].
I guess it does and Dan's solution for the error handling is claner then mine, a direct return indeed is the proper thing to do here.
Regards,
Hans
Quoted 28 lines
Quoted 26 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/surface3_power.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/platform/x86/surface3_power.c +4
-3@@ -522,8 +522,10 @@ static int mshw0011_probe(struct i2c_client *client)strlcpy (board_info.type,"MSHW0011-bat0" ,I2C_NAME_SIZE ); bat0 =i2c_acpi_new_device (dev,1 , &board_info); -if (!bat0) -return -ENOMEM ; +if (IS_ERR (bat0)) { + error =PTR_ERR (bat0); + goto out_err; + } data->bat0 = bat0;i2c_set_clientdata (bat0, data); --2.26.0