Skip to contentSkip to conversation

power: supply: olpc_battery: remove unnecessary CONFIG_PM_SLEEP

PATCH In review Coiby Xu 2 participants 6 messages Oct 29, 2020

Subsystems (2)
lore
Share & tools
lore

Coiby Xu

author
#0 lore raw

PATCH 1/1 power: supply: olpc_battery: remove unnecessary CONFIG_PM_SLEEP

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

---
 arch/x86/platform/olpc/olpc-xo15-sci.c | 2 --
 1 file changed, 2 deletions(-)
arch/x86/platform/olpc/olpc-xo15-sci.c +0 -2
index 85f4638764d6..716eefd735a4 100644
@@ -192,7 +192,6 @@ static int xo15_sci_remove(struct acpi_device *device)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int xo15_sci_resume(struct device *dev)
 {
 	/* Enable all EC events */
@@ -204,7 +203,6 @@ static int xo15_sci_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(xo15_sci_pm, NULL, xo15_sci_resume);
 
Signature · 1 line
2.28.0
#1 lore raw

Hi,

Quoted 1 line · Coiby Xu

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

No it does not, when CONFIG_PM_SLEEP is not set then the SET_SYSTEM_SLEEP_PM_OPS macro which SIMPLE_DEV_PM_OPS uses is a no-op, so nothing will reference xo15_sci_resume leading to a compiler warning when CONFIG_PM_SLEEP is not set.

You could drop the ifdef and add __maybe_unused to the definition of xo15_sci_resume, but that feels like needless churn, best to just keep this as is IMHO.

Also s/CONFIG_PM_CONFIG/CONFIG_PM_SLEEP/ in the commit message.

Regards,

Hans

Quoted 27 lines
---
 arch/x86/platform/olpc/olpc-xo15-sci.c | 2 --
 1 file changed, 2 deletions(-)
arch/x86/platform/olpc/olpc-xo15-sci.c +0 -2
index 85f4638764d6..716eefd735a4 100644
@@ -192,7 +192,6 @@ static int xo15_sci_remove(struct acpi_device *device)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int xo15_sci_resume(struct device *dev)
 {
 	/* Enable all EC events */
@@ -204,7 +203,6 @@ static int xo15_sci_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(xo15_sci_pm, NULL, xo15_sci_resume);
 
author
#2 lore raw

Hi Hans,

Thank you for reviewing this patch!

Quoted 5 lines · Hans de Goede

Hi,

Quoted 1 line · Coiby Xu

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

Quoted 9 lines

No it does not, when CONFIG_PM_SLEEP is not set then the SET_SYSTEM_SLEEP_PM_OPS macro which SIMPLE_DEV_PM_OPS uses is a no-op, so nothing will reference xo15_sci_resume leading to a compiler warning when CONFIG_PM_SLEEP is not set.

You could drop the ifdef and add __maybe_unused to the definition of xo15_sci_resume, but that feels like needless churn, best to just keep this as is IMHO.

Actually, this is a tree-wide change by some semi-automation scripts. Thank you for pointing out the issue to prevent me from releasing another ~150 emails to flood other mailing lists.

Currently there are 929 drivers has device PM callbacks,

$ grep -rI "\.pm = &" --include=*.c  ./|wc -l
929

I put all files having device PM callbacks into four categories based on weather a file has CONFIG_PM_SLEEP or PM macro like SET_SYSTEM_SLEEP_PM_OPS, here are the statistics,
1. have both CONFIG_PM_SLEEP and PM_OPS macro: 213
2. have CONFIG_PM_SLEEP but no PM_OPS macro: 19
3. have PM macro but not CONFIG_PM_SLEEP: 347
4. no PM macro or CONFIG_PM_SLEEP: 302

Some drivers which have PM macro but not CONFIG_PM_SLEEP like sound/x86/intel_hdmi_audio.c indeed use __maybe_unused to eliminate the compiling warning. In 2011, there's a patch proposing to remove ONFIG_PM altogether but an objection was turning CONFIG_PM on would increase the kernel size [1]. So __maybe_unused also have this issue. (I made a mistake when I thought PM macros like SIMPLE_DEV_PM_OPS didn't have this issue). What do you think? Btw, It's easy for me to add CONFIG_PM_SLEEP for those drivers have PM macro but not CONFIG_PM_SLEEP since I have already written the necessary automation scripts.

[1] https://lists.linux-foundation.org/pipermail/linux-pm/2011-February/030215.html

Quoted 2 lines

Also s/CONFIG_PM_CONFIG/CONFIG_PM_SLEEP/ in the commit message.

Thank you for pointing out the typo. I've written some scripts to automate the whole process from changing code to submitting patches. Somehow there is still this issue.

Quoted 25 lines

Regards,

Hans

Quoted 20 lines
---
 arch/x86/platform/olpc/olpc-xo15-sci.c | 2 --
 1 file changed, 2 deletions(-)
arch/x86/platform/olpc/olpc-xo15-sci.c +0 -1
index 85f4638764d6..716eefd735a4 100644
@@ -192,7 +192,6 @@ static int xo15_sci_remove(struct acpi_device *device)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int xo15_sci_resume(struct device *dev)
 {
 	/* Enable all EC events */
@@ -204,7 +203,6 @@ static int xo15_sci_resume(struct device *dev)
 
Quoted 8 lines

arch/x86/platform/olpc/olpc-xo15-sci.c static int xo15_sci_resume(struct device *dev) · line 208

Quoted 7 lines
arch/x86/platform/olpc/olpc-xo15-sci.c +0 -1
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(xo15_sci_pm, NULL, xo15_sci_resume);
 

--
Best regards,
Coiby

#3 lore raw

Hi,

Quoted 37 lines · Coiby Xu

Hi Hans,

Thank you for reviewing this patch!

Quoted 5 lines · Hans de Goede

Hi,

Quoted 1 line · Coiby Xu

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

Quoted 9 lines

No it does not, when CONFIG_PM_SLEEP is not set then the SET_SYSTEM_SLEEP_PM_OPS macro which SIMPLE_DEV_PM_OPS uses is a no-op, so nothing will reference xo15_sci_resume leading to a compiler warning when CONFIG_PM_SLEEP is not set.

You could drop the ifdef and add __maybe_unused to the definition of xo15_sci_resume, but that feels like needless churn, best to just keep this as is IMHO.

Actually, this is a tree-wide change by some semi-automation scripts. Thank you for pointing out the issue to prevent me from releasing another ~150 emails to flood other mailing lists.

Currently there are 929 drivers has device PM callbacks,

$ grep -rI "\.pm = &" --include=*.c  ./|wc -l
929

I put all files having device PM callbacks into four categories based on weather a file has CONFIG_PM_SLEEP or PM macro like SET_SYSTEM_SLEEP_PM_OPS, here are the statistics,
  1. have both CONFIG_PM_SLEEP and PM_OPS macro: 213
  2. have CONFIG_PM_SLEEP but no PM_OPS macro: 19
  3. have PM macro but not CONFIG_PM_SLEEP: 347
  4. no PM macro or CONFIG_PM_SLEEP: 302

Quoted 5 lines

Some drivers which have PM macro but not CONFIG_PM_SLEEP like sound/x86/intel_hdmi_audio.c indeed use __maybe_unused to eliminate the compiling warning. In 2011, there's a patch proposing to remove ONFIG_PM altogether but an objection was turning CONFIG_PM on would increase the kernel size [1]. So __maybe_unused also have this issue.

I would expect the compiler to remove the unused function, it knows it is unused, that is why __maybe_unused is necessary to suppress the warning and compilers are pretty smart and agressive wrt remove unnecessary code these days.

Regards,

Hans

Quoted 31 lines
Quoted 26 lines
Quoted 25 lines

---
 arch/x86/platform/olpc/olpc-xo15-sci.c | 2 --

 1 file changed, 2 deletions(-)
arch/x86/platform/olpc/olpc-xo15-sci.c +0 -2
index 85f4638764d6..716eefd735a4 100644
@@ -192,7 +192,6 @@ static int xo15_sci_remove(struct acpi_device *device)
      return 0;
  }
 
-#ifdef CONFIG_PM_SLEEP
  static int xo15_sci_resume(struct device *dev)
  {
      /* Enable all EC events */
@@ -204,7 +203,6 @@ static int xo15_sci_resume(struct device *dev)
 
      return 0;
  }
-#endif
 
  static SIMPLE_DEV_PM_OPS(xo15_sci_pm, NULL, xo15_sci_resume);
 
Signature · 2 lines
Best regards,
Coiby
author
#4 lore raw
Quoted 46 lines · Hans de Goede

Hi,

Quoted 37 lines · Coiby Xu

Hi Hans,

Thank you for reviewing this patch!

Quoted 5 lines · Hans de Goede

Hi,

Quoted 1 line · Coiby Xu

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

Quoted 9 lines

No it does not, when CONFIG_PM_SLEEP is not set then the SET_SYSTEM_SLEEP_PM_OPS macro which SIMPLE_DEV_PM_OPS uses is a no-op, so nothing will reference xo15_sci_resume leading to a compiler warning when CONFIG_PM_SLEEP is not set.

You could drop the ifdef and add __maybe_unused to the definition of xo15_sci_resume, but that feels like needless churn, best to just keep this as is IMHO.

Actually, this is a tree-wide change by some semi-automation scripts. Thank you for pointing out the issue to prevent me from releasing another ~150 emails to flood other mailing lists.

Currently there are 929 drivers has device PM callbacks,

$ grep -rI "\.pm = &" --include=*.c  ./|wc -l
929

I put all files having device PM callbacks into four categories based on weather a file has CONFIG_PM_SLEEP or PM macro like SET_SYSTEM_SLEEP_PM_OPS, here are the statistics,
  1. have both CONFIG_PM_SLEEP and PM_OPS macro: 213
  2. have CONFIG_PM_SLEEP but no PM_OPS macro: 19
  3. have PM macro but not CONFIG_PM_SLEEP: 347
  4. no PM macro or CONFIG_PM_SLEEP: 302

Quoted 5 lines

Some drivers which have PM macro but not CONFIG_PM_SLEEP like sound/x86/intel_hdmi_audio.c indeed use __maybe_unused to eliminate the compiling warning. In 2011, there's a patch proposing to remove ONFIG_PM altogether but an objection was turning CONFIG_PM on would increase the kernel size [1]. So __maybe_unused also have this issue.

Quoted 5 lines

I would expect the compiler to remove the unused function, it knows it is unused, that is why __maybe_unused is necessary to suppress the warning and compilers are pretty smart and agressive wrt remove unnecessary code these days.

Then __maybe_unused is a good solution and there's also convincing reason to prefer __maybe_unused over CONFIG_PM_SLEEP according to Arnd Bergmann [2],

Quoted 22 lines
Quoted 4 lines

By and large, drivers handle this by using a CONFIG_PM_SLEEP ifdef.

Unless you can make an extremely convincing argument why not to do so here, I'd like you to handle it that way instead.

[adding linux-pm to Cc]

The main reason is that everyone gets the #ifdef wrong, I run into half a dozen new build regressions with linux-next every week on average, the typical problems being:

- testing CONFIG_PM_SLEEP instead of CONFIG_PM, leading to an unused function warning
- testing CONFIG_PM instead of CONFIG_PM_SLEEP, leading to a build failure
- calling a function outside of the #ifdef only from inside an otherwise correct #ifdef, again leading to an unused function warning
- causing a warning inside of the #ifdef but only testing if that is disabled, leading to a problem if the macro is set (this is rare these days for CONFIG_PM as that is normally enabled)

Quoted 6 lines

Using __maybe_unused avoids all of the above.

Regards,

Hans

[2] https://lore.kernel.org/patchwork/comment/919944/

--
Best regards,
Coiby

#5 lore raw

Hi,

Quoted 47 lines · Coiby Xu
Quoted 46 lines · Hans de Goede

Hi,

Quoted 42 lines · Coiby Xu

Hi Hans,

Thank you for reviewing this patch!

Quoted 5 lines · Hans de Goede

Hi,

Quoted 1 line · Coiby Xu

SIMPLE_DEV_PM_OPS has already took good care of CONFIG_PM_CONFIG.

Quoted 9 lines

No it does not, when CONFIG_PM_SLEEP is not set then the SET_SYSTEM_SLEEP_PM_OPS macro which SIMPLE_DEV_PM_OPS uses is a no-op, so nothing will reference xo15_sci_resume leading to a compiler warning when CONFIG_PM_SLEEP is not set.

You could drop the ifdef and add __maybe_unused to the definition of xo15_sci_resume, but that feels like needless churn, best to just keep this as is IMHO.

Actually, this is a tree-wide change by some semi-automation scripts. Thank you for pointing out the issue to prevent me from releasing another ~150 emails to flood other mailing lists.

Currently there are 929 drivers has device PM callbacks,

$ grep -rI "\.pm = &" --include=*.c  ./|wc -l
929

I put all files having device PM callbacks into four categories based on weather a file has CONFIG_PM_SLEEP or PM macro like SET_SYSTEM_SLEEP_PM_OPS, here are the statistics,
  1. have both CONFIG_PM_SLEEP and PM_OPS macro: 213   2. have CONFIG_PM_SLEEP but no PM_OPS macro: 19   3. have PM macro but not CONFIG_PM_SLEEP: 347   4. no PM macro or CONFIG_PM_SLEEP: 302

Some drivers which have PM macro but not CONFIG_PM_SLEEP like sound/x86/intel_hdmi_audio.c indeed use __maybe_unused to eliminate the compiling warning. In 2011, there's a patch proposing to remove ONFIG_PM altogether but an objection was turning CONFIG_PM on would increase the kernel size [1]. So __maybe_unused also have this issue.

Quoted 8 lines
Quoted 5 lines

I would expect the compiler to remove the unused function, it knows it is unused, that is why __maybe_unused is necessary to suppress the warning and compilers are pretty smart and agressive wrt remove unnecessary code these days.

Then __maybe_unused is a good solution and there's also convincing reason to prefer __maybe_unused over CONFIG_PM_SLEEP according to Arnd Bergmann [2],

Ok, I would be happy to merge a patch for this which drops the #ifdef-s and adds a __maybe_unused.

Regards,

Hans