Skip to contentSkip to conversation

Improve drmmode_fb_reference debugging code

PATCH In review Michel Dänzer 2 participants 2 messages Jun 22, 2017 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Improve drmmode_fb_reference debugging code

From: Michel Dänzer <[email protected]>

If a reference count is <= 0, call FatalError with the call location (in case it doesn't get resolved in the backtrace printed by FatalError).

---
 src/drmmode_display.h | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
src/drmmode_display.h +16 -12
index b64a938cd..f351bb09c 100644
@@ -133,32 +133,36 @@ enum drmmode_flip_sync {
 
 
 static inline void
-drmmode_fb_reference(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new)
+drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct drmmode_fb *new,
+			 const char *caller, unsigned line)
 {
 	if (new) {
 		if (new->refcnt <= 0) {
-			ErrorF("New FB's refcnt was %d in %s\n", new->refcnt,
-			       __func__);
-		} else {
-			new->refcnt++;
+			FatalError("New FB's refcnt was %d at %s:%u",
+				   new->refcnt, caller, line);
 		}
+
+		new->refcnt++;
 	}
 
 	if (*old) {
 		if ((*old)->refcnt <= 0) {
-			ErrorF("Old FB's refcnt was %d in %s\n",
-			       (*old)->refcnt, __func__);
-		} else {
-			if (--(*old)->refcnt == 0) {
-				drmModeRmFB(drm_fd, (*old)->handle);
-				free(*old);
-			}
+			FatalError("Old FB's refcnt was %d at %s:%u",
+				   (*old)->refcnt, caller, line);
+		}
+
+		if (--(*old)->refcnt == 0) {
+			drmModeRmFB(drm_fd, (*old)->handle);
+			free(*old);
 		}
 	}
 
 	*old = new;
 }
 
+#define drmmode_fb_reference(fd, old, new) \
+	drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__)
+
 
 extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr pAMDGPUEnt,
 					     drmmode_crtc_private_ptr drmmode_crtc,
Signature · 6 lines
2.11.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20170622080255.4448-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by Alex Deucher
#2 lore raw
Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Michel Dänzer
Sent: Thursday, June 22, 2017 4:03 AM
To: [email protected]
Subject: [PATCH xf86-video-amdgpu] Improve drmmode_fb_reference debugging code

Quoted 7 lines

From: Michel Dänzer <[email protected]>

If a reference count is <= 0, call FatalError with the call location (in case it doesn't get resolved in the backtrace printed by FatalError).

Quoted 65 lines
---
 src/drmmode_display.h | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
src/drmmode_display.h +16 -12
index b64a938cd..f351bb09c 100644
@@ -133,32 +133,36 @@ enum drmmode_flip_sync {
 
 
 static inline void
-drmmode_fb_reference(int drm_fd, struct drmmode_fb **old, struct
 drmmode_fb *new)
+drmmode_fb_reference_loc(int drm_fd, struct drmmode_fb **old, struct
 drmmode_fb *new,
+			 const char *caller, unsigned line)
 {
 	if (new) {
 		if (new->refcnt <= 0) {
-			ErrorF("New FB's refcnt was %d in %s\n", new-
 >refcnt,
-			       __func__);
-		} else {
-			new->refcnt++;
+			FatalError("New FB's refcnt was %d at %s:%u",
+				   new->refcnt, caller, line);
 		}
+
+		new->refcnt++;
 	}
 
 	if (*old) {
 		if ((*old)->refcnt <= 0) {
-			ErrorF("Old FB's refcnt was %d in %s\n",
-			       (*old)->refcnt, __func__);
-		} else {
-			if (--(*old)->refcnt == 0) {
-				drmModeRmFB(drm_fd, (*old)->handle);
-				free(*old);
-			}
+			FatalError("Old FB's refcnt was %d at %s:%u",
+				   (*old)->refcnt, caller, line);
+		}
+
+		if (--(*old)->refcnt == 0) {
+			drmModeRmFB(drm_fd, (*old)->handle);
+			free(*old);
 		}
 	}
 
 	*old = new;
 }
 
+#define drmmode_fb_reference(fd, old, new) \
+	drmmode_fb_reference_loc(fd, old, new, __func__, __LINE__)
+

extern int drmmode_page_flip_target_absolute(AMDGPUEntPtr
pAMDGPUEnt,
drmmode_crtc_private_ptr
drmmode_crtc,
--
2.11.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx