Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spmi: Introduce device-managed functions

Utilize the managed resource (devres) framework and add the following
devm_* helpers for the SPMI driver:

- devm_spmi_controller_alloc()
- devm_spmi_controller_add()

[sboyd@kernel.org: Rename to spmi-devres for module niceness, slap on
GPL module license]

Signed-off-by: Fei Shao <fshao@chromium.org>
Link: https://lore.kernel.org/r/20230824104101.4083400-2-fshao@chromium.org
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20231206231733.4031901-4-sboyd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Fei Shao and committed by
Greg Kroah-Hartman
b6e53731 e821d50a

+68 -1
+1 -1
drivers/spmi/Makefile
··· 2 2 # 3 3 # Makefile for kernel SPMI framework. 4 4 # 5 - obj-$(CONFIG_SPMI) += spmi.o 5 + obj-$(CONFIG_SPMI) += spmi.o spmi-devres.o 6 6 7 7 obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o 8 8 obj-$(CONFIG_SPMI_MSM_PMIC_ARB) += spmi-pmic-arb.o
+64
drivers/spmi/spmi-devres.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright 2023 Google LLC. 4 + */ 5 + 6 + #include <linux/device.h> 7 + #include <linux/spmi.h> 8 + 9 + static void devm_spmi_controller_release(struct device *parent, void *res) 10 + { 11 + spmi_controller_put(*(struct spmi_controller **)res); 12 + } 13 + 14 + struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size) 15 + { 16 + struct spmi_controller **ptr, *ctrl; 17 + 18 + ptr = devres_alloc(devm_spmi_controller_release, sizeof(*ptr), GFP_KERNEL); 19 + if (!ptr) 20 + return ERR_PTR(-ENOMEM); 21 + 22 + ctrl = spmi_controller_alloc(parent, size); 23 + if (!ctrl) { 24 + devres_free(ptr); 25 + return ERR_PTR(-ENOMEM); 26 + } 27 + 28 + *ptr = ctrl; 29 + devres_add(parent, ptr); 30 + 31 + return ctrl; 32 + } 33 + EXPORT_SYMBOL_GPL(devm_spmi_controller_alloc); 34 + 35 + static void devm_spmi_controller_remove(struct device *parent, void *res) 36 + { 37 + spmi_controller_remove(*(struct spmi_controller **)res); 38 + } 39 + 40 + int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl) 41 + { 42 + struct spmi_controller **ptr; 43 + int ret; 44 + 45 + ptr = devres_alloc(devm_spmi_controller_remove, sizeof(*ptr), GFP_KERNEL); 46 + if (!ptr) 47 + return -ENOMEM; 48 + 49 + ret = spmi_controller_add(ctrl); 50 + if (ret) { 51 + devres_free(ptr); 52 + return ret; 53 + } 54 + 55 + *ptr = ctrl; 56 + devres_add(parent, ptr); 57 + 58 + return 0; 59 + 60 + } 61 + EXPORT_SYMBOL_GPL(devm_spmi_controller_add); 62 + 63 + MODULE_LICENSE("GPL"); 64 + MODULE_DESCRIPTION("SPMI devres helpers");
+3
include/linux/spmi.h
··· 120 120 int spmi_controller_add(struct spmi_controller *ctrl); 121 121 void spmi_controller_remove(struct spmi_controller *ctrl); 122 122 123 + struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size); 124 + int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl); 125 + 123 126 /** 124 127 * struct spmi_driver - SPMI slave device driver 125 128 * @driver: SPMI device drivers should initialize name and owner field of