linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR
@ 2020-04-20 22:04 Hans de Goede
  2020-04-20 22:33 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2020-04-20 22:04 UTC (permalink / raw)
  To: Darren Hart, Andy Shevchenko
  Cc: Hans de Goede, platform-driver-x86, linux-kernel

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).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/surface3_power.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/surface3_power.c b/drivers/platform/x86/surface3_power.c
index 946ac2dc08ae..32e6e86e27dd 100644
--- a/drivers/platform/x86/surface3_power.c
+++ b/drivers/platform/x86/surface3_power.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR
  2020-04-20 22:04 [PATCH] platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR Hans de Goede
@ 2020-04-20 22:33 ` Andy Shevchenko
  2020-04-21  7:40   ` Hans de Goede
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2020-04-20 22:33 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Darren Hart, Andy Shevchenko, Platform Driver, Linux Kernel Mailing List

On Tue, Apr 21, 2020 at 1:04 AM Hans de Goede <hdegoede@redhat.com> wrote:
>
> 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).
>

Thanks, I guess it repeats [1].

[1]: http://git.infradead.org/linux-platform-drivers-x86.git/commitdiff/4dbccb873f2b35ad1b26419ff88c80509e2d4cbb

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/surface3_power.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/surface3_power.c b/drivers/platform/x86/surface3_power.c
> index 946ac2dc08ae..32e6e86e27dd 100644
> --- a/drivers/platform/x86/surface3_power.c
> +++ b/drivers/platform/x86/surface3_power.c
> @@ -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
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR
  2020-04-20 22:33 ` Andy Shevchenko
@ 2020-04-21  7:40   ` Hans de Goede
  0 siblings, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2020-04-21  7:40 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Darren Hart, Andy Shevchenko, Platform Driver, Linux Kernel Mailing List

Hi,

On 4/21/20 12:33 AM, Andy Shevchenko wrote:
> On Tue, Apr 21, 2020 at 1:04 AM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> 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).
>>
> 
> Thanks, I guess it repeats [1].
> 
> [1]: http://git.infradead.org/linux-platform-drivers-x86.git/commitdiff/4dbccb873f2b35ad1b26419ff88c80509e2d4cbb

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



> 
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/platform/x86/surface3_power.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/platform/x86/surface3_power.c b/drivers/platform/x86/surface3_power.c
>> index 946ac2dc08ae..32e6e86e27dd 100644
>> --- a/drivers/platform/x86/surface3_power.c
>> +++ b/drivers/platform/x86/surface3_power.c
>> @@ -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
>>
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-21  7:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 22:04 [PATCH] platform/x86: surface3_power: i2c_acpi_new_device() returns a PTR_ERR Hans de Goede
2020-04-20 22:33 ` Andy Shevchenko
2020-04-21  7:40   ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).