[PATCH 2/2] dma-fence: Do not call kref utility functions from static inline code
Andy Ritger
aritger at nvidia.com
Tue Apr 18 17:55:04 UTC 2017
Commit 10383aea2f44 ("kref: Implement 'struct kref' using refcount_t")
updated the kref implementation to use refcount_t. Commit 29dee3c03abc
("locking/refcounts: Out-of-line everything") changed the refcount_t
utility functions from static inline to EXPORT_SYMBOL_GPL functions.
Through a chain of dma-fence -> kref -> refcount static inline utility
functions, drm drivers can inadvertently pick up a reference to the
EXPORT_SYMBOL_GPL refcount_t functions.
refcount_t is an internal implementation detail and not intended as
an interface. Thus, EXPORT_SYMBOL_GPL seems reasonable for it.
Higher-level dma-fence functions, on the other hand, are intended as an
interface exposed to drm drivers. So, it arguably seems reasonable that
dma-fence functions do not require EXPORT_SYMBOL_GPL.
Move dma_fence_{put,get,get_rcu} from static inline in dma-fence.h to
EXPORT_SYMBOL functions in dma-fence, to make the interface boundary clear.
Signed-off-by: Andy Ritger <aritger at nvidia.com>
---
drivers/dma-buf/dma-fence.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/linux/dma-fence.h | 40 +++-------------------------------------
2 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index d195d617076d..863bf55955ef 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -573,3 +573,44 @@ dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
trace_dma_fence_init(fence);
}
EXPORT_SYMBOL(dma_fence_init);
+
+/**
+ * dma_fence_put - decreases refcount of the fence
+ * @fence: [in] fence to reduce refcount of
+ */
+void dma_fence_put(struct dma_fence *fence)
+{
+ if (fence)
+ kref_put(&fence->refcount, dma_fence_release);
+}
+EXPORT_SYMBOL(dma_fence_put);
+
+/**
+ * dma_fence_get - increases refcount of the fence
+ * @fence: [in] fence to increase refcount of
+ *
+ * Returns the same fence, with refcount increased by 1.
+ */
+struct dma_fence *dma_fence_get(struct dma_fence *fence)
+{
+ if (fence)
+ kref_get(&fence->refcount);
+ return fence;
+}
+EXPORT_SYMBOL(dma_fence_get);
+
+/**
+ * dma_fence_get_rcu - get a fence from a reservation_object_list with
+ * rcu read lock
+ * @fence: [in] fence to increase refcount of
+ *
+ * Function returns NULL if no refcount could be obtained, or the fence.
+ */
+struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence)
+{
+ if (kref_get_unless_zero(&fence->refcount))
+ return fence;
+ else
+ return NULL;
+}
+EXPORT_SYMBOL(dma_fence_get_rcu);
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 6048fa404e57..0e8d714a5bc7 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -185,43 +185,9 @@ void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
void dma_fence_release(struct kref *kref);
void dma_fence_free(struct dma_fence *fence);
-/**
- * dma_fence_put - decreases refcount of the fence
- * @fence: [in] fence to reduce refcount of
- */
-static inline void dma_fence_put(struct dma_fence *fence)
-{
- if (fence)
- kref_put(&fence->refcount, dma_fence_release);
-}
-
-/**
- * dma_fence_get - increases refcount of the fence
- * @fence: [in] fence to increase refcount of
- *
- * Returns the same fence, with refcount increased by 1.
- */
-static inline struct dma_fence *dma_fence_get(struct dma_fence *fence)
-{
- if (fence)
- kref_get(&fence->refcount);
- return fence;
-}
-
-/**
- * dma_fence_get_rcu - get a fence from a reservation_object_list with
- * rcu read lock
- * @fence: [in] fence to increase refcount of
- *
- * Function returns NULL if no refcount could be obtained, or the fence.
- */
-static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence)
-{
- if (kref_get_unless_zero(&fence->refcount))
- return fence;
- else
- return NULL;
-}
+void dma_fence_put(struct dma_fence *fence);
+struct dma_fence *dma_fence_get(struct dma_fence *fence);
+struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence);
/**
* dma_fence_get_rcu_safe - acquire a reference to an RCU tracked fence
--
2.1.0
More information about the dri-devel
mailing list