/* Returns the number of sg lists actually used, zero if the sg lists is NULL, or -ENOMEM if the mapping failed.  */
int scsi_dma_map(struct scsi_cmnd *cmd)
/* Returns the number of sg lists actually used, zero if the sg lists is NULL, or -ENOMEM if the mapping failed.  */
int scsi_dma_map(struct scsi_cmnd *cmd)
{
	int nseg = 0;
	if (scsi_sg_count(cmd)) {
		struct device *dev = cmd->device->host->dma_dev;
		nseg = dma_map_sg(dev, scsi_sglist(cmd), scsi_sg_count(cmd),
				  cmd->sc_data_direction);
		if (unlikely(!nseg))
			return -ENOMEM;
	}
	return nseg;
}