Skip to contentSkip to conversation

Minor cleanups

PATCH In review Thierry Reding 2 participants 9 messages Apr 8, 2014 – Apr 17, 2014

lore
Share & tools
lore
#0 lore raw

cover Minor cleanups

From: Thierry Reding <[email protected]>

These four patches clean up some minor issues in libdrm. Patch 1 makes gcc aware of various functions (such as drmMsg(), drm_debug_print(), etc) being printf-like and patches 2 and 3 fix up a number of warnings flagged as a result of that.

Patch 4 uses drmFreeVersion() instead of drmFree() to free a drmVersion structure to prevent memory leaks.

Thierry

Thierry Reding (4):
Mark functions printf-like where possible
intel: Fix some format strings
libdrm: Remove extraneous parameter
tests: Use drmFreeVersion() instead of drmFree()

 intel/intel_bufmgr_fake.c | 20 ++++++++++----------
 intel/intel_decode.c      |  7 ++-----
 tests/drmstat.c           |  2 +-
 tests/getversion.c        |  2 +-
 xf86drm.c                 | 12 ++++++++----
 xf86drm.h                 |  2 +-
 6 files changed, 23 insertions(+), 22 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 Mark functions printf-like where possible

From: Thierry Reding <[email protected]>

These functions all take a format string and either a list of variable arguments or a va_list. Use the new DRM_PRINTFLIKE macro to tell the compiler about it so that the arguments can be checked against the format string.

---
 intel/intel_decode.c |  7 ++-----
 tests/drmstat.c      |  2 +-
 xf86drm.c            | 10 +++++++---
 xf86drm.h            |  2 +-
 4 files changed, 11 insertions(+), 10 deletions(-)
intel/intel_decode.c +2 -5
index c0a0cafc904e..61239dd96d27 100644
@@ -29,6 +29,7 @@
 #include <stdarg.h>
 #include <string.h>
 
+#include "xf86drm.h"
 #include "intel_chipset.h"
 #include "intel_bufmgr.h"
 
@@ -104,11 +105,7 @@ static float int_as_float(uint32_t intval)
 	return uval.f;
 }
 
-static void
-instr_out(struct drm_intel_decode *ctx, unsigned int index,
-	  const char *fmt, ...) __attribute__((format(__printf__, 3, 4)));
-
-static void
+static void DRM_PRINTFLIKE(3, 4)
 instr_out(struct drm_intel_decode *ctx, unsigned int index,
 	  const char *fmt, ...)
 {
tests/drmstat.c +1 -1
index 345b8d2cda31..c51cbc6c9f61 100644
@@ -425,7 +425,7 @@ int main(int argc, char **argv)
     return r; 
 }
 
-void
+void DRM_PRINTFLIKE(4, 0)
 xf86VDrvMsgVerb(int scrnIndex, int type, int verb, const char *format,
                 va_list args)
 {
xf86drm.c +7 -3
index 720952ff2cbd..fa5701abae51 100644
@@ -104,12 +104,16 @@ void drmSetServerInfo(drmServerInfoPtr info)
  * This function is a wrapper around vfprintf().
  */
 
-static int drmDebugPrint(const char *format, va_list ap)
+static int DRM_PRINTFLIKE(1, 0)
+drmDebugPrint(const char *format, va_list ap)
 {
     return vfprintf(stderr, format, ap);
 }
 
-static int (*drm_debug_print)(const char *format, va_list ap) = drmDebugPrint;
+typedef int DRM_PRINTFLIKE(1, 0) (*debug_msg_func_t)(const char *format,
+						     va_list ap);
+
+static debug_msg_func_t drm_debug_print = drmDebugPrint;
 
 void
 drmMsg(const char *format, ...)
@@ -129,7 +133,7 @@ drmMsg(const char *format, ...)
 }
 
 void
-drmSetDebugMsgFunction(int (*debug_msg_ptr)(const char *format, va_list ap))
+drmSetDebugMsgFunction(debug_msg_func_t debug_msg_ptr)
 {
     drm_debug_print = debug_msg_ptr;
 }
