Skip to contentSkip to conversation

platform/x86: int3472: A few cleanups

PATCH Superseded Andy Shevchenko 4 participants 15 messages Aug 21, 2024 – Aug 22, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover platform/x86: int3472: A few cleanups

A few cleanups to the driver. It includes an amendment to dev_err_probe() to ignore 0 error code. The patches 1 and 2 are dependent, while patches 2 and 3 may be applied in any order.

Assumed to go via PDx86 tree if no objections to the code.

Andy Shevchenko (4):
driver core: Ignore 0 in dev_err_probe() platform/x86: int3472: Simplify dev_err_probe() usage platform/x86: int3472: Use GPIO_LOOKUP() macro platform/x86: int3472: Use str_high_low()

 drivers/base/core.c                           |  4 ++++
 drivers/platform/x86/intel/int3472/discrete.c | 14 ++++----------
 2 files changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/4 driver core: Ignore 0 in dev_err_probe()

In the similar way, ignore 0 error code (AKA "success") in dev_err_probe(). This helps to simplify a code such as

  if (ret < 0)
    return dev_err_probe(int3472->dev, ret, err_msg);

return ret;

to

  return dev_err_probe(int3472->dev, ret, err_msg);
---
 drivers/base/core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/base/core.c +4 -0
index 6d3897492285..144cb8c201fb 100644
@@ -5046,6 +5046,10 @@ int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
 		 */
 		break;
 
+	case 0:
+		/* Success, no need to issue an error message */
+		break;
+
 	default:
 		dev_err(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
 		break;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH v1 1/4] driver core: Ignore 0 in dev_err_probe()

Quoted 23 lines · Andy Shevchenko

In the similar way, ignore 0 error code (AKA "success") in dev_err_probe(). This helps to simplify a code such as

  if (ret < 0)
    return dev_err_probe(int3472->dev, ret, err_msg);

return ret;

to

  return dev_err_probe(int3472->dev, ret, err_msg);
---
 drivers/base/core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/base/core.c +0 -0
index 6d3897492285..144cb8c201fb 100644

drivers/base/core.c int dev_err_probe(const struct device *dev, int err, const char *fmt, ...) · line 5055

Quoted 10 lines
drivers/base/core.c +4 -0
@@ -5046,6 +5046,10 @@ int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
 		 */
 		break;
 
+	case 0:
+		/* Success, no need to issue an error message */
+		break;
+
 	default:
 		dev_err(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
 		break;

This seems generally useful,

A nit, the code sequence that dev_err_probe() is documented to replace is no longer matches with the behavior (the else would need if (err < 0) added).

Signature · 1 line
 i.
#3 lore raw

Re: [PATCH v1 1/4] driver core: Ignore 0 in dev_err_probe()

Quoted 13 lines · Ilpo Järvinen
Quoted 11 lines · Andy Shevchenko

In the similar way, ignore 0 error code (AKA "success") in dev_err_probe(). This helps to simplify a code such as

  if (ret < 0)
    return dev_err_probe(int3472->dev, ret, err_msg);

return ret;

to

  return dev_err_probe(int3472->dev, ret, err_msg);

...

Quoted 3 lines

This seems generally useful,

Thanks!

Quoted 3 lines

A nit, the code sequence that dev_err_probe() is documented to replace is no longer matches with the behavior (the else would need if (err < 0) added).

Okay, let's wait what Greg says about it, if he is okay with the proposal, I'll amend documentation as well in v2.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v1 1/4] driver core: Ignore 0 in dev_err_probe()

Quoted 21 lines · Andy Shevchenko
Quoted 13 lines · Ilpo Järvinen
Quoted 11 lines · Andy Shevchenko

In the similar way, ignore 0 error code (AKA "success") in dev_err_probe(). This helps to simplify a code such as

  if (ret < 0)
    return dev_err_probe(int3472->dev, ret, err_msg);

return ret;

to

  return dev_err_probe(int3472->dev, ret, err_msg);

...

Quoted 3 lines

This seems generally useful,

Quoted 8 lines

Thanks!

Quoted 3 lines

A nit, the code sequence that dev_err_probe() is documented to replace is no longer matches with the behavior (the else would need if (err < 0) added).

Okay, let's wait what Greg says about it, if he is okay with the proposal, I'll amend documentation as well in v2.

I like it, and will be glad to take it if you update the documentation :)

thanks,

greg k-h

