dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); 
if (qc->n_elem) dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); 
static void ata_sg_clean(struct ata_queued_cmd *qc){	struct ata_port *ap = qc->ap;	struct scatterlist *sg = qc->__sg;	int dir = qc->dma_dir;	void *pad_buf = NULL;	assert(qc->flags & ATA_QCFLAG_DMAMAP);	assert(sg != NULL);	if (qc->flags & ATA_QCFLAG_SINGLE)		assert(qc->n_elem == 1);	DPRINTK("unmapping %u sg elements\n", qc->n_elem);	/* if we padded the buffer out to 32-bit bound, and data	 * xfer direction is from-device, we must copy from the	 * pad buffer back into the supplied buffer	 */	if (qc->pad_len && !(qc->tf.flags & ATA_TFLAG_WRITE))		pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);	if (qc->flags & ATA_QCFLAG_SG) {		dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir);		/* restore last sg */		sg[qc->orig_n_elem - 1].length += qc->pad_len;		if (pad_buf) {			struct scatterlist *psg = &qc->pad_sgent;			void *addr = kmap_atomic(psg->page, KM_IRQ0);			memcpy(addr + psg->offset, pad_buf, qc->pad_len);			kunmap_atomic(psg->page, KM_IRQ0);		}	} else {		dma_unmap_single(ap->host_set->dev, sg_dma_address(&sg[0]),				 sg_dma_len(&sg[0]), dir);		/* restore sg */		sg->length += qc->pad_len;		if (pad_buf)			memcpy(qc->buf_virt + sg->length - qc->pad_len,			       pad_buf, qc->pad_len);	}	qc->flags &= ~ATA_QCFLAG_DMAMAP;	qc->__sg = NULL;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/e1410f2d951d45aee3bdbcc05ecedaaa9db276e5/libata-core.c/buggy/drivers/scsi/libata-core.c