xf86drm.h +1 -1
index 5e170f86fe5e..c024cc446354 100644
@@ -704,7 +704,7 @@ extern int  drmSLLookupNeighbors(void *l, unsigned long key,
 
 extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
 extern void drmCloseOnce(int fd);
-extern void drmMsg(const char *format, ...);
+extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 intel: Fix some format strings

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Some of the format strings for debug messages use the wrong modifier to print sizes.

---
 intel/intel_bufmgr_fake.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
intel/intel_bufmgr_fake.c +10 -10
index d9b5cfdc8952..d63fc815cf9c 100644
@@ -505,7 +505,7 @@ alloc_backing_store(drm_intel_bo *bo)
 
 	bo_fake->backing_store = malloc(bo->size);
 
-	DBG("alloc_backing - buf %d %p %d\n", bo_fake->id,
+	DBG("alloc_backing - buf %d %p %lu\n", bo_fake->id,
 	    bo_fake->backing_store, bo->size);
 	assert(bo_fake->backing_store);
 }
@@ -716,7 +716,7 @@ evict_and_alloc_block(drm_intel_bo *bo)
 		if (alloc_block(bo))
 			return 1;
 
-	DBG("%s 0x%x bytes failed\n", __FUNCTION__, bo->size);
+	DBG("%s 0x%lx bytes failed\n", __FUNCTION__, bo->size);
 
 	return 0;
 }