#5 lore raw

Re: [PATCH v1 1/4] driver core: Ignore 0 in dev_err_probe()

Quoted 1 line · Greg Kroah-Hartman

On Wed, Aug 21, 2024 at 04:12:22PM +0300, Andy Shevchenko wrote:

...

Quoted 1 line

I like it, and will be glad to take it if you update the documentation :)

Consider it done.

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

PATCH 2/4 platform/x86: int3472: Simplify dev_err_probe() usage

In reply to Andy Shevchenko

Since dev_err_probe() ignores success, i.e. 0. we may call it unconditionally.

---
 drivers/platform/x86/intel/int3472/discrete.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +1 -4
index 07b302e09340..cd0743300d7f 100644
@@ -289,10 +289,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 	int3472->ngpios++;
 	ACPI_FREE(obj);
 
-	if (ret < 0)
-		return dev_err_probe(int3472->dev, ret, err_msg);
-
-	return ret;
+	return dev_err_probe(int3472->dev, ret, err_msg);
 }
 
 static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#7 lore raw

Re: [PATCH v1 2/4] platform/x86: int3472: Simplify dev_err_probe() usage

Le 21/08/2024 à 14:20, Andy Shevchenko a écrit :

Quoted 1 line

Since dev_err_probe() ignores success,

Hi,

Does it really?
It does not seem to be the case (at least on linux-next). Or I miss something obvious?

CJ

Quoted 24 lines

i.e. 0. we may call
it unconditionally.

---
  drivers/platform/x86/intel/int3472/discrete.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +1 -4
index 07b302e09340..cd0743300d7f 100644
@@ -289,10 +289,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
  	int3472->ngpios++;
  	ACPI_FREE(obj);
 
-	if (ret < 0)
-		return dev_err_probe(int3472->dev, ret, err_msg);
-
-	return ret;
+	return dev_err_probe(int3472->dev, ret, err_msg);
  }
 
  static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
maintainer
#8 lore raw

Re: [PATCH v1 2/4] platform/x86: int3472: Simplify dev_err_probe() usage

Quoted 8 lines · Christophe JAILLET

Le 21/08/2024 à 14:20, Andy Shevchenko a écrit :

Quoted 1 line

Since dev_err_probe() ignores success,

Hi,

Does it really?
It does not seem to be the case (at least on linux-next). Or I miss something obvious?

Yes, you're missing the first patch of the series. :-)

Signature · 1 line
 i.
Quoted 27 lines
Quoted 25 lines

i.e. 0. we may call
it unconditionally.

---
  drivers/platform/x86/intel/int3472/discrete.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +1 -3
index 07b302e09340..cd0743300d7f 100644
@@ -289,10 +289,7 @@ static int skl_int3472_handle_gpio_resources(struct
 acpi_resource *ares,
  	int3472->ngpios++;
  	ACPI_FREE(obj);
  -	if (ret < 0)
-		return dev_err_probe(int3472->dev, ret, err_msg);
-
-	return ret;
+	return dev_err_probe(int3472->dev, ret, err_msg);
  }
    static int skl_int3472_parse_crs(struct int3472_discrete_device

*int3472)

#9 lore raw

Re: [PATCH v1 2/4] platform/x86: int3472: Simplify dev_err_probe() usage

Le 21/08/2024 à 14:39, Ilpo Järvinen a écrit :

Quoted 5 lines · Christophe JAILLET
Quoted 4 lines

Le 21/08/2024 à 14:20, Andy Shevchenko a écrit :

Quoted 1 line

Since dev_err_probe() ignores success,

Quoted 8 lines
Quoted 5 lines

Hi,

Does it really?
It does not seem to be the case (at least on linux-next). Or I miss something obvious?

Yes, you're missing the first patch of the series. :-)

Lol.

Sorry for the noise. (* blushing *)

CJ

maintainer Reviewed-by on v1 2/4
#10 lore raw

Re: [PATCH v1 2/4] platform/x86: int3472: Simplify dev_err_probe() usage

In reply to Andy Shevchenko
Quoted 15 lines · Andy Shevchenko

Since dev_err_probe() ignores success, i.e. 0. we may call it unconditionally.

---
 drivers/platform/x86/intel/int3472/discrete.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +0 -0
index 07b302e09340..cd0743300d7f 100644
@@ -289,10 +289,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 	int3472->ngpios++;

drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 295

