Skip to contentSkip to conversation

drm/bridge: drm_bridge_get/put(): document NULL pointer behaviour

PATCH RESEND Applied Luca Ceresoli 3 participants 5 messages Mar 24 – Apr 9

Subsystems (3)
lore
Share & tools
lore

Luca Ceresoli

author reviewer
#0 lore raw

PATCH RESEND 1/1 drm/bridge: drm_bridge_get/put(): document NULL pointer behaviour

drm_bridge_get and drm_bridge_put() do nothing when they are passed a NULL pointer, and they do so since their initial addition in commit 30d1b37d4c02 ("drm/bridge: add support for refcounting").

This allows simpler code in various places when using these functions. However it's not documented, so it's not clear whether it is part of the API "contract" or just a current implementation detail that might change in the future.

There is no visible reason to remove this NULL check, so document it, making it part of the contract, letting users count on it.

---
Historical note: I thought this was documented from the beginning and realized it's not the case when someone proposed adding a 'if (bridge) drm_bridge_put(bridge)' to a driver [0]. Let's fix it now.

[0] https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/drm_bridge.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_bridge.c +2 -2
index 3b165a0d1e77..3108249a63cd 100644
@@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
 
 /**
  * drm_bridge_get - Acquire a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
  *
  * This function increments the bridge's refcount.
  *
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
 
 /**
  * drm_bridge_put - Release a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
  *
  * This function decrements the bridge's reference count and frees the
  * object if the reference count drops to zero.

---
base-commit: a50007089e078a1b7a826559a02277b1601ee189
change-id: 20260129-drm-bridge-alloc-getput-document-null-check-a551e64b8fc1

Best regards,

Signature · 1 line
Luca Ceresoli <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw

Hi Luca,

Quoted 37 lines · Luca Ceresoli

drm_bridge_get and drm_bridge_put() do nothing when they are passed a NULL pointer, and they do so since their initial addition in commit 30d1b37d4c02 ("drm/bridge: add support for refcounting").

This allows simpler code in various places when using these functions. However it's not documented, so it's not clear whether it is part of the API "contract" or just a current implementation detail that might change in the future.

There is no visible reason to remove this NULL check, so document it, making it part of the contract, letting users count on it.

---
Historical note: I thought this was documented from the beginning and realized it's not the case when someone proposed adding a 'if (bridge) drm_bridge_put(bridge)' to a driver [0]. Let's fix it now.

[0] https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/drm_bridge.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_bridge.c +1 -1
index 3b165a0d1e77..3108249a63cd 100644
@@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
 
 /**
  * drm_bridge_get - Acquire a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
  *
  * This function increments the bridge's refcount.
  *

drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(drm_bridge_get); · line 303

Quoted 5 lines
drivers/gpu/drm/drm_bridge.c +1 -1
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
 
 /**
  * drm_bridge_put - Release a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing

So, we can drop the if(_T) check for cleanup action, right?

DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T))

Quoted 9 lines
drivers/gpu/drm/drm_bridge.c +0 -1
  *
  * This function decrements the bridge's reference count and frees the
  * object if the reference count drops to zero.
 
---

base-commit: a50007089e078a1b7a826559a02277b1601ee189
change-id: 20260129-drm-bridge-alloc-getput-document-null-check-a551e64b8fc1

Best regards,

Signature · 2 lines
Regards,
Liu Ying
author reviewer
#2 lore raw

Hello Liu,

Quoted 13 lines · Liu Ying
Quoted 13 lines
drivers/gpu/drm/drm_bridge.c +1 -1
@@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
 
 /**
  * drm_bridge_get - Acquire a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
  *
  * This function increments the bridge's refcount.
  *
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
 
Quoted 6 lines

drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(drm_bridge_get); · line 303

Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +1 -1
 /**
  * drm_bridge_put - Release a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing

So, we can drop the if(_T) check for cleanup action, right?

We could, but it's supposed to be there to help compiler optimizations:
https://elixir.bootlin.com/linux/v7.0-rc5/source/include/linux/cleanup.h#L192-L207

Quoted 3 lines

DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T))

Thanks!

Luca

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Reviewed-by on v1 1/1
#3 lore raw
In reply to Luca Ceresoli
Quoted 9 lines · Luca Ceresoli

drm_bridge_get and drm_bridge_put() do nothing when they are passed a NULL pointer, and they do so since their initial addition in commit 30d1b37d4c02 ("drm/bridge: add support for refcounting").

This allows simpler code in various places when using these functions. However it's not documented, so it's not clear whether it is part of the API "contract" or just a current implementation detail that might change in the future.

Quoted 4 lines

There is no visible reason to remove this NULL check, so document it, making it part of the contract, letting users count on it.

Quoted 38 lines

---
Historical note: I thought this was documented from the beginning and realized it's not the case when someone proposed adding a 'if (bridge) drm_bridge_put(bridge)' to a driver [0]. Let's fix it now.

[0] https://lore.kernel.org/lkml/[email protected]/

---
  drivers/gpu/drm/drm_bridge.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_bridge.c +2 -3
index 3b165a0d1e77..3108249a63cd 100644
@@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
 
  /**
   * drm_bridge_get - Acquire a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
   *
   * This function increments the bridge's refcount.
   *
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
 
  /**
   * drm_bridge_put - Release a bridge reference
- * @bridge: DRM bridge
+ * @bridge: DRM bridge; if NULL this function does nothing
   *
   * This function decrements the bridge's reference count and frees the
   * object if the reference count drops to zero.
 
---

base-commit: a50007089e078a1b7a826559a02277b1601ee189
change-id: 20260129-drm-bridge-alloc-getput-document-null-check-a551e64b8fc1

Best regards,

author reviewer Applied
#4 lore raw
In reply to Luca Ceresoli
Quoted 10 lines · Luca Ceresoli

drm_bridge_get and drm_bridge_put() do nothing when they are passed a NULL pointer, and they do so since their initial addition in commit 30d1b37d4c02 ("drm/bridge: add support for refcounting").

This allows simpler code in various places when using these functions. However it's not documented, so it's not clear whether it is part of the API "contract" or just a current implementation detail that might change in the future.

[...]

Applied, thanks!

[1/1] drm/bridge: drm_bridge_get/put(): document NULL pointer behaviour

      commit: af29fcbe806ecd10078c406470fecb902b3c0e55

Best regards,

Signature · 1 line
Luca Ceresoli <[email protected]>