@@ -835,7 +835,7 @@ drm_intel_fake_bo_alloc(drm_intel_bufmgr *bufmgr,
 	bo_fake->flags = 0;
 	bo_fake->is_static = 0;
 
-	DBG("drm_bo_alloc: (buf %d: %s, %d kb)\n", bo_fake->id, bo_fake->name,
+	DBG("drm_bo_alloc: (buf %d: %s, %lu kb)\n", bo_fake->id, bo_fake->name,
 	    bo_fake->bo.size / 1024);
 
 	return &bo_fake->bo;
@@ -894,7 +894,7 @@ drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr,
 	bo_fake->flags = BM_PINNED;
 	bo_fake->is_static = 1;
 
-	DBG("drm_bo_alloc_static: (buf %d: %s, %d kb)\n", bo_fake->id,
+	DBG("drm_bo_alloc_static: (buf %d: %s, %lu kb)\n", bo_fake->id,
 	    bo_fake->name, bo_fake->bo.size / 1024);
 
 	return &bo_fake->bo;
@@ -1022,7 +1022,7 @@ static int
 		return 0;
 
 	{
-		DBG("drm_bo_map: (buf %d: %s, %d kb)\n", bo_fake->id,
+		DBG("drm_bo_map: (buf %d: %s, %lu kb)\n", bo_fake->id,
 		    bo_fake->name, bo_fake->bo.size / 1024);
 
 		if (bo->virtual != NULL) {
@@ -1100,7 +1100,7 @@ static int
 	if (--bo_fake->map_count != 0)
 		return 0;
 
-	DBG("drm_bo_unmap: (buf %d: %s, %d kb)\n", bo_fake->id, bo_fake->name,
+	DBG("drm_bo_unmap: (buf %d: %s, %lu kb)\n", bo_fake->id, bo_fake->name,
 	    bo_fake->bo.size / 1024);
 
 	bo->virtual = NULL;
@@ -1167,7 +1167,7 @@ static int
 
 	bufmgr_fake = (drm_intel_bufmgr_fake *) bo->bufmgr;
 
-	DBG("drm_bo_validate: (buf %d: %s, %d kb)\n", bo_fake->id,
+	DBG("drm_bo_validate: (buf %d: %s, %lu kb)\n", bo_fake->id,
 	    bo_fake->name, bo_fake->bo.size / 1024);
 
 	/* Sanity check: Buffers should be unmapped before being validated.
@@ -1197,7 +1197,7 @@ static int
 
 	/* Upload the buffer contents if necessary */
 	if (bo_fake->dirty) {
-		DBG("Upload dirty buf %d:%s, sz %d offset 0x%x\n", bo_fake->id,
+		DBG("Upload dirty buf %d:%s, sz %lu offset 0x%x\n", bo_fake->id,
 		    bo_fake->name, bo->size, bo_fake->block->mem->ofs);
 
 		assert(!(bo_fake->flags & (BM_NO_BACKING_STORE | BM_PINNED)));
@@ -1522,12 +1522,12 @@ drm_intel_fake_check_aperture_space(drm_intel_bo ** bo_array, int count)
 	}
 
 	if (sz > bufmgr_fake->size) {
-		DBG("check_space: overflowed bufmgr size, %dkb vs %dkb\n",
+		DBG("check_space: overflowed bufmgr size, %ukb vs %lukb\n",
 		    sz / 1024, bufmgr_fake->size / 1024);
 		return -1;
 	}
 
-	DBG("drm_check_space: sz %dkb vs bufgr %dkb\n", sz / 1024,
+	DBG("drm_check_space: sz %ukb vs bufgr %lukb\n", sz / 1024,
 	    bufmgr_fake->size / 1024);
 	return 0;
 }
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 libdrm: Remove extraneous parameter

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

The debug message's format string doesn't contain any conversion specifiers, therefore making the fd argument unused.

---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +1 -1
index fa5701abae51..e94f2cd00c11 100644
@@ -503,7 +503,7 @@ static int drmOpenByBusid(const char *busid)
 		sv.drm_di_minor = 1;
 		sv.drm_dd_major = -1;       /* Don't care */
 		sv.drm_dd_minor = -1;       /* Don't care */
-		drmMsg("drmOpenByBusid: Interface 1.4 failed, trying 1.1\n",fd);
+		drmMsg("drmOpenByBusid: Interface 1.4 failed, trying 1.1\n");
 		drmSetInterfaceVersion(fd, &sv);
 	    }
 	    buf = drmGetBusid(fd);
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/4 tests: Use drmFreeVersion() instead of drmFree()

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

drmFreeVersion() frees the memory allocated for the name, date and desc fields in addition to that for the struct _drmVersion.

---
 tests/getversion.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/getversion.c +1 -1
index 53d1d354ea16..bcec46999140 100644
@@ -43,7 +43,7 @@ int main(int argc, char **argv)
 	assert(strlen(v->desc) != 0);
 	if (strcmp(v->name, "i915") == 0)
 		assert(v->version_major >= 1);
-	drmFree(v);
+	drmFreeVersion(v);
 	close(fd);
 	return 0;
 }
Signature · 1 line
1.9.1
Reviewed-by on the v1 series
#5 lore raw
In reply to Thierry Reding
Quoted 9 lines · Thierry Reding

From: Thierry Reding <[email protected]>

These four patches clean up some minor issues in libdrm. Patch 1 makes gcc aware of various functions (such as drmMsg(), drm_debug_print(), etc) being printf-like and patches 2 and 3 fix up a number of warnings flagged as a result of that.

Patch 4 uses drmFreeVersion() instead of drmFree() to free a drmVersion structure to prevent memory leaks.

These are:

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 9 lines · Eric Anholt
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

These four patches clean up some minor issues in libdrm. Patch 1 makes gcc aware of various functions (such as drmMsg(), drm_debug_print(), etc) being printf-like and patches 2 and 3 fix up a number of warnings flagged as a result of that.

Quoted 6 lines
Quoted 2 lines

Patch 4 uses drmFreeVersion() instead of drmFree() to free a drmVersion structure to prevent memory leaks.

These are:

Thanks. I don't have the necessary permissions to push this, can somebody else help out here?

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 13 lines · Thierry Reding
Quoted 12 lines · Eric Anholt
Quoted 9 lines · Thierry Reding

From: Thierry Reding <[email protected]>

These four patches clean up some minor issues in libdrm. Patch 1 makes gcc aware of various functions (such as drmMsg(), drm_debug_print(), etc) being printf-like and patches 2 and 3 fix up a number of warnings flagged as a result of that.

Patch 4 uses drmFreeVersion() instead of drmFree() to free a drmVersion structure to prevent memory leaks.

Quoted 6 lines
Quoted 3 lines

These are:

Thanks. I don't have the necessary permissions to push this, can somebody else help out here?

I've given you permissions.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
Quoted 15 lines · Eric Anholt
Quoted 13 lines · Thierry Reding
Quoted 12 lines · Eric Anholt
Quoted 9 lines · Thierry Reding

From: Thierry Reding <[email protected]>

These four patches clean up some minor issues in libdrm. Patch 1 makes gcc aware of various functions (such as drmMsg(), drm_debug_print(), etc) being printf-like and patches 2 and 3 fix up a number of warnings flagged as a result of that.

Patch 4 uses drmFreeVersion() instead of drmFree() to free a drmVersion structure to prevent memory leaks.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

These are:

Thanks. I don't have the necessary permissions to push this, can somebody else help out here?

I've given you permissions.

I think Daniel Stone already gave me permissions as well. Anyway, pushed with your Reviewed-by.

Thanks,
Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel