accelerants/radeon: Fix potential memory leak

* Fix potential leak of 'node' at line 147, which is allocated
  at line 123. Pointed out by Clang Static Analyzer.
* Remove trailing tabs.

Change-Id: I2289dfb5a9d0ada1fd7fc3854906d66a730b5bcb
Reviewed-on: https://review.haiku-os.org/c/1058
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Murai Takashi 2019-02-14 06:37:15 +09:00 committed by waddlesplash
parent 4512141632
commit b7223dc11f

View File

@ -1,9 +1,9 @@
/*
Copyright (c) 2002, Thomas Kurschel
Part of Radeon accelerant
Overlay interface
*/
@ -31,7 +31,7 @@ uint32 OVERLAY_COUNT( const display_mode *dm )
SHOW_FLOW0( 3, "" );
(void) dm;
return 1;
}
@ -41,7 +41,7 @@ uint32 OVERLAY_COUNT( const display_mode *dm )
const uint32 *OVERLAY_SUPPORTED_SPACES( const display_mode *dm )
{
SHOW_FLOW0( 3, "" );
(void) dm;
return overlay_colorspaces;
@ -53,7 +53,7 @@ const uint32 *OVERLAY_SUPPORTED_SPACES( const display_mode *dm )
uint32 OVERLAY_SUPPORTED_FEATURES( uint32 color_space )
{
SHOW_FLOW0( 3, "" );
(void) color_space;
return
@ -75,7 +75,7 @@ const overlay_buffer *ALLOCATE_OVERLAY_BUFFER( color_space cs, uint16 width, uin
overlay_buffer *buffer;
status_t result;
uint ati_space, test_reg, bpp;
SHOW_FLOW0( 3, "" );
switch( cs ) {
@ -119,11 +119,11 @@ const overlay_buffer *ALLOCATE_OVERLAY_BUFFER( color_space cs, uint16 width, uin
SHOW_FLOW( 3, "Unsupported format (%x)", (int)cs );
return NULL;
}
node = malloc( sizeof( overlay_buffer_node ));
if( node == NULL )
return NULL;
node->ati_space = ati_space;
node->test_reg = test_reg;
@ -131,42 +131,43 @@ const overlay_buffer *ALLOCATE_OVERLAY_BUFFER( color_space cs, uint16 width, uin
// alloc graphics mem
buffer = &node->buffer;
buffer->space = cs;
buffer->width = width;
buffer->height = height;
buffer->bytes_per_row = (width * bpp + 0xf) & ~0xf;
am.magic = RADEON_PRIVATE_DATA_MAGIC;
am.size = buffer->bytes_per_row * height;
am.memory_type = mt_local;
am.global = false;
result = ioctl( ai->fd, RADEON_ALLOC_MEM, &am );
if( result != B_OK )
goto err;
node->mem_handle = am.handle;
node->mem_offset = am.offset;
buffer->buffer = si->local_mem + am.offset;
buffer->buffer_dma = (void *) ((unsigned long) si->framebuffer_pci + am.offset);
// add to list of overlays
node->next = vc->overlay_buffers;
node->prev = NULL;
if( node->next )
node->next->prev = node;
vc->overlay_buffers = node;
RELEASE_BEN( si->engine.lock );
SHOW_FLOW( 0, "success: mem_handle=%x, offset=%x, CPU-address=%x, phys-address=%x",
node->mem_handle, node->mem_offset, buffer->buffer, buffer->buffer_dma );
return buffer;
err:
free(node);
RELEASE_BEN( si->engine.lock );
return NULL;
}
@ -180,20 +181,20 @@ status_t RELEASE_OVERLAY_BUFFER( const overlay_buffer *ob )
overlay_buffer_node *node;
radeon_free_mem fm;
status_t result;
SHOW_FLOW0( 3, "" );
node = (overlay_buffer_node *)((char *)ob - offsetof( overlay_buffer_node, buffer ));
if( si->active_overlay.on == node || si->active_overlay.prev_on )
Radeon_HideOverlay( ai );
// free memory
// free memory
fm.magic = RADEON_PRIVATE_DATA_MAGIC;
fm.handle = node->mem_handle;
fm.memory_type = mt_local;
fm.global = false;
result = ioctl( ai->fd, RADEON_FREE_MEM, &fm );
if( result != B_OK ) {
SHOW_FLOW( 3, "ups - couldn't free memory (handle=%x, status=%s)",
@ -205,16 +206,16 @@ status_t RELEASE_OVERLAY_BUFFER( const overlay_buffer *ob )
// remove from list
if( node->next )
node->next->prev = node->prev;
if( node->prev )
node->prev->next = node->next;
else
vc->overlay_buffers = node->next;
RELEASE_BEN( si->engine.lock );
RELEASE_BEN( si->engine.lock );
SHOW_FLOW0( 3, "success" );
return B_OK;
}
@ -229,11 +230,11 @@ status_t GET_OVERLAY_CONSTRAINTS( const display_mode *dm, const overlay_buffer *
// which should know what it's doing
if( dm == NULL || ob == NULL || oc == NULL )
return B_BAD_VALUE;
// scaler input restrictions
// TBD: check all these values; I reckon that
// most of them are too restrictive
// position
oc->view.h_alignment = 0;
oc->view.v_alignment = 0;
@ -281,7 +282,7 @@ status_t GET_OVERLAY_CONSTRAINTS( const display_mode *dm, const overlay_buffer *
oc->h_scale.max = 1 << 12;
oc->v_scale.min = 1.0f / (1 << 4);
oc->v_scale.max = 1 << 12;
SHOW_FLOW0( 3, "success" );
return B_OK;
@ -293,16 +294,16 @@ overlay_token ALLOCATE_OVERLAY( void )
{
shared_info *si = ai->si;
virtual_card *vc = ai->vc;
SHOW_FLOW0( 3, "" );
if( atomic_or( &si->overlay_mgr.inuse, 1 ) != 0 ) {
SHOW_FLOW0( 3, "already in use" );
return NULL;
}
SHOW_FLOW0( 3, "success" );
vc->uses_overlay = true;
return (void *)++si->overlay_mgr.token;
@ -314,21 +315,21 @@ status_t RELEASE_OVERLAY(overlay_token ot)
{
virtual_card *vc = ai->vc;
shared_info *si = ai->si;
SHOW_FLOW0( 3, "" );
if( (void *)si->overlay_mgr.token != ot )
return B_BAD_VALUE;
if( si->overlay_mgr.inuse == 0 )
return B_ERROR;
if( si->active_overlay.on )
Radeon_HideOverlay( ai );
si->overlay_mgr.inuse = 0;
vc->uses_overlay = false;
SHOW_FLOW0( 3, "released" );
return B_OK;
@ -368,10 +369,10 @@ status_t CONFIGURE_OVERLAY( overlay_token ot, const overlay_buffer *ob,
si->pending_overlay.ov = *ov;
si->pending_overlay.on = (overlay_buffer_node *)((char *)ob - offsetof( overlay_buffer_node, buffer ));
result = Radeon_UpdateOverlay( ai );
RELEASE_BEN( si->engine.lock );
return result;
}