From 1aa8df90f4569acd36d2c94a9cfe1eee561575d6 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 22 Sep 2023 10:51:47 -0700 Subject: platform/chrome: wilco_ec: Annotate struct ec_event_queue with __counted_by MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct ec_event_queue. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Benson Leung Cc: Tzung-Bi Shih Cc: Dawei Li Cc: Dmitry Torokhov Cc: Maximilian Luz Cc: "Uwe Kleine-König" Cc: Greg Kroah-Hartman Cc: Jiang Jian Cc: chrome-platform@lists.linux.dev Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Link: https://lore.kernel.org/r/20230922175146.work.219-kees@kernel.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/wilco_ec/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/wilco_ec/event.c b/drivers/platform/chrome/wilco_ec/event.c index a40f60bcefb6..f80a7c83cfba 100644 --- a/drivers/platform/chrome/wilco_ec/event.c +++ b/drivers/platform/chrome/wilco_ec/event.c @@ -95,7 +95,7 @@ struct ec_event_queue { int capacity; int head; int tail; - struct ec_event *entries[]; + struct ec_event *entries[] __counted_by(capacity); }; /* Maximum number of events to store in ec_event_queue */ -- cgit v1.2.3 From f04410e7be65f0d005238f286ee37572874c0d5d Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:14 +0200 Subject: platform/chrome: cros_ec_chardev: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-2-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_chardev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_chardev.c b/drivers/platform/chrome/cros_ec_chardev.c index d6de5a294128..81950bb2c6da 100644 --- a/drivers/platform/chrome/cros_ec_chardev.c +++ b/drivers/platform/chrome/cros_ec_chardev.c @@ -396,13 +396,11 @@ static int cros_ec_chardev_probe(struct platform_device *pdev) return misc_register(&data->misc); } -static int cros_ec_chardev_remove(struct platform_device *pdev) +static void cros_ec_chardev_remove(struct platform_device *pdev) { struct chardev_data *data = dev_get_drvdata(&pdev->dev); misc_deregister(&data->misc); - - return 0; } static struct platform_driver cros_ec_chardev_driver = { @@ -410,7 +408,7 @@ static struct platform_driver cros_ec_chardev_driver = { .name = DRV_NAME, }, .probe = cros_ec_chardev_probe, - .remove = cros_ec_chardev_remove, + .remove_new = cros_ec_chardev_remove, }; module_platform_driver(cros_ec_chardev_driver); -- cgit v1.2.3 From f366fa0064ef3f7dda4ed8d25b41f8c96f5b2d3e Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:15 +0200 Subject: platform/chrome: cros_ec_debugfs: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-3-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_debugfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index c876120e0ebc..091fdc154d79 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -533,14 +533,12 @@ remove_debugfs: return ret; } -static int cros_ec_debugfs_remove(struct platform_device *pd) +static void cros_ec_debugfs_remove(struct platform_device *pd) { struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent); debugfs_remove_recursive(ec->debug_info->dir); cros_ec_cleanup_console_log(ec->debug_info); - - return 0; } static int __maybe_unused cros_ec_debugfs_suspend(struct device *dev) @@ -573,7 +571,7 @@ static struct platform_driver cros_ec_debugfs_driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, .probe = cros_ec_debugfs_probe, - .remove = cros_ec_debugfs_remove, + .remove_new = cros_ec_debugfs_remove, }; module_platform_driver(cros_ec_debugfs_driver); -- cgit v1.2.3 From fa45583c3133ed4c910216cae38c49c65af70c85 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:16 +0200 Subject: platform/chrome: cros_ec_lightbar: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-4-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_lightbar.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c index 376425bbd8ff..6677cc6c4984 100644 --- a/drivers/platform/chrome/cros_ec_lightbar.c +++ b/drivers/platform/chrome/cros_ec_lightbar.c @@ -560,7 +560,7 @@ static int cros_ec_lightbar_probe(struct platform_device *pd) return ret; } -static int cros_ec_lightbar_remove(struct platform_device *pd) +static void cros_ec_lightbar_remove(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); @@ -569,8 +569,6 @@ static int cros_ec_lightbar_remove(struct platform_device *pd) /* Let the EC take over the lightbar again. */ lb_manual_suspend_ctrl(ec_dev, 0); - - return 0; } static int __maybe_unused cros_ec_lightbar_resume(struct device *dev) @@ -603,7 +601,7 @@ static struct platform_driver cros_ec_lightbar_driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, .probe = cros_ec_lightbar_probe, - .remove = cros_ec_lightbar_remove, + .remove_new = cros_ec_lightbar_remove, }; module_platform_driver(cros_ec_lightbar_driver); -- cgit v1.2.3 From e02944e85169b0350ea12264e530858250991546 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:17 +0200 Subject: platform/chrome: cros_ec_lpc: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-5-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_lpc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 356572452898..897090f0f26e 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -460,7 +460,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) return 0; } -static int cros_ec_lpc_remove(struct platform_device *pdev) +static void cros_ec_lpc_remove(struct platform_device *pdev) { struct cros_ec_device *ec_dev = platform_get_drvdata(pdev); struct acpi_device *adev; @@ -471,8 +471,6 @@ static int cros_ec_lpc_remove(struct platform_device *pdev) cros_ec_lpc_acpi_notify); cros_ec_unregister(ec_dev); - - return 0; } static const struct acpi_device_id cros_ec_lpc_acpi_device_ids[] = { @@ -580,7 +578,7 @@ static struct platform_driver cros_ec_lpc_driver = { .probe_type = PROBE_FORCE_SYNCHRONOUS, }, .probe = cros_ec_lpc_probe, - .remove = cros_ec_lpc_remove, + .remove_new = cros_ec_lpc_remove, }; static struct platform_device cros_ec_lpc_device = { -- cgit v1.2.3 From 6478e302409a0377cd6382c05b0ece22fc05c308 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:18 +0200 Subject: platform/chrome: cros_ec_sysfs: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-6-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_sysfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c index 09e3bf5e8ec6..93e67ab4af06 100644 --- a/drivers/platform/chrome/cros_ec_sysfs.c +++ b/drivers/platform/chrome/cros_ec_sysfs.c @@ -340,13 +340,11 @@ static int cros_ec_sysfs_probe(struct platform_device *pd) return ret; } -static int cros_ec_sysfs_remove(struct platform_device *pd) +static void cros_ec_sysfs_remove(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group); - - return 0; } static struct platform_driver cros_ec_sysfs_driver = { @@ -354,7 +352,7 @@ static struct platform_driver cros_ec_sysfs_driver = { .name = DRV_NAME, }, .probe = cros_ec_sysfs_probe, - .remove = cros_ec_sysfs_remove, + .remove_new = cros_ec_sysfs_remove, }; module_platform_driver(cros_ec_sysfs_driver); -- cgit v1.2.3 From 58b15196b0ef1be58d331d47d7787c1baca85e80 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:19 +0200 Subject: platform/chrome: cros_ec_vbc: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-7-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_vbc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_vbc.c b/drivers/platform/chrome/cros_ec_vbc.c index c859c862d7ac..2e4af10c7679 100644 --- a/drivers/platform/chrome/cros_ec_vbc.c +++ b/drivers/platform/chrome/cros_ec_vbc.c @@ -121,14 +121,12 @@ static int cros_ec_vbc_probe(struct platform_device *pd) return ret; } -static int cros_ec_vbc_remove(struct platform_device *pd) +static void cros_ec_vbc_remove(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_vbc_attr_group); - - return 0; } static struct platform_driver cros_ec_vbc_driver = { @@ -136,7 +134,7 @@ static struct platform_driver cros_ec_vbc_driver = { .name = DRV_NAME, }, .probe = cros_ec_vbc_probe, - .remove = cros_ec_vbc_remove, + .remove_new = cros_ec_vbc_remove, }; module_platform_driver(cros_ec_vbc_driver); -- cgit v1.2.3 From ea4bad2badb704a64556116e831979a5761da1d8 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:20 +0200 Subject: platform/chrome: cros_typec_switch: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-8-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_typec_switch.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index 0eefdcf14d63..07a19386dc4e 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -297,12 +297,11 @@ static int cros_typec_switch_probe(struct platform_device *pdev) return cros_typec_register_switches(sdata); } -static int cros_typec_switch_remove(struct platform_device *pdev) +static void cros_typec_switch_remove(struct platform_device *pdev) { struct cros_typec_switch_data *sdata = platform_get_drvdata(pdev); cros_typec_unregister_switches(sdata); - return 0; } #ifdef CONFIG_ACPI @@ -319,7 +318,7 @@ static struct platform_driver cros_typec_switch_driver = { .acpi_match_table = ACPI_PTR(cros_typec_switch_acpi_id), }, .probe = cros_typec_switch_probe, - .remove = cros_typec_switch_remove, + .remove_new = cros_typec_switch_remove, }; module_platform_driver(cros_typec_switch_driver); -- cgit v1.2.3 From b6c1fea8355045d13b888743cba5a2cf8627d845 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:21 +0200 Subject: platform/chrome: cros_usbpd_logger: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-9-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_usbpd_logger.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_usbpd_logger.c b/drivers/platform/chrome/cros_usbpd_logger.c index d16931203d82..f618757f8b32 100644 --- a/drivers/platform/chrome/cros_usbpd_logger.c +++ b/drivers/platform/chrome/cros_usbpd_logger.c @@ -219,14 +219,12 @@ static int cros_usbpd_logger_probe(struct platform_device *pd) return 0; } -static int cros_usbpd_logger_remove(struct platform_device *pd) +static void cros_usbpd_logger_remove(struct platform_device *pd) { struct logger_data *logger = platform_get_drvdata(pd); cancel_delayed_work_sync(&logger->log_work); destroy_workqueue(logger->log_workqueue); - - return 0; } static int __maybe_unused cros_usbpd_logger_resume(struct device *dev) @@ -257,7 +255,7 @@ static struct platform_driver cros_usbpd_logger_driver = { .pm = &cros_usbpd_logger_pm_ops, }, .probe = cros_usbpd_logger_probe, - .remove = cros_usbpd_logger_remove, + .remove_new = cros_usbpd_logger_remove, }; module_platform_driver(cros_usbpd_logger_driver); -- cgit v1.2.3 From b98362be7c92003903c9feefddeab7ca30392aae Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:22 +0200 Subject: platform/chrome: cros_usbpd_notify: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-10-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_usbpd_notify.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c index 10670b6588e3..aacad022f21d 100644 --- a/drivers/platform/chrome/cros_usbpd_notify.c +++ b/drivers/platform/chrome/cros_usbpd_notify.c @@ -134,15 +134,13 @@ static int cros_usbpd_notify_probe_acpi(struct platform_device *pdev) return 0; } -static int cros_usbpd_notify_remove_acpi(struct platform_device *pdev) +static void cros_usbpd_notify_remove_acpi(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct acpi_device *adev = ACPI_COMPANION(dev); acpi_remove_notify_handler(adev->handle, ACPI_ALL_NOTIFY, cros_usbpd_notify_acpi); - - return 0; } static const struct acpi_device_id cros_usbpd_notify_acpi_device_ids[] = { @@ -157,7 +155,7 @@ static struct platform_driver cros_usbpd_notify_acpi_driver = { .acpi_match_table = cros_usbpd_notify_acpi_device_ids, }, .probe = cros_usbpd_notify_probe_acpi, - .remove = cros_usbpd_notify_remove_acpi, + .remove_new = cros_usbpd_notify_remove_acpi, }; #endif /* CONFIG_ACPI */ @@ -209,7 +207,7 @@ static int cros_usbpd_notify_probe_plat(struct platform_device *pdev) return 0; } -static int cros_usbpd_notify_remove_plat(struct platform_device *pdev) +static void cros_usbpd_notify_remove_plat(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct cros_ec_dev *ecdev = dev_get_drvdata(dev->parent); @@ -218,8 +216,6 @@ static int cros_usbpd_notify_remove_plat(struct platform_device *pdev) blocking_notifier_chain_unregister(&ecdev->ec_dev->event_notifier, &pdnotify->nb); - - return 0; } static struct platform_driver cros_usbpd_notify_plat_driver = { @@ -227,7 +223,7 @@ static struct platform_driver cros_usbpd_notify_plat_driver = { .name = DRV_NAME, }, .probe = cros_usbpd_notify_probe_plat, - .remove = cros_usbpd_notify_remove_plat, + .remove_new = cros_usbpd_notify_remove_plat, }; static int __init cros_usbpd_notify_init(void) -- cgit v1.2.3 From 48648504e488f9affbb2bbe8b48e4f5f724a89ba Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:23 +0200 Subject: platform/chrome/wilco_ec: core: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-11-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/wilco_ec/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/wilco_ec/core.c b/drivers/platform/chrome/wilco_ec/core.c index d6a994bdc182..9b59a1bed286 100644 --- a/drivers/platform/chrome/wilco_ec/core.c +++ b/drivers/platform/chrome/wilco_ec/core.c @@ -132,7 +132,7 @@ unregister_debugfs: return ret; } -static int wilco_ec_remove(struct platform_device *pdev) +static void wilco_ec_remove(struct platform_device *pdev) { struct wilco_ec_device *ec = platform_get_drvdata(pdev); @@ -142,7 +142,6 @@ static int wilco_ec_remove(struct platform_device *pdev) platform_device_unregister(ec->rtc_pdev); if (ec->debugfs_pdev) platform_device_unregister(ec->debugfs_pdev); - return 0; } static const struct acpi_device_id wilco_ec_acpi_device_ids[] = { @@ -157,7 +156,7 @@ static struct platform_driver wilco_ec_driver = { .acpi_match_table = wilco_ec_acpi_device_ids, }, .probe = wilco_ec_probe, - .remove = wilco_ec_remove, + .remove_new = wilco_ec_remove, }; module_platform_driver(wilco_ec_driver); -- cgit v1.2.3 From 1fca58f347d8a958bd708a98c0e478e65ab48408 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:24 +0200 Subject: platform/chrome/wilco_ec: debugfs: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-12-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/wilco_ec/debugfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/wilco_ec/debugfs.c b/drivers/platform/chrome/wilco_ec/debugfs.c index 7a13f13b16cd..93c11f81ca45 100644 --- a/drivers/platform/chrome/wilco_ec/debugfs.c +++ b/drivers/platform/chrome/wilco_ec/debugfs.c @@ -260,11 +260,9 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev) return 0; } -static int wilco_ec_debugfs_remove(struct platform_device *pdev) +static void wilco_ec_debugfs_remove(struct platform_device *pdev) { debugfs_remove_recursive(debug_info->dir); - - return 0; } static struct platform_driver wilco_ec_debugfs_driver = { @@ -272,7 +270,7 @@ static struct platform_driver wilco_ec_debugfs_driver = { .name = DRV_NAME, }, .probe = wilco_ec_debugfs_probe, - .remove = wilco_ec_debugfs_remove, + .remove_new = wilco_ec_debugfs_remove, }; module_platform_driver(wilco_ec_debugfs_driver); -- cgit v1.2.3 From 7396a5b980fdeb2cb97136db45405b4fb5d21dfc Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 27 Sep 2023 10:10:25 +0200 Subject: platform/chrome/wilco_ec: telemetry: Convert to platform remove callback returning void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20230927081040.2198742-13-u.kleine-koenig@pengutronix.de Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/wilco_ec/telemetry.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/wilco_ec/telemetry.c b/drivers/platform/chrome/wilco_ec/telemetry.c index 54708aa6c700..253098bace63 100644 --- a/drivers/platform/chrome/wilco_ec/telemetry.c +++ b/drivers/platform/chrome/wilco_ec/telemetry.c @@ -400,20 +400,18 @@ static int telem_device_probe(struct platform_device *pdev) return 0; } -static int telem_device_remove(struct platform_device *pdev) +static void telem_device_remove(struct platform_device *pdev) { struct telem_device_data *dev_data = platform_get_drvdata(pdev); cdev_device_del(&dev_data->cdev, &dev_data->dev); ida_simple_remove(&telem_ida, MINOR(dev_data->dev.devt)); put_device(&dev_data->dev); - - return 0; } static struct platform_driver telem_driver = { .probe = telem_device_probe, - .remove = telem_device_remove, + .remove_new = telem_device_remove, .driver = { .name = DRV_NAME, }, -- cgit v1.2.3 From a88f6ef679579256ec9561fb1359332df5eaa94d Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 2 Oct 2023 17:34:25 -0700 Subject: platform/chrome: cros_ec_typec: Use semi-colons instead of commas These should be semi-colons so that one statement is per line. Cc: Prashant Malani Signed-off-by: Stephen Boyd Acked-by: Prashant Malani Link: https://lore.kernel.org/r/20231003003429.1378109-2-swboyd@chromium.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_typec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index d0b4d3fc40ed..82e7d08b52c7 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -271,9 +271,9 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, struct typec_altmode *amode; /* All PD capable CrOS devices are assumed to support DP altmode. */ - desc.svid = USB_TYPEC_DP_SID, - desc.mode = USB_TYPEC_DP_MODE, - desc.vdo = DP_PORT_VDO, + desc.svid = USB_TYPEC_DP_SID; + desc.mode = USB_TYPEC_DP_MODE; + desc.vdo = DP_PORT_VDO; amode = typec_port_register_altmode(port->port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode); @@ -287,8 +287,8 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, * here for now. */ memset(&desc, 0, sizeof(desc)); - desc.svid = USB_TYPEC_TBT_SID, - desc.mode = TYPEC_ANY_MODE, + desc.svid = USB_TYPEC_TBT_SID; + desc.mode = TYPEC_ANY_MODE; amode = typec_port_register_altmode(port->port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode); -- cgit v1.2.3 From 2b055bf8ac8492111a62177764e54e0d2614c6b8 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 2 Oct 2023 17:34:26 -0700 Subject: platform/chrome: cros_ec_typec: Use dev_err_probe() more There's some debug prints here that can be upgraded to dev_err_probe() so that we don't have to fish out the error messages when a true error happens. If they're simply probe defers then the kernel will keep silent but if they're true errors we'll see the errors in the logs. Cc: Prashant Malani Signed-off-by: Stephen Boyd Acked-by: Prashant Malani Link: https://lore.kernel.org/r/20231003003429.1378109-3-swboyd@chromium.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_typec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 82e7d08b52c7..67000e4a8082 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -80,28 +80,28 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port, port->mux = fwnode_typec_mux_get(fwnode); if (IS_ERR(port->mux)) { ret = PTR_ERR(port->mux); - dev_dbg(dev, "Mux handle not found: %d.\n", ret); + dev_err_probe(dev, ret, "Mux handle not found\n"); goto mux_err; } port->retimer = fwnode_typec_retimer_get(fwnode); if (IS_ERR(port->retimer)) { ret = PTR_ERR(port->retimer); - dev_dbg(dev, "Retimer handle not found: %d.\n", ret); + dev_err_probe(dev, ret, "Retimer handle not found\n"); goto retimer_sw_err; } port->ori_sw = fwnode_typec_switch_get(fwnode); if (IS_ERR(port->ori_sw)) { ret = PTR_ERR(port->ori_sw); - dev_dbg(dev, "Orientation switch handle not found: %d\n", ret); + dev_err_probe(dev, ret, "Orientation switch handle not found\n"); goto ori_sw_err; } port->role_sw = fwnode_usb_role_switch_get(fwnode); if (IS_ERR(port->role_sw)) { ret = PTR_ERR(port->role_sw); - dev_dbg(dev, "USB role switch handle not found: %d\n", ret); + dev_err_probe(dev, ret, "USB role switch handle not found\n"); goto role_sw_err; } -- cgit v1.2.3 From 14e7c01cc3494b75c3ff1d099a2f5f76b1fcb01d Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 2 Oct 2023 17:34:27 -0700 Subject: platform/chrome: cros_typec_vdm: Mark port_amode_ops const Mark this struct of functions const so it moves to RO memory. Cc: Prashant Malani Signed-off-by: Stephen Boyd Acked-by: Prashant Malani Link: https://lore.kernel.org/r/20231003003429.1378109-4-swboyd@chromium.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_typec_vdm.c | 2 +- drivers/platform/chrome/cros_typec_vdm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c index 20515ee0a20e..3f632fd35000 100644 --- a/drivers/platform/chrome/cros_typec_vdm.c +++ b/drivers/platform/chrome/cros_typec_vdm.c @@ -142,7 +142,7 @@ static int cros_typec_port_amode_vdm(struct typec_altmode *amode, const u32 hdr, sizeof(req), NULL, 0); } -struct typec_altmode_ops port_amode_ops = { +const struct typec_altmode_ops port_amode_ops = { .enter = cros_typec_port_amode_enter, .vdm = cros_typec_port_amode_vdm, }; diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h index 95a6a75d32b6..631bd2ce4b00 100644 --- a/drivers/platform/chrome/cros_typec_vdm.h +++ b/drivers/platform/chrome/cros_typec_vdm.h @@ -5,7 +5,7 @@ #include -extern struct typec_altmode_ops port_amode_ops; +extern const struct typec_altmode_ops port_amode_ops; void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num); void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num); -- cgit v1.2.3 From 2f3dd39e2b492bec366487a2c9bcbdbd7792f77c Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 2 Oct 2023 17:34:28 -0700 Subject: platform/chrome: cros_ec_proto: Mark outdata as const The 'outdata' is copied to the data buffer in cros_ec_cmd() before being sent over to the EC. Mark the argument as const so that callers can pass const pointers to this function and so that callers know the data won't be modified. Cc: Prashant Malani Signed-off-by: Stephen Boyd Acked-by: Prashant Malani Link: https://lore.kernel.org/r/20231003003429.1378109-5-swboyd@chromium.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto.c | 2 +- include/linux/platform_data/cros_ec_proto.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 475a6dd72db6..945b1b15a04c 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -1004,7 +1004,7 @@ EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count); int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, - void *outdata, + const void *outdata, size_t outsize, void *indata, size_t insize) diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h index 4f9f756bc17c..8865e350c12a 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -258,7 +258,7 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature); int cros_ec_get_sensor_count(struct cros_ec_dev *ec); -int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, void *outdata, +int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, const void *outdata, size_t outsize, void *indata, size_t insize); /** -- cgit v1.2.3 From a7bad167bdc3cf4c47c6a9ec4fc9b4ae18b4614d Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Tue, 3 Oct 2023 08:04:53 +0000 Subject: platform/chrome: cros_ec: fix compilation warning When including cros_ec.h solely, the compiler emits the following warning: > 'struct cros_ec_device' declared inside parameter list will not be visible outside of this definition or declaration Fix it by forward declaration. Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20231003080453.4011301-1-tzungbi@kernel.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec.h b/drivers/platform/chrome/cros_ec.h index bbca0096868a..2b2574236030 100644 --- a/drivers/platform/chrome/cros_ec.h +++ b/drivers/platform/chrome/cros_ec.h @@ -10,6 +10,8 @@ #include +struct cros_ec_device; + int cros_ec_register(struct cros_ec_device *ec_dev); void cros_ec_unregister(struct cros_ec_device *ec_dev); -- cgit v1.2.3 From e410b4ade83d06a046f6e32b5085997502ba0559 Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Tue, 3 Oct 2023 08:05:04 +0000 Subject: platform/chrome: kunit: initialize lock for fake ec_dev cros_ec_cmd_xfer() uses ec_dev->lock. Initialize it. Otherwise, dmesg shows the following: > DEBUG_LOCKS_WARN_ON(lock->magic != lock) > ... > Call Trace: > ? __mutex_lock > ? __warn > ? __mutex_lock > ... > ? cros_ec_cmd_xfer Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20231003080504.4011337-1-tzungbi@kernel.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto_test.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 5b9748e0463b..63e38671e95a 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -2668,6 +2668,7 @@ static int cros_ec_proto_test_init(struct kunit *test) ec_dev->dev->release = cros_ec_proto_test_release; ec_dev->cmd_xfer = cros_kunit_ec_xfer_mock; ec_dev->pkt_xfer = cros_kunit_ec_xfer_mock; + mutex_init(&ec_dev->lock); priv->msg = (struct cros_ec_command *)priv->_msg; -- cgit v1.2.3 From 466f70fb1b10fd139582646285e587fb38a9ff2c Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Tue, 3 Oct 2023 08:05:15 +0000 Subject: platform/chrome: kunit: make EC protocol tests independent Remove CONFIG_CROS_KUNIT and common code concept for ChromeOS Kunit but make it bundle to ChromeOS EC protocol tests. Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20231003080515.4011374-1-tzungbi@kernel.org Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/Kconfig | 6 +- drivers/platform/chrome/Makefile | 5 +- drivers/platform/chrome/cros_ec_proto_test.c | 2 +- drivers/platform/chrome/cros_ec_proto_test_util.c | 128 +++++++++++++++++++++ drivers/platform/chrome/cros_ec_proto_test_util.h | 48 ++++++++ drivers/platform/chrome/cros_kunit_util.c | 130 ---------------------- drivers/platform/chrome/cros_kunit_util.h | 48 -------- 7 files changed, 182 insertions(+), 185 deletions(-) create mode 100644 drivers/platform/chrome/cros_ec_proto_test_util.c create mode 100644 drivers/platform/chrome/cros_ec_proto_test_util.h delete mode 100644 drivers/platform/chrome/cros_kunit_util.c delete mode 100644 drivers/platform/chrome/cros_kunit_util.h (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 7d82a0946e1c..7a83346bfa53 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -299,12 +299,12 @@ config CROS_TYPEC_SWITCH source "drivers/platform/chrome/wilco_ec/Kconfig" # Kunit test cases -config CROS_KUNIT - tristate "Kunit tests for ChromeOS" if !KUNIT_ALL_TESTS +config CROS_KUNIT_EC_PROTO_TEST + tristate "Kunit tests for ChromeOS EC protocol" if !KUNIT_ALL_TESTS depends on KUNIT && CROS_EC default KUNIT_ALL_TESTS select CROS_EC_PROTO help - ChromeOS Kunit tests. + Kunit tests for ChromeOS EC protocol. endif # CHROMEOS_PLATFORMS diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 9e26e45c4a37..2dcc6ccc2302 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -36,6 +36,5 @@ obj-$(CONFIG_CROS_USBPD_NOTIFY) += cros_usbpd_notify.o obj-$(CONFIG_WILCO_EC) += wilco_ec/ # Kunit test cases -obj-$(CONFIG_CROS_KUNIT) += cros_kunit.o -cros_kunit-objs := cros_kunit_util.o -cros_kunit-objs += cros_ec_proto_test.o +obj-$(CONFIG_CROS_KUNIT_EC_PROTO_TEST) += cros_kunit_proto_test.o +cros_kunit_proto_test-objs := cros_ec_proto_test_util.o cros_ec_proto_test.o diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 63e38671e95a..b6169d6f2467 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -11,7 +11,7 @@ #include #include "cros_ec.h" -#include "cros_kunit_util.h" +#include "cros_ec_proto_test_util.h" #define BUFSIZE 512 diff --git a/drivers/platform/chrome/cros_ec_proto_test_util.c b/drivers/platform/chrome/cros_ec_proto_test_util.c new file mode 100644 index 000000000000..65d328bcd6eb --- /dev/null +++ b/drivers/platform/chrome/cros_ec_proto_test_util.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * CrOS Kunit tests utilities. + */ + +#include + +#include +#include +#include +#include + +#include "cros_ec.h" +#include "cros_ec_proto_test_util.h" + +int cros_kunit_ec_xfer_mock_default_result; +int cros_kunit_ec_xfer_mock_default_ret; +int cros_kunit_ec_cmd_xfer_mock_called; +int cros_kunit_ec_pkt_xfer_mock_called; + +static struct list_head cros_kunit_ec_xfer_mock_in; +static struct list_head cros_kunit_ec_xfer_mock_out; + +int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + struct ec_xfer_mock *mock; + + mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_in, struct ec_xfer_mock, list); + if (!mock) { + msg->result = cros_kunit_ec_xfer_mock_default_result; + return cros_kunit_ec_xfer_mock_default_ret; + } + + list_del(&mock->list); + + memcpy(&mock->msg, msg, sizeof(*msg)); + if (msg->outsize) { + mock->i_data = kunit_kzalloc(mock->test, msg->outsize, GFP_KERNEL); + if (mock->i_data) + memcpy(mock->i_data, msg->data, msg->outsize); + } + + msg->result = mock->result; + if (msg->insize) + memcpy(msg->data, mock->o_data, min(msg->insize, mock->o_data_len)); + + list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_out); + + return mock->ret; +} + +int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + ++cros_kunit_ec_cmd_xfer_mock_called; + return cros_kunit_ec_xfer_mock(ec_dev, msg); +} + +int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + ++cros_kunit_ec_pkt_xfer_mock_called; + return cros_kunit_ec_xfer_mock(ec_dev, msg); +} + +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size) +{ + return cros_kunit_ec_xfer_mock_addx(test, size, EC_RES_SUCCESS, size); +} + +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test, + int ret, int result, size_t size) +{ + struct ec_xfer_mock *mock; + + mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); + if (!mock) + return NULL; + + list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_in); + mock->test = test; + + mock->ret = ret; + mock->result = result; + mock->o_data = kunit_kzalloc(test, size, GFP_KERNEL); + if (!mock->o_data) + return NULL; + mock->o_data_len = size; + + return mock; +} + +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void) +{ + struct ec_xfer_mock *mock; + + mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_out, struct ec_xfer_mock, list); + if (mock) + list_del(&mock->list); + + return mock; +} + +int cros_kunit_readmem_mock_offset; +u8 *cros_kunit_readmem_mock_data; +int cros_kunit_readmem_mock_ret; + +int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset, + unsigned int bytes, void *dest) +{ + cros_kunit_readmem_mock_offset = offset; + + memcpy(dest, cros_kunit_readmem_mock_data, bytes); + + return cros_kunit_readmem_mock_ret; +} + +void cros_kunit_mock_reset(void) +{ + cros_kunit_ec_xfer_mock_default_result = 0; + cros_kunit_ec_xfer_mock_default_ret = 0; + cros_kunit_ec_cmd_xfer_mock_called = 0; + cros_kunit_ec_pkt_xfer_mock_called = 0; + INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in); + INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out); + + cros_kunit_readmem_mock_offset = 0; + cros_kunit_readmem_mock_data = NULL; + cros_kunit_readmem_mock_ret = 0; +} diff --git a/drivers/platform/chrome/cros_ec_proto_test_util.h b/drivers/platform/chrome/cros_ec_proto_test_util.h new file mode 100644 index 000000000000..414002271c9c --- /dev/null +++ b/drivers/platform/chrome/cros_ec_proto_test_util.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * CrOS Kunit tests utilities. + */ + +#ifndef _CROS_KUNIT_UTIL_H_ +#define _CROS_KUNIT_UTIL_H_ + +#include + +struct ec_xfer_mock { + struct list_head list; + struct kunit *test; + + /* input */ + struct cros_ec_command msg; + void *i_data; + + /* output */ + int ret; + int result; + void *o_data; + u32 o_data_len; +}; + +extern int cros_kunit_ec_xfer_mock_default_result; +extern int cros_kunit_ec_xfer_mock_default_ret; +extern int cros_kunit_ec_cmd_xfer_mock_called; +extern int cros_kunit_ec_pkt_xfer_mock_called; + +int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); +int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); +int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size); +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test, + int ret, int result, size_t size); +struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void); + +extern int cros_kunit_readmem_mock_offset; +extern u8 *cros_kunit_readmem_mock_data; +extern int cros_kunit_readmem_mock_ret; + +int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset, + unsigned int bytes, void *dest); + +void cros_kunit_mock_reset(void); + +#endif diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c deleted file mode 100644 index f0fda96b11bd..000000000000 --- a/drivers/platform/chrome/cros_kunit_util.c +++ /dev/null @@ -1,130 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * CrOS Kunit tests utilities. - */ - -#include - -#include -#include -#include -#include - -#include "cros_ec.h" -#include "cros_kunit_util.h" - -int cros_kunit_ec_xfer_mock_default_result; -int cros_kunit_ec_xfer_mock_default_ret; -int cros_kunit_ec_cmd_xfer_mock_called; -int cros_kunit_ec_pkt_xfer_mock_called; - -static struct list_head cros_kunit_ec_xfer_mock_in; -static struct list_head cros_kunit_ec_xfer_mock_out; - -int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) -{ - struct ec_xfer_mock *mock; - - mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_in, struct ec_xfer_mock, list); - if (!mock) { - msg->result = cros_kunit_ec_xfer_mock_default_result; - return cros_kunit_ec_xfer_mock_default_ret; - } - - list_del(&mock->list); - - memcpy(&mock->msg, msg, sizeof(*msg)); - if (msg->outsize) { - mock->i_data = kunit_kzalloc(mock->test, msg->outsize, GFP_KERNEL); - if (mock->i_data) - memcpy(mock->i_data, msg->data, msg->outsize); - } - - msg->result = mock->result; - if (msg->insize) - memcpy(msg->data, mock->o_data, min(msg->insize, mock->o_data_len)); - - list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_out); - - return mock->ret; -} - -int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) -{ - ++cros_kunit_ec_cmd_xfer_mock_called; - return cros_kunit_ec_xfer_mock(ec_dev, msg); -} - -int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) -{ - ++cros_kunit_ec_pkt_xfer_mock_called; - return cros_kunit_ec_xfer_mock(ec_dev, msg); -} - -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size) -{ - return cros_kunit_ec_xfer_mock_addx(test, size, EC_RES_SUCCESS, size); -} - -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test, - int ret, int result, size_t size) -{ - struct ec_xfer_mock *mock; - - mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); - if (!mock) - return NULL; - - list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_in); - mock->test = test; - - mock->ret = ret; - mock->result = result; - mock->o_data = kunit_kzalloc(test, size, GFP_KERNEL); - if (!mock->o_data) - return NULL; - mock->o_data_len = size; - - return mock; -} - -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void) -{ - struct ec_xfer_mock *mock; - - mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_out, struct ec_xfer_mock, list); - if (mock) - list_del(&mock->list); - - return mock; -} - -int cros_kunit_readmem_mock_offset; -u8 *cros_kunit_readmem_mock_data; -int cros_kunit_readmem_mock_ret; - -int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset, - unsigned int bytes, void *dest) -{ - cros_kunit_readmem_mock_offset = offset; - - memcpy(dest, cros_kunit_readmem_mock_data, bytes); - - return cros_kunit_readmem_mock_ret; -} - -void cros_kunit_mock_reset(void) -{ - cros_kunit_ec_xfer_mock_default_result = 0; - cros_kunit_ec_xfer_mock_default_ret = 0; - cros_kunit_ec_cmd_xfer_mock_called = 0; - cros_kunit_ec_pkt_xfer_mock_called = 0; - INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in); - INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out); - - cros_kunit_readmem_mock_offset = 0; - cros_kunit_readmem_mock_data = NULL; - cros_kunit_readmem_mock_ret = 0; -} - -MODULE_LICENSE("GPL"); diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h deleted file mode 100644 index 414002271c9c..000000000000 --- a/drivers/platform/chrome/cros_kunit_util.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * CrOS Kunit tests utilities. - */ - -#ifndef _CROS_KUNIT_UTIL_H_ -#define _CROS_KUNIT_UTIL_H_ - -#include - -struct ec_xfer_mock { - struct list_head list; - struct kunit *test; - - /* input */ - struct cros_ec_command msg; - void *i_data; - - /* output */ - int ret; - int result; - void *o_data; - u32 o_data_len; -}; - -extern int cros_kunit_ec_xfer_mock_default_result; -extern int cros_kunit_ec_xfer_mock_default_ret; -extern int cros_kunit_ec_cmd_xfer_mock_called; -extern int cros_kunit_ec_pkt_xfer_mock_called; - -int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); -int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); -int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size); -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test, - int ret, int result, size_t size); -struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void); - -extern int cros_kunit_readmem_mock_offset; -extern u8 *cros_kunit_readmem_mock_data; -extern int cros_kunit_readmem_mock_ret; - -int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset, - unsigned int bytes, void *dest); - -void cros_kunit_mock_reset(void); - -#endif -- cgit v1.2.3 From 47ea0ddb1f5604ba3496baa19110aec6a3151f2e Mon Sep 17 00:00:00 2001 From: Lalith Rajendran Date: Fri, 27 Oct 2023 16:02:22 -0500 Subject: platform/chrome: cros_ec_lpc: Separate host command and irq disable Both cros host command and irq disable were moved to suspend prepare stage from late suspend recently. This is causing EC to report MKBP event timeouts during suspend stress testing. When the MKBP event timeouts happen during suspend, subsequent wakeup of AP by EC using MKBP doesn't happen properly. Move the irq disabling part back to late suspend stage which is a general suggestion from the suspend kernel documentaiton to do irq disable as late as possible. Fixes: 4b9abbc132b8 ("platform/chrome: cros_ec_lpc: Move host command to prepare/complete") Signed-off-by: Lalith Rajendran Link: https://lore.kernel.org/r/20231027160221.v4.1.I1725c3ed27eb7cd9836904e49e8bfa9fb0200a97@changeid Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec.c | 116 +++++++++++++++++++++++++++------- drivers/platform/chrome/cros_ec.h | 4 ++ drivers/platform/chrome/cros_ec_lpc.c | 22 +++++-- 3 files changed, 116 insertions(+), 26 deletions(-) (limited to 'drivers/platform') diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 5d36fbc75e1b..badc68bbae8c 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -321,17 +321,8 @@ void cros_ec_unregister(struct cros_ec_device *ec_dev) EXPORT_SYMBOL(cros_ec_unregister); #ifdef CONFIG_PM_SLEEP -/** - * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device. - * @ec_dev: Device to suspend. - * - * This can be called by drivers to handle a suspend event. - * - * Return: 0 on success or negative error code. - */ -int cros_ec_suspend(struct cros_ec_device *ec_dev) +static void cros_ec_send_suspend_event(struct cros_ec_device *ec_dev) { - struct device *dev = ec_dev->dev; int ret; u8 sleep_event; @@ -343,7 +334,26 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev) if (ret < 0) dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec\n", ret); +} +/** + * cros_ec_suspend_prepare() - Handle a suspend prepare operation for the ChromeOS EC device. + * @ec_dev: Device to suspend. + * + * This can be called by drivers to handle a suspend prepare stage of suspend. + * + * Return: 0 always. + */ +int cros_ec_suspend_prepare(struct cros_ec_device *ec_dev) +{ + cros_ec_send_suspend_event(ec_dev); + return 0; +} +EXPORT_SYMBOL(cros_ec_suspend_prepare); + +static void cros_ec_disable_irq(struct cros_ec_device *ec_dev) +{ + struct device *dev = ec_dev->dev; if (device_may_wakeup(dev)) ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq); else @@ -351,7 +361,35 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev) disable_irq(ec_dev->irq); ec_dev->suspended = true; +} +/** + * cros_ec_suspend_late() - Handle a suspend late operation for the ChromeOS EC device. + * @ec_dev: Device to suspend. + * + * This can be called by drivers to handle a suspend late stage of suspend. + * + * Return: 0 always. + */ +int cros_ec_suspend_late(struct cros_ec_device *ec_dev) +{ + cros_ec_disable_irq(ec_dev); + return 0; +} +EXPORT_SYMBOL(cros_ec_suspend_late); + +/** + * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device. + * @ec_dev: Device to suspend. + * + * This can be called by drivers to handle a suspend event. + * + * Return: 0 always. + */ +int cros_ec_suspend(struct cros_ec_device *ec_dev) +{ + cros_ec_send_suspend_event(ec_dev); + cros_ec_disable_irq(ec_dev); return 0; } EXPORT_SYMBOL(cros_ec_suspend); @@ -370,22 +408,11 @@ static void cros_ec_report_events_during_suspend(struct cros_ec_device *ec_dev) } } -/** - * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device. - * @ec_dev: Device to resume. - * - * This can be called by drivers to handle a resume event. - * - * Return: 0 on success or negative error code. - */ -int cros_ec_resume(struct cros_ec_device *ec_dev) +static void cros_ec_send_resume_event(struct cros_ec_device *ec_dev) { int ret; u8 sleep_event; - ec_dev->suspended = false; - enable_irq(ec_dev->irq); - sleep_event = (!IS_ENABLED(CONFIG_ACPI) || pm_suspend_via_firmware()) ? HOST_SLEEP_EVENT_S3_RESUME : HOST_SLEEP_EVENT_S0IX_RESUME; @@ -394,6 +421,24 @@ int cros_ec_resume(struct cros_ec_device *ec_dev) if (ret < 0) dev_dbg(ec_dev->dev, "Error %d sending resume event to ec\n", ret); +} + +/** + * cros_ec_resume_complete() - Handle a resume complete operation for the ChromeOS EC device. + * @ec_dev: Device to resume. + * + * This can be called by drivers to handle a resume complete stage of resume. + */ +void cros_ec_resume_complete(struct cros_ec_device *ec_dev) +{ + cros_ec_send_resume_event(ec_dev); +} +EXPORT_SYMBOL(cros_ec_resume_complete); + +static void cros_ec_enable_irq(struct cros_ec_device *ec_dev) +{ + ec_dev->suspended = false; + enable_irq(ec_dev->irq); if (ec_dev->wake_enabled) disable_irq_wake(ec_dev->irq); @@ -403,8 +448,35 @@ int cros_ec_resume(struct cros_ec_device *ec_dev) * suspend. This way the clients know what to do with them. */ cros_ec_report_events_during_suspend(ec_dev); +} +/** + * cros_ec_resume_early() - Handle a resume early operation for the ChromeOS EC device. + * @ec_dev: Device to resume. + * + * This can be called by drivers to handle a resume early stage of resume. + * + * Return: 0 always. + */ +int cros_ec_resume_early(struct cros_ec_device *ec_dev) +{ + cros_ec_enable_irq(ec_dev); + return 0; +} +EXPORT_SYMBOL(cros_ec_resume_early); +/** + * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device. + * @ec_dev: Device to resume. + * + * This can be called by drivers to handle a resume event. + * + * Return: 0 always. + */ +int cros_ec_resume(struct cros_ec_device *ec_dev) +{ + cros_ec_enable_irq(ec_dev); + cros_ec_send_resume_event(ec_dev); return 0; } EXPORT_SYMBOL(cros_ec_resume); diff --git a/drivers/platform/chrome/cros_ec.h b/drivers/platform/chrome/cros_ec.h index 2b2574236030..6b95f1e0bace 100644 --- a/drivers/platform/chrome/cros_ec.h +++ b/drivers/platform/chrome/cros_ec.h @@ -16,7 +16,11 @@ int cros_ec_register(struct cros_ec_device *ec_dev); void cros_ec_unregister(struct cros_ec_device *ec_dev); int cros_ec_suspend(struct cros_ec_device *ec_dev); +int cros_ec_suspend_late(struct cros_ec_device *ec_dev); +int cros_ec_suspend_prepare(struct cros_ec_device *ec_dev); int cros_ec_resume(struct cros_ec_device *ec_dev); +int cros_ec_resume_early(struct cros_ec_device *ec_dev); +void cros_ec_resume_complete(struct cros_ec_device *ec_dev); irqreturn_t cros_ec_irq_thread(int irq, void *data); diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 897090f0f26e..f0f3d3d56157 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -547,22 +547,36 @@ MODULE_DEVICE_TABLE(dmi, cros_ec_lpc_dmi_table); static int cros_ec_lpc_prepare(struct device *dev) { struct cros_ec_device *ec_dev = dev_get_drvdata(dev); - - return cros_ec_suspend(ec_dev); + return cros_ec_suspend_prepare(ec_dev); } static void cros_ec_lpc_complete(struct device *dev) { struct cros_ec_device *ec_dev = dev_get_drvdata(dev); - cros_ec_resume(ec_dev); + cros_ec_resume_complete(ec_dev); +} + +static int cros_ec_lpc_suspend_late(struct device *dev) +{ + struct cros_ec_device *ec_dev = dev_get_drvdata(dev); + + return cros_ec_suspend_late(ec_dev); +} + +static int cros_ec_lpc_resume_early(struct device *dev) +{ + struct cros_ec_device *ec_dev = dev_get_drvdata(dev); + + return cros_ec_resume_early(ec_dev); } #endif static const struct dev_pm_ops cros_ec_lpc_pm_ops = { #ifdef CONFIG_PM_SLEEP .prepare = cros_ec_lpc_prepare, - .complete = cros_ec_lpc_complete + .complete = cros_ec_lpc_complete, #endif + SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_lpc_suspend_late, cros_ec_lpc_resume_early) }; static struct platform_driver cros_ec_lpc_driver = { -- cgit v1.2.3