[Openchrome-devel] Fix for bug introduced with changeset 1051

James Simmons jsimmons
Mon Dec 12 07:06:43 PST 2011


> Dear James,
> 
> I've been testing your latest openchrome changes (thanks again for your 
> ongoing work!) and found a bug introduced with changeset 1051. The problem is 
> that drm_bo_alloc() will not correctly allocate memory for the domains 
> TTM_PL_VRAM and TTM_PL_TT when directRenderingType is != DRI_1.

The ifdef is also incorrect.
 
> There is also an older bug that makes drm_bo_alloc() return the pointer to a 
> freed buffer_object in case viaOffScreenLinear() also was unsuccessful. Instead 
> NULL should be returned.

That and also I discovered this weekend that the object ptr was not being 
set.

> A third, minor, problem is following format string:
>  DEBUG(ErrorF("%u of DRI memory allocated at %llx\n", obj->size, obj->offset));
> 
> Both fields ("size" and "offset") are unsigned long values, so the format 
> strings should be "%lu" and "%lx".
> 
> All these bugs/problems are fixed with the attached patch.

Since you posted the patch some more changes have happened. How about the 
below patch. Haven't test it yet.

Index: via_memmgr.c
===================================================================
--- via_memmgr.c	(revision 1058)
+++ via_memmgr.c	(working copy)
@@ -99,7 +99,6 @@
 {
     struct buffer_object *obj = NULL;
     VIAPtr pVia = VIAPTR(pScrn);
-    int ret;
 
     obj = xnfcalloc(1, sizeof(*obj));
     if (obj) {
@@ -109,30 +108,24 @@
 #ifdef XF86DRI
             if (pVia->directRenderingType == DRI_1) {
                 drm_via_mem_t drm;
+                int ret;
 
                 drm.context = DRIGetContext(pScrn->pScreen);
                 drm.size = size;
                 drm.type = (domain == TTM_PL_TT ? VIA_MEM_AGP : VIA_MEM_VIDEO);
                 ret = drmCommandWriteRead(pVia->drmFD, DRM_VIA_ALLOCMEM,
                                             &drm, sizeof(drm_via_mem_t));
-                if (ret || (size != drm.size)) {
+                if (!ret && (size == drm.size)) {
+                    obj->offset = drm.offset;
+                    obj->handle = drm.index;
+                    obj->domain = domain;
+                    obj->size = drm.size;
+                    DEBUG(ErrorF("%lu of DRI memory allocated at %lx, handle %lu\n",
+                                obj->size, obj->offset, obj->handle));
+                    break;
+                } else
                     DEBUG(ErrorF("DRM memory allocation failed %d\n", ret));
-                    /* Try X Offsceen fallback before failing. */
-                    if (Success != viaOffScreenLinear(obj, pScrn, size)) {
-                        ErrorF("Linear memory allocation failed\n");
-                        free(obj);
-                    }
-                    return NULL;
-                }
-                obj->offset = drm.offset;
-                obj->handle = drm.index;
-                obj->domain = domain;
-                obj->size = drm.size;
-                DEBUG(ErrorF("%u of DRI memory allocated at %llx, handle %lld\n",
-                            obj->size, obj->offset, obj->handle));
-                return obj;
             }
-            break;
 #endif
         case TTM_PL_SYSTEM:
         default:




More information about the Openchrome-devel mailing list