Skip to contentSkip to conversation

pwm: sysfs: Switch to DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr()

PATCH Applied Andy Shevchenko 4 participants 21 messages Aug 26, 2022 – Sep 28, 2022 1 message not in the archive PWM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 pwm: sysfs: Switch to DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr()

Using these newer macros allows the compiler to remove the unused structure and functions when !CONFIG_PM_SLEEP + removes the need to mark pm functions __maybe_unused.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pwm/sysfs.c +4 -4
index 9903c3a7eced..c21b6046067b 100644
@@ -433,7 +433,7 @@ static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm)
 	return ret;
 }
 
-static int __maybe_unused pwm_class_suspend(struct device *parent)
+static int pwm_class_suspend(struct device *parent)
 {
 	struct pwm_chip *chip = dev_get_drvdata(parent);
 	unsigned int i;
@@ -464,20 +464,20 @@ static int __maybe_unused pwm_class_suspend(struct device *parent)
 	return ret;
 }
 
-static int __maybe_unused pwm_class_resume(struct device *parent)
+static int pwm_class_resume(struct device *parent)
 {
 	struct pwm_chip *chip = dev_get_drvdata(parent);
 
 	return pwm_class_resume_npwm(parent, chip->npwm);
 }
 
-static SIMPLE_DEV_PM_OPS(pwm_class_pm_ops, pwm_class_suspend, pwm_class_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(pwm_class_pm_ops, pwm_class_suspend, pwm_class_resume);
 
 static struct class pwm_class = {
 	.name = "pwm",
 	.owner = THIS_MODULE,
 	.dev_groups = pwm_chip_groups,
-	.pm = &pwm_class_pm_ops,
+	.pm = pm_sleep_ptr(&pwm_class_pm_ops),
 };
 
 static int pwmchip_sysfs_match(struct device *parent, const void *data)
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 2/4 pwm: sysfs: Return directly from the for-loop in PM callbacks

There is no need to assign ret to 0 and then break the loop just for returning the error to the caller. Instead, return directly from the for-loop, and 0 otherwise.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pwm/sysfs.c +6 -6
index c21b6046067b..1543fe07765b 100644
@@ -413,7 +413,7 @@ static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm)
 {
 	struct pwm_chip *chip = dev_get_drvdata(parent);
 	unsigned int i;
-	int ret = 0;
+	int ret;
 
 	for (i = 0; i < npwm; i++) {
 		struct pwm_device *pwm = &chip->pwms[i];
@@ -427,17 +427,17 @@ static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm)
 		state.enabled = export->suspend.enabled;
 		ret = pwm_class_apply_state(export, pwm, &state);
 		if (ret < 0)
-			break;
+			return ret;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int pwm_class_suspend(struct device *parent)
 {
 	struct pwm_chip *chip = dev_get_drvdata(parent);
 	unsigned int i;
-	int ret = 0;
+	int ret;
 
 	for (i = 0; i < chip->npwm; i++) {
 		struct pwm_device *pwm = &chip->pwms[i];
@@ -457,11 +457,11 @@ static int pwm_class_suspend(struct device *parent)
 			 * this suspend function.
 			 */
 			pwm_class_resume_npwm(parent, i);
-			break;
+			return ret;
 		}
 	}
 
-	return ret;
+	return 0;
 }
 
 static int pwm_class_resume(struct device *parent)
Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH v2 2/4] pwm: sysfs: Return directly from the for-loop in PM callbacks

Quoted 10 lines · Andy Shevchenko

There is no need to assign ret to 0 and then break the loop just for returning the error to the caller. Instead, return directly from the for-loop, and 0 otherwise.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

I fail to see how this is an improvement. The outcome is exactly the same and this doesn't even make the code shorter. Why bother?

Thierry

#3 lore raw

Re: [PATCH v2 2/4] pwm: sysfs: Return directly from the for-loop in PM callbacks

Quoted 7 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

There is no need to assign ret to 0 and then break the loop just for returning the error to the caller. Instead, return directly from the for-loop, and 0 otherwise.

I fail to see how this is an improvement. The outcome is exactly the same and this doesn't even make the code shorter. Why bother?

The improvement is in maintenance. It's proven that assignments in the definition block might lead to the subtle mistakes when it's not close enough to the actual use. That said, this is an improvement from maintaining and developing perspectives.

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

PATCH v2 3/4 pwm: sysfs: Replace sprintf() with sysfs_emit()

