mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	pcm: Clean up error paths in snd_pcm_plugin_*() helpers
Minor code refactoring to unify the error return paths. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
		
							parent
							
								
									7c424edd11
								
							
						
					
					
						commit
						503a285ed6
					
				
					 1 changed files with 45 additions and 22 deletions
				
			
		| 
						 | 
					@ -276,7 +276,8 @@ static snd_pcm_sframes_t snd_pcm_plugin_write_areas(snd_pcm_t *pcm,
 | 
				
			||||||
		if (CHECK_SANITY(slave_frames > snd_pcm_mmap_playback_avail(slave))) {
 | 
							if (CHECK_SANITY(slave_frames > snd_pcm_mmap_playback_avail(slave))) {
 | 
				
			||||||
			SNDMSG("write overflow %ld > %ld", slave_frames,
 | 
								SNDMSG("write overflow %ld > %ld", slave_frames,
 | 
				
			||||||
			       snd_pcm_mmap_playback_avail(slave));
 | 
								       snd_pcm_mmap_playback_avail(slave));
 | 
				
			||||||
			return -EPIPE;
 | 
								err = -EPIPE;
 | 
				
			||||||
 | 
								goto error;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		snd_atomic_write_begin(&plugin->watom);
 | 
							snd_atomic_write_begin(&plugin->watom);
 | 
				
			||||||
		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 | 
							result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 | 
				
			||||||
| 
						 | 
					@ -284,14 +285,14 @@ static snd_pcm_sframes_t snd_pcm_plugin_write_areas(snd_pcm_t *pcm,
 | 
				
			||||||
			snd_pcm_sframes_t res;
 | 
								snd_pcm_sframes_t res;
 | 
				
			||||||
			res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
 | 
								res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
 | 
				
			||||||
			if (res < 0) {
 | 
								if (res < 0) {
 | 
				
			||||||
				snd_atomic_write_end(&plugin->watom);
 | 
									err = res;
 | 
				
			||||||
				return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
 | 
									goto error_atomic;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			frames -= res;
 | 
								frames -= res;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (result <= 0) {
 | 
							if (result <= 0) {
 | 
				
			||||||
			snd_atomic_write_end(&plugin->watom);
 | 
								err = result;
 | 
				
			||||||
			return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
 | 
								goto error_atomic;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		snd_pcm_mmap_appl_forward(pcm, frames);
 | 
							snd_pcm_mmap_appl_forward(pcm, frames);
 | 
				
			||||||
		snd_atomic_write_end(&plugin->watom);
 | 
							snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
| 
						 | 
					@ -300,6 +301,11 @@ static snd_pcm_sframes_t snd_pcm_plugin_write_areas(snd_pcm_t *pcm,
 | 
				
			||||||
		size -= frames;
 | 
							size -= frames;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return (snd_pcm_sframes_t)xfer;
 | 
						return (snd_pcm_sframes_t)xfer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 error_atomic:
 | 
				
			||||||
 | 
						snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
 | 
					 error:
 | 
				
			||||||
 | 
						return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
					static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
				
			||||||
| 
						 | 
					@ -311,6 +317,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
				
			||||||
	snd_pcm_t *slave = plugin->gen.slave;
 | 
						snd_pcm_t *slave = plugin->gen.slave;
 | 
				
			||||||
	snd_pcm_uframes_t xfer = 0;
 | 
						snd_pcm_uframes_t xfer = 0;
 | 
				
			||||||
	snd_pcm_sframes_t result;
 | 
						snd_pcm_sframes_t result;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	while (size > 0) {
 | 
						while (size > 0) {
 | 
				
			||||||
		snd_pcm_uframes_t frames = size;
 | 
							snd_pcm_uframes_t frames = size;
 | 
				
			||||||
| 
						 | 
					@ -326,7 +333,8 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
				
			||||||
		if (CHECK_SANITY(slave_frames > snd_pcm_mmap_capture_avail(slave))) {
 | 
							if (CHECK_SANITY(slave_frames > snd_pcm_mmap_capture_avail(slave))) {
 | 
				
			||||||
			SNDMSG("read overflow %ld > %ld", slave_frames,
 | 
								SNDMSG("read overflow %ld > %ld", slave_frames,
 | 
				
			||||||
			       snd_pcm_mmap_playback_avail(slave));
 | 
								       snd_pcm_mmap_playback_avail(slave));
 | 
				
			||||||
			return -EPIPE;
 | 
								err = -EPIPE;
 | 
				
			||||||
 | 
								goto error;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		snd_atomic_write_begin(&plugin->watom);
 | 
							snd_atomic_write_begin(&plugin->watom);
 | 
				
			||||||
		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 | 
							result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 | 
				
			||||||
| 
						 | 
					@ -335,14 +343,14 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			res = plugin->undo_read(slave, areas, offset, frames, slave_frames - result);
 | 
								res = plugin->undo_read(slave, areas, offset, frames, slave_frames - result);
 | 
				
			||||||
			if (res < 0) {
 | 
								if (res < 0) {
 | 
				
			||||||
				snd_atomic_write_end(&plugin->watom);
 | 
									err = res;
 | 
				
			||||||
				return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
 | 
									goto error_atomic;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			frames -= res;
 | 
								frames -= res;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (result <= 0) {
 | 
							if (result <= 0) {
 | 
				
			||||||
			snd_atomic_write_end(&plugin->watom);
 | 
								err = result;
 | 
				
			||||||
			return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
 | 
								goto error_atomic;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		snd_pcm_mmap_appl_forward(pcm, frames);
 | 
							snd_pcm_mmap_appl_forward(pcm, frames);
 | 
				
			||||||
		snd_atomic_write_end(&plugin->watom);
 | 
							snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
| 
						 | 
					@ -351,6 +359,11 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 | 
				
			||||||
		size -= frames;
 | 
							size -= frames;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return (snd_pcm_sframes_t)xfer;
 | 
						return (snd_pcm_sframes_t)xfer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 error_atomic:
 | 
				
			||||||
 | 
						snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
 | 
					 error:
 | 
				
			||||||
 | 
						return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -401,6 +414,7 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
 | 
				
			||||||
	snd_pcm_uframes_t appl_offset;
 | 
						snd_pcm_uframes_t appl_offset;
 | 
				
			||||||
	snd_pcm_sframes_t slave_size;
 | 
						snd_pcm_sframes_t slave_size;
 | 
				
			||||||
	snd_pcm_sframes_t xfer;
 | 
						snd_pcm_sframes_t xfer;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
 | 
						if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
 | 
				
			||||||
		snd_atomic_write_begin(&plugin->watom);
 | 
							snd_atomic_write_begin(&plugin->watom);
 | 
				
			||||||
| 
						 | 
					@ -421,11 +435,10 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
 | 
				
			||||||
		snd_pcm_uframes_t slave_offset;
 | 
							snd_pcm_uframes_t slave_offset;
 | 
				
			||||||
		snd_pcm_uframes_t slave_frames = ULONG_MAX;
 | 
							snd_pcm_uframes_t slave_frames = ULONG_MAX;
 | 
				
			||||||
		snd_pcm_sframes_t result;
 | 
							snd_pcm_sframes_t result;
 | 
				
			||||||
		int err;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 | 
							err = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			return xfer > 0 ? xfer : err;
 | 
								goto error;
 | 
				
			||||||
		if (frames > cont)
 | 
							if (frames > cont)
 | 
				
			||||||
			frames = cont;
 | 
								frames = cont;
 | 
				
			||||||
		frames = plugin->write(pcm, areas, appl_offset, frames,
 | 
							frames = plugin->write(pcm, areas, appl_offset, frames,
 | 
				
			||||||
| 
						 | 
					@ -437,14 +450,14 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
 | 
								res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
 | 
				
			||||||
			if (res < 0) {
 | 
								if (res < 0) {
 | 
				
			||||||
				snd_atomic_write_end(&plugin->watom);
 | 
									err = res;
 | 
				
			||||||
				return xfer > 0 ? xfer : res;
 | 
									goto error_atomic;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			frames -= res;
 | 
								frames -= res;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (result <= 0) {
 | 
							if (result <= 0) {
 | 
				
			||||||
			snd_atomic_write_end(&plugin->watom);
 | 
								err = result;
 | 
				
			||||||
			return xfer > 0 ? xfer : result;
 | 
								goto error_atomic;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		snd_pcm_mmap_appl_forward(pcm, frames);
 | 
							snd_pcm_mmap_appl_forward(pcm, frames);
 | 
				
			||||||
		snd_atomic_write_end(&plugin->watom);
 | 
							snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
| 
						 | 
					@ -461,6 +474,11 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
 | 
				
			||||||
		return -EPIPE;
 | 
							return -EPIPE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return xfer;
 | 
						return xfer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 error_atomic:
 | 
				
			||||||
 | 
						snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
 | 
					 error:
 | 
				
			||||||
 | 
						return xfer > 0 ? xfer : err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
					static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
| 
						 | 
					@ -468,6 +486,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
	snd_pcm_plugin_t *plugin = pcm->private_data;
 | 
						snd_pcm_plugin_t *plugin = pcm->private_data;
 | 
				
			||||||
	snd_pcm_t *slave = plugin->gen.slave;
 | 
						snd_pcm_t *slave = plugin->gen.slave;
 | 
				
			||||||
	snd_pcm_sframes_t slave_size;
 | 
						snd_pcm_sframes_t slave_size;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	slave_size = snd_pcm_avail_update(slave);
 | 
						slave_size = snd_pcm_avail_update(slave);
 | 
				
			||||||
	if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
 | 
						if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
 | 
				
			||||||
| 
						 | 
					@ -492,11 +511,10 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
			snd_pcm_uframes_t slave_offset;
 | 
								snd_pcm_uframes_t slave_offset;
 | 
				
			||||||
			snd_pcm_uframes_t slave_frames = ULONG_MAX;
 | 
								snd_pcm_uframes_t slave_frames = ULONG_MAX;
 | 
				
			||||||
			snd_pcm_sframes_t result;
 | 
								snd_pcm_sframes_t result;
 | 
				
			||||||
			int err;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			err = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 | 
								err = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
 | 
				
			||||||
			if (err < 0)
 | 
								if (err < 0)
 | 
				
			||||||
				return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 | 
									goto error;
 | 
				
			||||||
			if (frames > cont)
 | 
								if (frames > cont)
 | 
				
			||||||
				frames = cont;
 | 
									frames = cont;
 | 
				
			||||||
			frames = (plugin->read)(pcm, areas, hw_offset, frames,
 | 
								frames = (plugin->read)(pcm, areas, hw_offset, frames,
 | 
				
			||||||
| 
						 | 
					@ -508,14 +526,14 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
 | 
									res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
 | 
				
			||||||
				if (res < 0) {
 | 
									if (res < 0) {
 | 
				
			||||||
					snd_atomic_write_end(&plugin->watom);
 | 
										err = res;
 | 
				
			||||||
					return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
 | 
										goto error_atomic;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				frames -= res;
 | 
									frames -= res;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (result <= 0) {
 | 
								if (result <= 0) {
 | 
				
			||||||
				snd_atomic_write_end(&plugin->watom);
 | 
									err = result;
 | 
				
			||||||
				return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
 | 
									goto error_atomic;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			snd_pcm_mmap_hw_forward(pcm, frames);
 | 
								snd_pcm_mmap_hw_forward(pcm, frames);
 | 
				
			||||||
			snd_atomic_write_end(&plugin->watom);
 | 
								snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
| 
						 | 
					@ -528,6 +546,11 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
			xfer += frames;
 | 
								xfer += frames;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return (snd_pcm_sframes_t)xfer;
 | 
							return (snd_pcm_sframes_t)xfer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						error_atomic:
 | 
				
			||||||
 | 
							snd_atomic_write_end(&plugin->watom);
 | 
				
			||||||
 | 
						error:
 | 
				
			||||||
 | 
							return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue