input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS()
PATCH 1/1 input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS()
Convert deprecated SIMPLE_DEV_PM_OPS
to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr().
This lets us drop the __maybe_unused annotations from the resume and suspend callbacks. Also reduces kernel size when CONFIG_PM or CONFIG_PM_SLEEP is disabled.
--- drivers/input/touchscreen/ad7879-i2c.c | 2 +- drivers/input/touchscreen/ad7879-spi.c | 2 +- drivers/input/touchscreen/ad7879.c | 8 ++++---- drivers/input/touchscreen/cyttsp5.c | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-)
drivers/input/touchscreen/ad7879-i2c.c +1 -1
@@ -60,7 +60,7 @@ static struct i2c_driver ad7879_i2c_driver = { .driver = { .name = "ad7879", .dev_groups = ad7879_groups, - .pm = &ad7879_pm_ops, + .pm = pm_sleep_ptr(&ad7879_pm_ops), .of_match_table = of_match_ptr(ad7879_i2c_dt_ids), }, .probe = ad7879_i2c_probe,
drivers/input/touchscreen/ad7879-spi.c +1 -1
@@ -58,7 +58,7 @@ static struct spi_driver ad7879_spi_driver = { .driver = { .name = "ad7879", .dev_groups = ad7879_groups, - .pm = &ad7879_pm_ops, + .pm = pm_sleep_ptr(&ad7879_pm_ops), .of_match_table = of_match_ptr(ad7879_spi_dt_ids), }, .probe = ad7879_spi_probe,
drivers/input/touchscreen/ad7879.c +4 -4
@@ -301,7 +301,7 @@ static void ad7879_close(struct input_dev *input)__ad7879_disable (ts); } -static int __maybe_unused ad7879_suspend (struct device *dev) +static int ad7879_suspend (struct device *dev) {struct ad7879 *ts =dev_get_drvdata (dev);
@@ -315,7 +315,7 @@ static int __maybe_unused ad7879_suspend(struct device *dev)return 0 ; } -static int __maybe_unused ad7879_resume (struct device *dev) +static int ad7879_resume (struct device *dev) {struct ad7879 *ts =dev_get_drvdata (dev);
@@ -329,8 +329,8 @@ static int __maybe_unused ad7879_resume(struct device *dev)return 0 ; } -SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); -EXPORT_SYMBOL (ad7879_pm_ops); +DEFINE_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); +EXPORT_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume);static void ad7879_toggle (struct ad7879 *ts,bool disable) {
drivers/input/touchscreen/cyttsp5.c +4 -4
@@ -942,7 +942,7 @@ static const struct i2c_device_id cyttsp5_i2c_id[] = { };MODULE_DEVICE_TABLE (i2c, cyttsp5_i2c_id); -static int __maybe_unused cyttsp5_suspend (struct device *dev) +static int cyttsp5_suspend (struct device *dev) {struct cyttsp5 *ts =dev_get_drvdata (dev);
@@ -952,7 +952,7 @@ static int __maybe_unused cyttsp5_suspend(struct device *dev)return 0 ; } -static int __maybe_unused cyttsp5_resume (struct device *dev) +static int cyttsp5_resume (struct device *dev) {struct cyttsp5 *ts =dev_get_drvdata (dev);
@@ -962,13 +962,13 @@ static int __maybe_unused cyttsp5_resume(struct device *dev)return 0 ; } -static SIMPLE_DEV_PM_OPS(cyttsp5_pm, cyttsp5_suspend, cyttsp5_resume); +static DEFINE_SIMPLE_DEV_PM_OPS(cyttsp5_pm, cyttsp5_suspend, cyttsp5_resume);static struct i2c_driver cyttsp5_i2c_driver = { .driver = { .name =CYTTSP5_NAME , .of_match_table = cyttsp5_of_match, - .pm = &cyttsp5_pm, + .pm =pm_sleep_ptr (&cyttsp5_pm), }, .probe = cyttsp5_i2c_probe, .id_table = cyttsp5_i2c_id,
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The patch introduces a strict C compiler redefinition error for `ad7879_pm_ops` when…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces a strict C compiler redefinition error for ad7879_pm_ops when CONFIG_PM_SLEEP is enabled. --
--- Patch [1]: [PATCH] input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS() --- commit 44d9a5ca9f2aa03594a9658d8105747b57b227ba
Author: Triet Hoang <[email protected]>
input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS()
This commit updates several touchscreen drivers to use the newer DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr() macros instead of the deprecated SIMPLE_DEV_PM_OPS. This allows the removal of __maybe_unused annotations on suspend and resume callbacks.
Quoted 4 lines
drivers/input/touchscreen/ad7879.c +0
-0
[ ... ]
drivers/input/touchscreen/ad7879.c static int __maybe_unused ad7879_resume(struct device *dev) · line 333
Quoted 8 lines
drivers/input/touchscreen/ad7879.c +2
-2@@ -329,8 +329,8 @@ static int __maybe_unused ad7879_resume(struct device *dev)return 0 ; } -SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); -EXPORT_SYMBOL (ad7879_pm_ops); +DEFINE_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); +EXPORT_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume);
[Severity: Low]
Does this cause a compilation error when CONFIG_PM_SLEEP is enabled?
Both DEFINE_SIMPLE_DEV_PM_OPS and EXPORT_SIMPLE_DEV_PM_OPS expand to a complete initialization of the ad7879_pm_ops struct. Using both sequentially redefines the same global variable, which will result in a build failure.
Should this just be EXPORT_SIMPLE_DEV_PM_OPS by itself?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/1 input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS()
Convert deprecated SIMPLE_DEV_PM_OPS
to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr().
This lets us drop the __maybe_unused annotations from the resume and suspend callbacks. Also reduces kernel size when CONFIG_PM or CONFIG_PM_SLEEP is disabled.
---
Changes in v2:
- Remove DEFINE_SIMPLE_DEV_PM_OPS, use only EXPORT_SIMPLE_DEV_PM_OPS for ad7879_pm_ops
--- drivers/input/touchscreen/ad7879-i2c.c | 2 +- drivers/input/touchscreen/ad7879-spi.c | 2 +- drivers/input/touchscreen/ad7879.c | 7 +++---- drivers/input/touchscreen/cyttsp5.c | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-)
drivers/input/touchscreen/ad7879-i2c.c +1 -1
@@ -60,7 +60,7 @@ static struct i2c_driver ad7879_i2c_driver = { .driver = { .name = "ad7879", .dev_groups = ad7879_groups, - .pm = &ad7879_pm_ops, + .pm = pm_sleep_ptr(&ad7879_pm_ops), .of_match_table = of_match_ptr(ad7879_i2c_dt_ids), }, .probe = ad7879_i2c_probe,
drivers/input/touchscreen/ad7879-spi.c +1 -1
@@ -58,7 +58,7 @@ static struct spi_driver ad7879_spi_driver = { .driver = { .name = "ad7879", .dev_groups = ad7879_groups, - .pm = &ad7879_pm_ops, + .pm = pm_sleep_ptr(&ad7879_pm_ops), .of_match_table = of_match_ptr(ad7879_spi_dt_ids), }, .probe = ad7879_spi_probe,
drivers/input/touchscreen/ad7879.c +3 -4
@@ -301,7 +301,7 @@ static void ad7879_close(struct input_dev *input)__ad7879_disable (ts); } -static int __maybe_unused ad7879_suspend (struct device *dev) +static int ad7879_suspend (struct device *dev) {struct ad7879 *ts =dev_get_drvdata (dev);
@@ -315,7 +315,7 @@ static int __maybe_unused ad7879_suspend(struct device *dev)return 0 ; } -static int __maybe_unused ad7879_resume (struct device *dev) +static int ad7879_resume (struct device *dev) {struct ad7879 *ts =dev_get_drvdata (dev);
@@ -329,8 +329,7 @@ static int __maybe_unused ad7879_resume(struct device *dev)return 0 ; } -SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); -EXPORT_SYMBOL (ad7879_pm_ops); +EXPORT_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume);static void ad7879_toggle (struct ad7879 *ts,bool disable) {
drivers/input/touchscreen/cyttsp5.c +4 -4
@@ -942,7 +942,7 @@ static const struct i2c_device_id cyttsp5_i2c_id[] = { };MODULE_DEVICE_TABLE (i2c, cyttsp5_i2c_id); -static int __maybe_unused cyttsp5_suspend (struct device *dev) +static int cyttsp5_suspend (struct device *dev) {struct cyttsp5 *ts =dev_get_drvdata (dev);
@@ -952,7 +952,7 @@ static int __maybe_unused cyttsp5_suspend(struct device *dev)return 0 ; } -static int __maybe_unused cyttsp5_resume (struct device *dev) +static int cyttsp5_resume (struct device *dev) {struct cyttsp5 *ts =dev_get_drvdata (dev);
@@ -962,13 +962,13 @@ static int __maybe_unused cyttsp5_resume(struct device *dev)return 0 ; } -static SIMPLE_DEV_PM_OPS(cyttsp5_pm, cyttsp5_suspend, cyttsp5_resume); +static DEFINE_SIMPLE_DEV_PM_OPS(cyttsp5_pm, cyttsp5_suspend, cyttsp5_resume);static struct i2c_driver cyttsp5_i2c_driver = { .driver = { .name =CYTTSP5_NAME , .of_match_table = cyttsp5_of_match, - .pm = &cyttsp5_pm, + .pm =pm_sleep_ptr (&cyttsp5_pm), }, .probe = cyttsp5_i2c_probe, .id_table = cyttsp5_i2c_id,
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The logic in ad7879_toggle() is completely inverted, causing the sysfs disable attribute to malfunction and desynchronize the hardware state from software tracking. --
--- Patch [1]: [PATCH v2] input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS() --- commit b2cacedba4aaf53cb97b0b4bbb302d78a3a37daf
Author: Triet Hoang <[email protected]>
input: touchscreen: Convert to DEFINE_SIMPLE_DEV_PM_OPS()
This commit converts the deprecated SIMPLE_DEV_PM_OPS to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr() across several touchscreen drivers. This allows dropping the __maybe_unused annotations and reduces kernel size when PM features are disabled.
Quoted 4 lines
drivers/input/touchscreen/ad7879.c +0
-0
[ ... ]
drivers/input/touchscreen/ad7879.c static int __maybe_unused ad7879_resume(struct device *dev) · line 335
Quoted 10 lines
drivers/input/touchscreen/ad7879.c +1
-2@@ -329,8 +329,7 @@ static int __maybe_unused ad7879_resume(struct device *dev)return 0 ; } -SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume); -EXPORT_SYMBOL (ad7879_pm_ops); +EXPORT_SIMPLE_DEV_PM_OPS (ad7879_pm_ops, ad7879_suspend, ad7879_resume);static void ad7879_toggle (struct ad7879 *ts,bool disable) {
[Severity: High]
This is a pre-existing issue, but the logic in this function appears to be completely inverted.
Looking at the full ad7879_toggle() function indrivers/input/touchscreen/ad7879.c:
static void ad7879_toggle(struct ad7879 *ts, bool disable)
{
guard(mutex)(&ts->input->mutex);
if (!ts->suspended && input_device_enabled(ts->input)) {
if (disable) {
if (ts->disabled)
__ad7879_enable(ts);
} else {
if (!ts->disabled)
__ad7879_disable(ts);
}
}
ts->disabled = disable;
}If a user writes 1 to the disable sysfs attribute (disable == true), and the device is already marked disabled (ts->disabled == true), won't this logic actually enable the hardware by calling __ad7879_enable(ts)?
Conversely, if the user writes 0 to enable the device (disable == false) while the device is currently enabled (ts->disabled == false), won't this unexpectedly disable the hardware?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1