In reply to Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pwm/sysfs.c +6 -6
index 1543fe07765b..767c4b19afb1 100644
@@ -42,7 +42,7 @@ static ssize_t period_show(struct device *child,
 
 	pwm_get_state(pwm, &state);
 
-	return sprintf(buf, "%llu\n", state.period);
+	return sysfs_emit(buf, "%llu\n", state.period);
 }
 
 static ssize_t period_store(struct device *child,
@@ -77,7 +77,7 @@ static ssize_t duty_cycle_show(struct device *child,
 
 	pwm_get_state(pwm, &state);
 
-	return sprintf(buf, "%llu\n", state.duty_cycle);
+	return sysfs_emit(buf, "%llu\n", state.duty_cycle);
 }
 
 static ssize_t duty_cycle_store(struct device *child,
@@ -112,7 +112,7 @@ static ssize_t enable_show(struct device *child,
 
 	pwm_get_state(pwm, &state);
 
-	return sprintf(buf, "%d\n", state.enabled);
+	return sysfs_emit(buf, "%d\n", state.enabled);
 }
 
 static ssize_t enable_store(struct device *child,
@@ -171,7 +171,7 @@ static ssize_t polarity_show(struct device *child,
 		break;
 	}
 
-	return sprintf(buf, "%s\n", polarity);
+	return sysfs_emit(buf, "%s\n", polarity);
 }
 
 static ssize_t polarity_store(struct device *child,
@@ -212,7 +212,7 @@ static ssize_t capture_show(struct device *child,
 	if (ret)
 		return ret;
 
-	return sprintf(buf, "%u %u\n", result.period, result.duty_cycle);
+	return sysfs_emit(buf, "%u %u\n", result.period, result.duty_cycle);
 }
 
 static DEVICE_ATTR_RW(period);
@@ -361,7 +361,7 @@ static ssize_t npwm_show(struct device *parent, struct device_attribute *attr,
 {
 	const struct pwm_chip *chip = dev_get_drvdata(parent);
 
-	return sprintf(buf, "%u\n", chip->npwm);
+	return sysfs_emit(buf, "%u\n", chip->npwm);
 }
 static DEVICE_ATTR_RO(npwm);
 
Signature · 1 line
2.35.1
#5 lore raw

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

Quoted 10 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

Thierry

#6 lore raw

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

Quoted 9 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

This is a recommended way to use sysfs_emit() mentioned in Documentation. Care to fix documentation?

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

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

Quoted 7 lines
Quoted 4 lines

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

This is a recommended way to use sysfs_emit() mentioned in Documentation. Care to fix documentation?

For your convenience, Documentation/filesystems/sysfs.rst says:

- show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

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

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

Quoted 7 lines
Quoted 2 lines

This is a recommended way to use sysfs_emit() mentioned in Documentation. Care to fix documentation?

For your convenience, Documentation/filesystems/sysfs.rst says:

- show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

Took some digging to find enough information to convince me. Again, the commit message says that sysfs_emit() is safer, but that's a bad reason in this case because these cases are fine. The sprintf() calls that this replaces aren't unbound and we're not appending to an existing seq_buf, so nothing to worry on that front.

I think the better argument for broadly applying this is to specifically distinguish the sysfs sprintf() calls from others so that they can be auditioned better and perhaps help with the documentation[0].

Do you mind if I apply this with a reworded documentation?

Thierry

[0]: https://lore.kernel.org/all/[email protected]/

#9 lore raw

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

Quoted 27 lines · Thierry Reding
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

Quoted 7 lines
Quoted 2 lines

This is a recommended way to use sysfs_emit() mentioned in Documentation. Care to fix documentation?

For your convenience, Documentation/filesystems/sysfs.rst says:

- show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

Took some digging to find enough information to convince me. Again, the commit message says that sysfs_emit() is safer, but that's a bad reason in this case because these cases are fine. The sprintf() calls that this replaces aren't unbound and we're not appending to an existing seq_buf, so nothing to worry on that front.

Quoted 5 lines

I think the better argument for broadly applying this is to specifically distinguish the sysfs sprintf() calls from others so that they can be auditioned better and perhaps help with the documentation[0].

Do you mind if I apply this with a reworded documentation?

I meant "commit message", not documentation.

Thierry

#10 lore raw

Re: [PATCH v2 3/4] pwm: sysfs: Replace sprintf() with sysfs_emit()

In reply to Thierry Reding
Quoted 27 lines · Thierry Reding
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such a sprintf() call straightforwardly with the new helper.

How exactly is sysfs_emit() safer here? In all of these cases, the values that sprintf() writes are the only values that are written into the buffer and we know that none of them exceed PAGE_SIZE. So the additional checks that sysfs_emit() performs are useless.

Quoted 7 lines
Quoted 2 lines

This is a recommended way to use sysfs_emit() mentioned in Documentation. Care to fix documentation?

For your convenience, Documentation/filesystems/sysfs.rst says:

- show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

Took some digging to find enough information to convince me. Again, the commit message says that sysfs_emit() is safer, but that's a bad reason in this case because these cases are fine. The sprintf() calls that this replaces aren't unbound and we're not appending to an existing seq_buf, so nothing to worry on that front.

Quoted 5 lines

I think the better argument for broadly applying this is to specifically distinguish the sysfs sprintf() calls from others so that they can be auditioned better and perhaps help with the documentation[0].

Do you mind if I apply this with a reworded documentation?

I do not mind, go ahead with it.
Thank you!

Quoted 3 lines

Thierry

[0]: https://lore.kernel.org/all/[email protected]/

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

PATCH v2 4/4 pwm: sysfs: Utilize an array for polarity strings

In reply to Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

---
v2: added pwm_ prefix to the variable (Uwe), adjusted intendation (Uwe)

 drivers/pwm/sysfs.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/pwm/sysfs.c +12 -20
index 767c4b19afb1..502167e44a3d 100644
@@ -151,27 +151,23 @@ static ssize_t enable_store(struct device *child,
 	return ret ? : size;
 }
 
+static const char * const pwm_polarity_strings[] = {
+	[PWM_POLARITY_NORMAL] = "normal",
+	[PWM_POLARITY_INVERSED] = "inversed",
+};
+
 static ssize_t polarity_show(struct device *child,
 			     struct device_attribute *attr,
 			     char *buf)
 {
 	const struct pwm_device *pwm = child_to_pwm_device(child);
-	const char *polarity = "unknown";
 	struct pwm_state state;
 
 	pwm_get_state(pwm, &state);
+	if (state.polarity < 0 || state.polarity >= ARRAY_SIZE(pwm_polarity_strings))
+		return sysfs_emit(buf, "unknown\n");
 
-	switch (state.polarity) {
-	case PWM_POLARITY_NORMAL:
-		polarity = "normal";
-		break;
-
-	case PWM_POLARITY_INVERSED:
-		polarity = "inversed";
-		break;
-	}
-
-	return sysfs_emit(buf, "%s\n", polarity);
+	return sysfs_emit(buf, "%s\n", pwm_polarity_strings[state.polarity]);
 }
 
 static ssize_t polarity_store(struct device *child,
@@ -180,20 +176,16 @@ static ssize_t polarity_store(struct device *child,
 {
 	struct pwm_export *export = child_to_pwm_export(child);
 	struct pwm_device *pwm = export->pwm;
-	enum pwm_polarity polarity;
 	struct pwm_state state;
 	int ret;
 
-	if (sysfs_streq(buf, "normal"))
-		polarity = PWM_POLARITY_NORMAL;
-	else if (sysfs_streq(buf, "inversed"))
-		polarity = PWM_POLARITY_INVERSED;
-	else
-		return -EINVAL;
+	ret = sysfs_match_string(pwm_polarity_strings, buf);
+	if (ret < 0)
+		return ret;
 
 	mutex_lock(&export->lock);
 	pwm_get_state(pwm, &state);
-	state.polarity = polarity;
+	state.polarity = ret;
 	ret = pwm_apply_state(pwm, &state);
 	mutex_unlock(&export->lock);
 
Signature · 1 line
2.35.1
#12 lore raw

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

Quoted 71 lines

---
v2: added pwm_ prefix to the variable (Uwe), adjusted intendation (Uwe)

 drivers/pwm/sysfs.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/pwm/sysfs.c +12 -20
index 767c4b19afb1..502167e44a3d 100644
@@ -151,27 +151,23 @@ static ssize_t enable_store(struct device *child,
 	return ret ? : size;
 }
 
+static const char * const pwm_polarity_strings[] = {
+	[PWM_POLARITY_NORMAL] = "normal",
+	[PWM_POLARITY_INVERSED] = "inversed",
+};
+
 static ssize_t polarity_show(struct device *child,
 			     struct device_attribute *attr,
 			     char *buf)
 {
 	const struct pwm_device *pwm = child_to_pwm_device(child);
-	const char *polarity = "unknown";
 	struct pwm_state state;
 
 	pwm_get_state(pwm, &state);
+	if (state.polarity < 0 || state.polarity >= ARRAY_SIZE(pwm_polarity_strings))
+		return sysfs_emit(buf, "unknown\n");
 
-	switch (state.polarity) {
-	case PWM_POLARITY_NORMAL:
-		polarity = "normal";
-		break;
-
-	case PWM_POLARITY_INVERSED:
-		polarity = "inversed";
-		break;
-	}
-
-	return sysfs_emit(buf, "%s\n", polarity);
+	return sysfs_emit(buf, "%s\n", pwm_polarity_strings[state.polarity]);
 }
 
 static ssize_t polarity_store(struct device *child,
@@ -180,20 +176,16 @@ static ssize_t polarity_store(struct device *child,
 {
 	struct pwm_export *export = child_to_pwm_export(child);
 	struct pwm_device *pwm = export->pwm;
-	enum pwm_polarity polarity;
 	struct pwm_state state;
 	int ret;
 
-	if (sysfs_streq(buf, "normal"))
-		polarity = PWM_POLARITY_NORMAL;
-	else if (sysfs_streq(buf, "inversed"))
-		polarity = PWM_POLARITY_INVERSED;
-	else
-		return -EINVAL;
+	ret = sysfs_match_string(pwm_polarity_strings, buf);
+	if (ret < 0)
+		return ret;
 
 	mutex_lock(&export->lock);
 	pwm_get_state(pwm, &state);
-	state.polarity = polarity;
+	state.polarity = ret;
 	ret = pwm_apply_state(pwm, &state);
 	mutex_unlock(&export->lock);
 

A message that is not in the archive (sent off-list or not yet received): CAHp75VfY5RgAju5ASvAp565oF6VmYYiuowNsPTGSm=+1iFJ98A@mail.gmail.com

#14 lore raw

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Joe Perches
Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

First of all, please remove unnecessary context when replying.

I am _very_ aware of context.
I specifically left the code in.

Quoted 7 lines
Quoted 4 lines

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

So, what do you suggest here and in many other similar places (yes, ABI implied) in the kernel?

Leaving the code alone.

#15 lore raw

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

Quoted 16 lines · Joe Perches
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Joe Perches
Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

First of all, please remove unnecessary context when replying.

I am _very_ aware of context.
I specifically left the code in.

Quoted 5 lines
Quoted 4 lines

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

Quoted 4 lines
Quoted 2 lines

So, what do you suggest here and in many other similar places (yes, ABI implied) in the kernel?

Leaving the code alone.

It's good that PWM maintainers look at this differently.

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

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Joe Perches
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Joe Perches
Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

First of all, please remove unnecessary context when replying.

I am _very_ aware of context.
I specifically left the code in.

Quoted 5 lines
Quoted 4 lines

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

So, what do you suggest here and in many other similar places (yes, ABI implied) in the kernel?

Leaving the code alone.

It's good that PWM maintainers look at this differently.

The enum is not userspace so it's not ABI.

The PWM maintainers are free to do what they want but I prefer obviousness over compactness.

#17 lore raw

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

Quoted 21 lines · Joe Perches
Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Joe Perches
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Joe Perches
Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

First of all, please remove unnecessary context when replying.

I am _very_ aware of context.
I specifically left the code in.

Quoted 7 lines
Quoted 4 lines

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

So, what do you suggest here and in many other similar places (yes, ABI implied) in the kernel?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Leaving the code alone.

It's good that PWM maintainers look at this differently.

The enum is not userspace so it's not ABI.

The PWM maintainers are free to do what they want but I prefer obviousness over compactness.

Why do you not start "fixing" other similar places in the kernel?

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

Re: [PATCH v2 4/4] pwm: sysfs: Utilize an array for polarity strings

In reply to Joe Perches
Quoted 21 lines · Joe Perches
Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Joe Perches
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Joe Perches
Quoted 2 lines · Andy Shevchenko

Code is smaller and looks nicer if we combine polarity strings into an array.

First of all, please remove unnecessary context when replying.

I am _very_ aware of context.
I specifically left the code in.

Quoted 7 lines
Quoted 4 lines

It's less robust though as PWM_POLARITY_NORMAL and _INVERSED are now required to be 0 and 1. As the only 2 values in an enum they are, but that's not really guaranteed unless you read the enum definition.

So, what do you suggest here and in many other similar places (yes, ABI implied) in the kernel?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Leaving the code alone.

It's good that PWM maintainers look at this differently.

The enum is not userspace so it's not ABI.

The PWM maintainers are free to do what they want but I prefer obviousness over compactness.

I do agree with Joe, I don't see any benefit in this.

Thierry

#19 lore raw
In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

Using these newer macros allows the compiler to remove the unused structure and functions when !CONFIG_PM_SLEEP + removes the need to mark pm functions __maybe_unused.

Anything I should have done for this to be applied?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

Using these newer macros allows the compiler to remove the unused structure and functions when !CONFIG_PM_SLEEP + removes the need to mark pm functions __maybe_unused.

---
v2: added tag (Uwe)

 drivers/pwm/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks.

Thierry

#21 lore raw
Quoted 6 lines · Thierry Reding
Quoted 3 lines · Andy Shevchenko

Using these newer macros allows the compiler to remove the unused structure and functions when !CONFIG_PM_SLEEP + removes the need to mark pm functions __maybe_unused.

Applied, thanks.

Thanks and thank you for the review. It would be nice if you can check PWM LPSS series [1] as well and another PWM related patch [2] I sent.

[1]: https://lore.kernel.org/linux-pwm/[email protected]/
[2]: https://lore.kernel.org/linux-pwm/[email protected]/

Signature · 2 lines
With Best Regards,
Andy Shevchenko