DRM_DEBUG("takedown completed\n"); 
int drm_takedown( drm_device_t *dev ){	drm_magic_entry_t *pt, *next;	drm_map_t *map;	drm_map_list_t *r_list;	struct list_head *list, *list_next;	drm_vma_entry_t *vma, *vma_next;	int i;	DRM_DEBUG( "\n" );	if (dev->driver->pretakedown)	  dev->driver->pretakedown(dev);	if (dev->unique) {		drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);		dev->unique = NULL;		dev->unique_len = 0;	}	if ( dev->irq_enabled ) drm_irq_uninstall( dev );	down( &dev->struct_sem );	del_timer( &dev->timer );				/* Clear pid list */	for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {		for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {			next = pt->next;			drm_free( pt, sizeof(*pt), DRM_MEM_MAGIC );		}		dev->magiclist[i].head = dev->magiclist[i].tail = NULL;	}				/* Clear AGP information */	if (drm_core_has_AGP(dev) && dev->agp) {		drm_agp_mem_t *entry;		drm_agp_mem_t *nexte;				/* Remove AGP resources, but leave dev->agp                                   intact until drv_cleanup is called. */		for ( entry = dev->agp->memory ; entry ; entry = nexte ) {			nexte = entry->next;			if ( entry->bound ) drm_unbind_agp( entry->memory );			drm_free_agp( entry->memory, entry->pages );			drm_free( entry, sizeof(*entry), DRM_MEM_AGPLISTS );		}		dev->agp->memory = NULL;		if (dev->agp->acquired)		  drm_agp_release(dev);		dev->agp->acquired = 0;		dev->agp->enabled  = 0;	}				/* Clear vma list (only built for debugging) */	if ( dev->vmalist ) {		for ( vma = dev->vmalist ; vma ; vma = vma_next ) {			vma_next = vma->next;			drm_free( vma, sizeof(*vma), DRM_MEM_VMAS );		}		dev->vmalist = NULL;	}	if( dev->maplist ) {		list_for_each_safe( list, list_next, &dev->maplist->head ) {			r_list = (drm_map_list_t *)list;			if ( ( map = r_list->map ) ) {				drm_dma_handle_t dmah;				switch ( map->type ) {				case _DRM_REGISTERS:				case _DRM_FRAME_BUFFER:					if (drm_core_has_MTRR(dev)) {						if ( map->mtrr >= 0 ) {							int retcode;							retcode = mtrr_del( map->mtrr,									    map->offset,									    map->size );							DRM_DEBUG( "mtrr_del=%d\n", retcode );						}					}					drm_ioremapfree( map->handle, map->size, dev );					break;				case _DRM_SHM:					vfree(map->handle);					break;				case _DRM_AGP:					/* Do nothing here, because this is all					 * handled in the AGP/GART driver.					 */					break;				case _DRM_SCATTER_GATHER:					/* Handle it */					if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {						drm_sg_cleanup(dev->sg);						dev->sg = NULL;					}					break;				case _DRM_CONSISTENT:					dmah.vaddr = map->handle;					dmah.busaddr = map->offset;					dmah.size = map->size;					__drm_pci_free(dev, &dmah);					break;				}				drm_free(map, sizeof(*map), DRM_MEM_MAPS);			}			list_del( list );			drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS); 		}		drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);		dev->maplist = NULL; 	}	if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist ) {		for ( i = 0 ; i < dev->queue_count ; i++ ) {			if ( dev->queuelist[i] ) {				drm_free( dev->queuelist[i],					  sizeof(*dev->queuelist[0]),					  DRM_MEM_QUEUES );				dev->queuelist[i] = NULL;			}		}		drm_free( dev->queuelist,			  dev->queue_slots * sizeof(*dev->queuelist),			  DRM_MEM_QUEUES );		dev->queuelist = NULL;	}	dev->queue_count = 0;	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))		drm_dma_takedown( dev );	if ( dev->lock.hw_lock ) {		dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */		dev->lock.filp = NULL;		wake_up_interruptible( &dev->lock.lock_queue );	}	up( &dev->struct_sem );	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/836cf0465c422ee6d654060edd7c620d9cf0c09c/drm_drv.c/buggy/drivers/char/drm/drm_drv.c