[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_66CF9C91EB4A4417F70E9511649A57DEC906@qq.com>
Date: Fri, 28 Feb 2025 17:18:35 +0800
From: xiaopeitux@...mail.com
To: gregkh@...uxfoundation.org,
linux-kernel@...r.kernel.org,
andriy.shevchenko@...ux.intel.com
Cc: Pei Xiao <xiaopei01@...inos.cn>
Subject: [PATCH] driver core: Split devres APIs to device/devres.h
From: Pei Xiao <xiaopei01@...inos.cn>
Since a21cad931276 ("driver core: Split devres APIs to
device/devres.h"),but some APIs like 'devm_alloc_percpu' didn't move to
devres.h. we should also move it.
Signed-off-by: Pei Xiao <xiaopei01@...inos.cn>
---
include/linux/device.h | 60 -----------------------------------
include/linux/device/devres.h | 58 +++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 60 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index ec330af24151..ab383a9bbc17 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -281,63 +281,6 @@ int __must_check device_create_bin_file(struct device *dev,
void device_remove_bin_file(struct device *dev,
const struct bin_attribute *attr);
-/* allows to add/remove a custom action to devres stack */
-int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
-
-/**
- * devm_remove_action() - removes previously added custom action
- * @dev: Device that owns the action
- * @action: Function implementing the action
- * @data: Pointer to data passed to @action implementation
- *
- * Removes instance of @action previously added by devm_add_action().
- * Both action and data should match one of the existing entries.
- */
-static inline
-void devm_remove_action(struct device *dev, void (*action)(void *), void *data)
-{
- WARN_ON(devm_remove_action_nowarn(dev, action, data));
-}
-
-void devm_release_action(struct device *dev, void (*action)(void *), void *data);
-
-int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);
-#define devm_add_action(dev, action, data) \
- __devm_add_action(dev, action, data, #action)
-
-static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *),
- void *data, const char *name)
-{
- int ret;
-
- ret = __devm_add_action(dev, action, data, name);
- if (ret)
- action(data);
-
- return ret;
-}
-#define devm_add_action_or_reset(dev, action, data) \
- __devm_add_action_or_reset(dev, action, data, #action)
-
-/**
- * devm_alloc_percpu - Resource-managed alloc_percpu
- * @dev: Device to allocate per-cpu memory for
- * @type: Type to allocate per-cpu memory for
- *
- * Managed alloc_percpu. Per-cpu memory allocated with this function is
- * automatically freed on driver detach.
- *
- * RETURNS:
- * Pointer to allocated memory on success, NULL on failure.
- */
-#define devm_alloc_percpu(dev, type) \
- ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
- __alignof__(type)))
-
-void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
- size_t align);
-void devm_free_percpu(struct device *dev, void __percpu *pdata);
-
struct device_dma_parameters {
/*
* a low level driver may set these to teach IOMMU code about
@@ -1163,9 +1106,6 @@ static inline void device_remove_group(struct device *dev,
device_remove_groups(dev, groups);
}
-int __must_check devm_device_add_group(struct device *dev,
- const struct attribute_group *grp);
-
/*
* get_device - atomically increment the reference count for the device.
*
diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h
index 9b49f9915850..8f93f7388dc1 100644
--- a/include/linux/device/devres.h
+++ b/include/linux/device/devres.h
@@ -126,4 +126,62 @@ void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int in
#endif
+/* allows to add/remove a custom action to devres stack */
+int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
+
+/**
+ * devm_remove_action() - removes previously added custom action
+ * @dev: Device that owns the action
+ * @action: Function implementing the action
+ * @data: Pointer to data passed to @action implementation
+ *
+ * Removes instance of @action previously added by devm_add_action().
+ * Both action and data should match one of the existing entries.
+ */
+static inline
+void devm_remove_action(struct device *dev, void (*action)(void *), void *data)
+{
+ WARN_ON(devm_remove_action_nowarn(dev, action, data));
+}
+
+void devm_release_action(struct device *dev, void (*action)(void *), void *data);
+
+int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);
+#define devm_add_action(dev, action, data) \
+ __devm_add_action(dev, action, data, #action)
+
+static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *),
+ void *data, const char *name)
+{
+ int ret;
+
+ ret = __devm_add_action(dev, action, data, name);
+ if (ret)
+ action(data);
+
+ return ret;
+}
+#define devm_add_action_or_reset(dev, action, data) \
+ __devm_add_action_or_reset(dev, action, data, #action)
+
+/**
+ * devm_alloc_percpu - Resource-managed alloc_percpu
+ * @dev: Device to allocate per-cpu memory for
+ * @type: Type to allocate per-cpu memory for
+ *
+ * Managed alloc_percpu. Per-cpu memory allocated with this function is
+ * automatically freed on driver detach.
+ *
+ * RETURNS:
+ * Pointer to allocated memory on success, NULL on failure.
+ */
+#define devm_alloc_percpu(dev, type) \
+ ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
+ __alignof__(type)))
+
+void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
+ size_t align);
+void devm_free_percpu(struct device *dev, void __percpu *pdata);
+int __must_check devm_device_add_group(struct device *dev,
+ const struct attribute_group *grp);
#endif /* _DEVICE_DEVRES_H_ */
--
2.25.1
Powered by blists - more mailing lists