[PATCH v1 1/2] i2c: acpi: Return -ENOENT when no resources found in i2c_acpi_client_count()

Andy Shevchenko posted 2 patches 6 days, 14 hours ago
[PATCH v1 1/2] i2c: acpi: Return -ENOENT when no resources found in i2c_acpi_client_count()
Posted by Andy Shevchenko 6 days, 14 hours ago
Some users want to return an error to the upper layers when
i2c_acpi_client_count() returns 0. Follow the common pattern
in such cases, i.e. return -ENOENT instead of 0.

While at it, fix the kernel-doc warning about missing return value
description.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-acpi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index ed90858a27b7..a7d36f8d7f2f 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -84,8 +84,11 @@ static int i2c_acpi_resource_count(struct acpi_resource *ares, void *data)
  * i2c_acpi_client_count - Count the number of I2cSerialBus resources
  * @adev:	ACPI device
  *
- * Returns the number of I2cSerialBus resources in the ACPI-device's
+ * Return:
+ * The number of I2cSerialBus resources in the ACPI-device's
  * resource-list; or a negative error code.
+ *
+ * Specifically returns -ENOENT when no resources found.
  */
 int i2c_acpi_client_count(struct acpi_device *adev)
 {
@@ -97,7 +100,7 @@ int i2c_acpi_client_count(struct acpi_device *adev)
 		return ret;
 
 	acpi_dev_free_resource_list(&r);
-	return count;
+	return count ?: -ENOENT;
 }
 EXPORT_SYMBOL_GPL(i2c_acpi_client_count);
 
-- 
2.50.1
Re: [PATCH v1 1/2] i2c: acpi: Return -ENOENT when no resources found in i2c_acpi_client_count()
Posted by Mika Westerberg 6 days, 14 hours ago
On Tue, Nov 25, 2025 at 10:40:11AM +0100, Andy Shevchenko wrote:
> Some users want to return an error to the upper layers when
> i2c_acpi_client_count() returns 0. Follow the common pattern
> in such cases, i.e. return -ENOENT instead of 0.

Well what does 0 mean then?

To me it's logical that i2c_acpi_client_count() as it returns count,
returns 0 if the count is 0. Let's not make it any more complex than that.
;-)

> While at it, fix the kernel-doc warning about missing return value
> description.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/i2c/i2c-core-acpi.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index ed90858a27b7..a7d36f8d7f2f 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -84,8 +84,11 @@ static int i2c_acpi_resource_count(struct acpi_resource *ares, void *data)
>   * i2c_acpi_client_count - Count the number of I2cSerialBus resources
>   * @adev:	ACPI device
>   *
> - * Returns the number of I2cSerialBus resources in the ACPI-device's
> + * Return:
> + * The number of I2cSerialBus resources in the ACPI-device's
>   * resource-list; or a negative error code.
> + *
> + * Specifically returns -ENOENT when no resources found.
>   */
>  int i2c_acpi_client_count(struct acpi_device *adev)
>  {
> @@ -97,7 +100,7 @@ int i2c_acpi_client_count(struct acpi_device *adev)
>  		return ret;
>  
>  	acpi_dev_free_resource_list(&r);
> -	return count;
> +	return count ?: -ENOENT;
>  }
>  EXPORT_SYMBOL_GPL(i2c_acpi_client_count);
>  
> -- 
> 2.50.1
Re: [PATCH v1 1/2] i2c: acpi: Return -ENOENT when no resources found in i2c_acpi_client_count()
Posted by Andy Shevchenko 6 days, 13 hours ago
On Tue, Nov 25, 2025 at 10:50:46AM +0100, Mika Westerberg wrote:
> On Tue, Nov 25, 2025 at 10:40:11AM +0100, Andy Shevchenko wrote:
> > Some users want to return an error to the upper layers when
> > i2c_acpi_client_count() returns 0. Follow the common pattern
> > in such cases, i.e. return -ENOENT instead of 0.
> 
> Well what does 0 mean then?

There is no 0.

> To me it's logical that i2c_acpi_client_count() as it returns count,
> returns 0 if the count is 0. Let's not make it any more complex than that.
> ;-)

The same approach used elsewhere, e.g., gpiod_count(),
   of_reset_control_get_count() / reset_control_get_count().
And other count methods used for IRQ resource, for example.
However PCI MSI/MSI-X counters never return 0.

-- 
With Best Regards,
Andy Shevchenko