1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2023 Google LLC.
6 #include <linux/device.h>
7 #include <linux/spmi.h>
9 static void devm_spmi_controller_release(struct device *parent, void *res)
11 spmi_controller_put(*(struct spmi_controller **)res);
14 struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size)
16 struct spmi_controller **ptr, *ctrl;
18 ptr = devres_alloc(devm_spmi_controller_release, sizeof(*ptr), GFP_KERNEL);
20 return ERR_PTR(-ENOMEM);
22 ctrl = spmi_controller_alloc(parent, size);
29 devres_add(parent, ptr);
33 EXPORT_SYMBOL_GPL(devm_spmi_controller_alloc);
35 static void devm_spmi_controller_remove(struct device *parent, void *res)
37 spmi_controller_remove(*(struct spmi_controller **)res);
40 int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl)
42 struct spmi_controller **ptr;
45 ptr = devres_alloc(devm_spmi_controller_remove, sizeof(*ptr), GFP_KERNEL);
49 ret = spmi_controller_add(ctrl);
56 devres_add(parent, ptr);
61 EXPORT_SYMBOL_GPL(devm_spmi_controller_add);
63 MODULE_LICENSE("GPL");
64 MODULE_DESCRIPTION("SPMI devres helpers");