Skip to content

Commit 168e4b2

Browse files
krzkTzung-Bi Shih
authored andcommitted
platform/chrome: cros_usbpd_logger: Simplify with devm
Simplify the driver by using devm interfaces, which allow to drop probe() error paths and the remove() callback. Change is not equivalent in the workqueue itself: use non-legacy API which does not set (__WQ_LEGACY | WQ_MEM_RECLAIM). The workqueue is used to update logs, thus there is no point to run it for memory reclaim. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20260305-workqueue-devm-v2-10-66a38741c652@oss.qualcomm.com Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
1 parent c98f7d6 commit 168e4b2

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

drivers/platform/chrome/cros_usbpd_logger.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright 2018 Google LLC.
66
*/
77

8+
#include <linux/devm-helpers.h>
89
#include <linux/ktime.h>
910
#include <linux/math64.h>
1011
#include <linux/mod_devicetable.h>
@@ -199,6 +200,7 @@ static int cros_usbpd_logger_probe(struct platform_device *pd)
199200
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
200201
struct device *dev = &pd->dev;
201202
struct logger_data *logger;
203+
int ret;
202204

203205
logger = devm_kzalloc(dev, sizeof(*logger), GFP_KERNEL);
204206
if (!logger)
@@ -210,25 +212,20 @@ static int cros_usbpd_logger_probe(struct platform_device *pd)
210212
platform_set_drvdata(pd, logger);
211213

212214
/* Retrieve PD event logs periodically */
213-
INIT_DELAYED_WORK(&logger->log_work, cros_usbpd_log_check);
214-
logger->log_workqueue = create_singlethread_workqueue("cros_usbpd_log");
215+
logger->log_workqueue = devm_alloc_ordered_workqueue(dev, "cros_usbpd_log", 0);
215216
if (!logger->log_workqueue)
216217
return -ENOMEM;
217218

219+
ret = devm_delayed_work_autocancel(dev, &logger->log_work, cros_usbpd_log_check);
220+
if (ret)
221+
return ret;
222+
218223
queue_delayed_work(logger->log_workqueue, &logger->log_work,
219224
CROS_USBPD_LOG_UPDATE_DELAY);
220225

221226
return 0;
222227
}
223228

224-
static void cros_usbpd_logger_remove(struct platform_device *pd)
225-
{
226-
struct logger_data *logger = platform_get_drvdata(pd);
227-
228-
cancel_delayed_work_sync(&logger->log_work);
229-
destroy_workqueue(logger->log_workqueue);
230-
}
231-
232229
static int __maybe_unused cros_usbpd_logger_resume(struct device *dev)
233230
{
234231
struct logger_data *logger = dev_get_drvdata(dev);
@@ -263,7 +260,6 @@ static struct platform_driver cros_usbpd_logger_driver = {
263260
.pm = &cros_usbpd_logger_pm_ops,
264261
},
265262
.probe = cros_usbpd_logger_probe,
266-
.remove = cros_usbpd_logger_remove,
267263
.id_table = cros_usbpd_logger_id,
268264
};
269265

0 commit comments

Comments
 (0)