external/gbm_gralloc
Revision | fd87c76a2f0b07308112dc2e286d29238eec38f3 (tree) |
---|---|
Zeit | 2017-09-11 23:59:44 |
Autor | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Rework handle register/unregister calls
What validate_handle() did was ambiguous and broken for binderized
gralloc. Reusing the existing BO pointer for gralloc_gbm_handle_register
is broken because the BO may get freed. It is necessary to always import
the buffer. So split validate handle into separate functions to retrieve
the BO ptr and import the buffer.
Change-Id: I4ea18aa0ded2d201c8f71f4e33a8fc893240d109
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -310,42 +310,24 @@ static int gralloc_gbm_get_pid(void) | ||
310 | 310 | } |
311 | 311 | |
312 | 312 | /* |
313 | - * Validate a buffer handle and return the associated bo. | |
313 | + * Register a buffer handle. | |
314 | 314 | */ |
315 | -static struct gralloc_gbm_bo_t *validate_handle(buffer_handle_t _handle, | |
316 | - struct gbm_device *gbm) | |
315 | +int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | |
317 | 316 | { |
318 | 317 | struct gralloc_gbm_bo_t *bo; |
319 | 318 | struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle); |
320 | 319 | |
321 | 320 | if (!handle) |
322 | - return NULL; | |
323 | - | |
324 | - /* the buffer handle is passed to a new process */ | |
325 | - //ALOGE("data_owner=%d gralloc_pid=%d data=%p\n", handle->data_owner, gralloc_gbm_get_pid(), handle->data); | |
326 | - if (handle->data_owner == gralloc_gbm_get_pid()) | |
327 | - return (struct gralloc_gbm_bo_t *)handle->data; | |
328 | - | |
329 | - /* check only */ | |
330 | - if (!gbm) | |
331 | - return NULL; | |
332 | - | |
333 | - ALOGV("handle: pfd=%d\n", handle->prime_fd); | |
321 | + return -EINVAL; | |
334 | 322 | |
335 | 323 | bo = gbm_import(gbm, handle); |
324 | + if (!bo) | |
325 | + return -EINVAL; | |
336 | 326 | |
337 | 327 | handle->data_owner = gralloc_gbm_get_pid(); |
338 | 328 | handle->data = bo; |
339 | 329 | |
340 | - return bo; | |
341 | -} | |
342 | - | |
343 | -/* | |
344 | - * Register a buffer handle. | |
345 | - */ | |
346 | -int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm) | |
347 | -{ | |
348 | - return (validate_handle(handle, gbm)) ? 0 : -EINVAL; | |
330 | + return 0; | |
349 | 331 | } |
350 | 332 | |
351 | 333 | /* |
@@ -354,15 +336,14 @@ int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm) | ||
354 | 336 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
355 | 337 | { |
356 | 338 | struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); |
357 | - struct gralloc_gbm_bo_t *bo; | |
339 | + struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle); | |
358 | 340 | |
359 | - bo = validate_handle(handle, NULL); | |
360 | 341 | if (!bo) |
361 | 342 | return -EINVAL; |
362 | 343 | |
363 | 344 | gbm_free(bo); |
364 | 345 | gbm_handle->data_owner = 0; |
365 | - gbm_handle->data = 0; | |
346 | + gbm_handle->data = NULL; | |
366 | 347 | |
367 | 348 | return 0; |
368 | 349 | } |