Quoted 10 lines
drivers/platform/x86/intel/int3472/discrete.c +1 -4
 	ACPI_FREE(obj);
 
-	if (ret < 0)
-		return dev_err_probe(int3472->dev, ret, err_msg);
-
-	return ret;
+	return dev_err_probe(int3472->dev, ret, err_msg);
 }
 
 static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
Signature · 1 line
 i.
#11 lore raw

PATCH 3/4 platform/x86: int3472: Use GPIO_LOOKUP() macro

In reply to Andy Shevchenko

Use GPIO_LOOKUP() macro which provides a compound literal and can be used with dynamic data.

---
 drivers/platform/x86/intel/int3472/discrete.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +1 -5
index cd0743300d7f..96a9673a0165 100644
@@ -69,11 +69,7 @@ static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry,
 	if (!adev)
 		return -ENODEV;
 
-	table_entry->key = acpi_dev_name(adev);
-	table_entry->chip_hwnum = agpio->pin_table[0];
-	table_entry->con_id = func;
-	table_entry->idx = 0;
-	table_entry->flags = polarity;
+	*table_entry = GPIO_LOOKUP(acpi_dev_name(adev), agpio->pin_table[0], func, polarity);
 
 	return 0;
 }
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Reviewed-by on v1 3/4
#12 lore raw

Re: [PATCH v1 3/4] platform/x86: int3472: Use GPIO_LOOKUP() macro

Quoted 16 lines · Andy Shevchenko

Use GPIO_LOOKUP() macro which provides a compound literal and can be used with dynamic data.

---
 drivers/platform/x86/intel/int3472/discrete.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +0 -0
index cd0743300d7f..96a9673a0165 100644
@@ -69,11 +69,7 @@ static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry,
 	if (!adev)
 		return -ENODEV;

drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry, · line 75

Quoted 10 lines
drivers/platform/x86/intel/int3472/discrete.c +1 -5
 
-	table_entry->key = acpi_dev_name(adev);
-	table_entry->chip_hwnum = agpio->pin_table[0];
-	table_entry->con_id = func;
-	table_entry->idx = 0;
-	table_entry->flags = polarity;
+	*table_entry = GPIO_LOOKUP(acpi_dev_name(adev), agpio->pin_table[0], func, polarity);
 
 	return 0;
 }
Signature · 1 line
 i.
#13 lore raw

PATCH 4/4 platform/x86: int3472: Use str_high_low()

In reply to Andy Shevchenko

Use str_high_low() rather than open coding.

---
 drivers/platform/x86/intel/int3472/discrete.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/int3472/discrete.c +2 -1
index 96a9673a0165..b5f6f71bb1dd 100644
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/overflow.h>
 #include <linux/platform_device.h>
+#include <linux/string_choices.h>
 #include <linux/uuid.h>
 
 #include "common.h"
@@ -230,7 +231,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 
 	dev_dbg(int3472->dev, "%s %s pin %d active-%s\n", func,
 		agpio->resource_source.string_ptr, agpio->pin_table[0],
-		(polarity == GPIO_ACTIVE_HIGH) ? "high" : "low");
+		str_high_low(polarity == GPIO_ACTIVE_HIGH));
 
 	switch (type) {
 	case INT3472_GPIO_TYPE_RESET:
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Reviewed-by on v1 4/4
#14 lore raw

Re: [PATCH v1 4/4] platform/x86: int3472: Use str_high_low()

Quoted 21 lines · Andy Shevchenko

Use str_high_low() rather than open coding.

---
 drivers/platform/x86/intel/int3472/discrete.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/int3472/discrete.c +1 -0
index 96a9673a0165..b5f6f71bb1dd 100644
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/overflow.h>
 #include <linux/platform_device.h>
+#include <linux/string_choices.h>
 #include <linux/uuid.h>
 
 #include "common.h"

drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 237

Quoted 8 lines
drivers/platform/x86/intel/int3472/discrete.c +1 -1
@@ -230,7 +231,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 
 	dev_dbg(int3472->dev, "%s %s pin %d active-%s\n", func,
 		agpio->resource_source.string_ptr, agpio->pin_table[0],
-		(polarity == GPIO_ACTIVE_HIGH) ? "high" : "low");
+		str_high_low(polarity == GPIO_ACTIVE_HIGH));
 
 	switch (type) {
 	case INT3472_GPIO_TYPE_RESET:
Signature · 1 line
 i.