提交 20b65dd0 编写于 作者: C Clemens Ladisch

ALSA: firewire: introduce amdtp_out_stream_running()

Introduce the helper function amdtp_out_stream_running().  This makes
many checks in amdtp.c clearer and frees the device drivers from having
to track this with a separate variable.
Signed-off-by: NClemens Ladisch <clemens@ladisch.de>
上级 9dd81e31
...@@ -59,7 +59,7 @@ EXPORT_SYMBOL(amdtp_out_stream_init); ...@@ -59,7 +59,7 @@ EXPORT_SYMBOL(amdtp_out_stream_init);
*/ */
void amdtp_out_stream_destroy(struct amdtp_out_stream *s) void amdtp_out_stream_destroy(struct amdtp_out_stream *s)
{ {
WARN_ON(!IS_ERR(s->context)); WARN_ON(amdtp_out_stream_running(s));
mutex_destroy(&s->mutex); mutex_destroy(&s->mutex);
fw_unit_put(s->unit); fw_unit_put(s->unit);
} }
...@@ -89,7 +89,7 @@ void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate) ...@@ -89,7 +89,7 @@ void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate)
}; };
unsigned int sfc; unsigned int sfc;
if (WARN_ON(!IS_ERR(s->context))) if (WARN_ON(amdtp_out_stream_running(s)))
return; return;
for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc) for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc)
...@@ -145,7 +145,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s, ...@@ -145,7 +145,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s,
void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
snd_pcm_format_t format) snd_pcm_format_t format)
{ {
if (WARN_ON(!IS_ERR(s->context))) if (WARN_ON(amdtp_out_stream_running(s)))
return; return;
switch (format) { switch (format) {
...@@ -481,7 +481,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed) ...@@ -481,7 +481,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
mutex_lock(&s->mutex); mutex_lock(&s->mutex);
if (WARN_ON(!IS_ERR(s->context) || if (WARN_ON(amdtp_out_stream_running(s) ||
(!s->pcm_channels && !s->midi_ports))) { (!s->pcm_channels && !s->midi_ports))) {
err = -EBADFD; err = -EBADFD;
goto err_unlock; goto err_unlock;
...@@ -577,7 +577,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s) ...@@ -577,7 +577,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
{ {
mutex_lock(&s->mutex); mutex_lock(&s->mutex);
if (IS_ERR(s->context)) { if (!amdtp_out_stream_running(s)) {
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
return; return;
} }
......
#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
#define SOUND_FIREWIRE_AMDTP_H_INCLUDED #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
#include <linux/err.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include "packets-buffer.h" #include "packets-buffer.h"
...@@ -92,6 +93,11 @@ void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s); ...@@ -92,6 +93,11 @@ void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
{
return !IS_ERR(s->context);
}
/** /**
* amdtp_out_stream_set_pcm - configure format of PCM samples * amdtp_out_stream_set_pcm - configure format of PCM samples
* @s: the AMDTP output stream to be configured * @s: the AMDTP output stream to be configured
......
...@@ -246,7 +246,6 @@ struct dice { ...@@ -246,7 +246,6 @@ struct dice {
int dev_lock_count; /* > 0 driver, < 0 userspace */ int dev_lock_count; /* > 0 driver, < 0 userspace */
bool dev_lock_changed; bool dev_lock_changed;
bool global_enabled; bool global_enabled;
bool stream_running;
wait_queue_head_t hwdep_wait; wait_queue_head_t hwdep_wait;
u32 notification_bits; u32 notification_bits;
struct snd_pcm_substream *pcm; struct snd_pcm_substream *pcm;
...@@ -654,7 +653,7 @@ static int dice_stream_start_packets(struct dice *dice) ...@@ -654,7 +653,7 @@ static int dice_stream_start_packets(struct dice *dice)
{ {
int err; int err;
if (dice->stream_running) if (amdtp_out_stream_running(&dice->stream))
return 0; return 0;
err = amdtp_out_stream_start(&dice->stream, dice->resources.channel, err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,
...@@ -668,8 +667,6 @@ static int dice_stream_start_packets(struct dice *dice) ...@@ -668,8 +667,6 @@ static int dice_stream_start_packets(struct dice *dice)
return err; return err;
} }
dice->stream_running = true;
return 0; return 0;
} }
...@@ -712,14 +709,10 @@ static int dice_stream_start(struct dice *dice) ...@@ -712,14 +709,10 @@ static int dice_stream_start(struct dice *dice)
static void dice_stream_stop_packets(struct dice *dice) static void dice_stream_stop_packets(struct dice *dice)
{ {
if (!dice->stream_running) if (amdtp_out_stream_running(&dice->stream)) {
return; dice_enable_clear(dice);
amdtp_out_stream_stop(&dice->stream);
dice_enable_clear(dice); }
amdtp_out_stream_stop(&dice->stream);
dice->stream_running = false;
} }
static void dice_stream_stop(struct dice *dice) static void dice_stream_stop(struct dice *dice)
......
...@@ -53,7 +53,6 @@ struct fwspk { ...@@ -53,7 +53,6 @@ struct fwspk {
struct mutex mutex; struct mutex mutex;
struct cmp_connection connection; struct cmp_connection connection;
struct amdtp_out_stream stream; struct amdtp_out_stream stream;
bool stream_running;
bool mute; bool mute;
s16 volume[6]; s16 volume[6];
s16 volume_min; s16 volume_min;
...@@ -189,10 +188,9 @@ static int fwspk_close(struct snd_pcm_substream *substream) ...@@ -189,10 +188,9 @@ static int fwspk_close(struct snd_pcm_substream *substream)
static void fwspk_stop_stream(struct fwspk *fwspk) static void fwspk_stop_stream(struct fwspk *fwspk)
{ {
if (fwspk->stream_running) { if (amdtp_out_stream_running(&fwspk->stream)) {
amdtp_out_stream_stop(&fwspk->stream); amdtp_out_stream_stop(&fwspk->stream);
cmp_connection_break(&fwspk->connection); cmp_connection_break(&fwspk->connection);
fwspk->stream_running = false;
} }
} }
...@@ -286,7 +284,7 @@ static int fwspk_prepare(struct snd_pcm_substream *substream) ...@@ -286,7 +284,7 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
if (amdtp_out_streaming_error(&fwspk->stream)) if (amdtp_out_streaming_error(&fwspk->stream))
fwspk_stop_stream(fwspk); fwspk_stop_stream(fwspk);
if (!fwspk->stream_running) { if (!amdtp_out_stream_running(&fwspk->stream)) {
err = cmp_connection_establish(&fwspk->connection, err = cmp_connection_establish(&fwspk->connection,
amdtp_out_stream_get_max_payload(&fwspk->stream)); amdtp_out_stream_get_max_payload(&fwspk->stream));
if (err < 0) if (err < 0)
...@@ -297,8 +295,6 @@ static int fwspk_prepare(struct snd_pcm_substream *substream) ...@@ -297,8 +295,6 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
fwspk->connection.speed); fwspk->connection.speed);
if (err < 0) if (err < 0)
goto err_connection; goto err_connection;
fwspk->stream_running = true;
} }
mutex_unlock(&fwspk->mutex); mutex_unlock(&fwspk->mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册