mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
ALSA: ca0106: Use guard() for spin locks
Clean up the code using guard() for spin locks. Merely code refactoring, and no behavior change. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250829144342.4290-16-tiwai@suse.de
This commit is contained in:
@@ -332,16 +332,13 @@ unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
|
||||
unsigned int reg,
|
||||
unsigned int chn)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned int regptr, val;
|
||||
unsigned int regptr;
|
||||
|
||||
regptr = (reg << 16) | chn;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
outl(regptr, emu->port + CA0106_PTR);
|
||||
val = inl(emu->port + CA0106_DATA);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
return val;
|
||||
return inl(emu->port + CA0106_DATA);
|
||||
}
|
||||
|
||||
void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
|
||||
@@ -350,14 +347,12 @@ void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
|
||||
unsigned int data)
|
||||
{
|
||||
unsigned int regptr;
|
||||
unsigned long flags;
|
||||
|
||||
regptr = (reg << 16) | chn;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
outl(regptr, emu->port + CA0106_PTR);
|
||||
outl(data, emu->port + CA0106_DATA);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
}
|
||||
|
||||
int snd_ca0106_spi_write(struct snd_ca0106 * emu,
|
||||
@@ -451,24 +446,20 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
|
||||
|
||||
static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned int intr_enable;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
intr_enable = inl(emu->port + CA0106_INTE) | intrenb;
|
||||
outl(intr_enable, emu->port + CA0106_INTE);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
}
|
||||
|
||||
static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned int intr_enable;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
intr_enable = inl(emu->port + CA0106_INTE) & ~intrenb;
|
||||
outl(intr_enable, emu->port + CA0106_INTE);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,26 +1129,20 @@ static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97,
|
||||
unsigned short reg)
|
||||
{
|
||||
struct snd_ca0106 *emu = ac97->private_data;
|
||||
unsigned long flags;
|
||||
unsigned short val;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
outb(reg, emu->port + CA0106_AC97ADDRESS);
|
||||
val = inw(emu->port + CA0106_AC97DATA);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
return val;
|
||||
return inw(emu->port + CA0106_AC97DATA);
|
||||
}
|
||||
|
||||
static void snd_ca0106_ac97_write(struct snd_ac97 *ac97,
|
||||
unsigned short reg, unsigned short val)
|
||||
{
|
||||
struct snd_ca0106 *emu = ac97->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
outb(reg, emu->port + CA0106_AC97ADDRESS);
|
||||
outw(val, emu->port + CA0106_AC97DATA);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
}
|
||||
|
||||
static int snd_ca0106_ac97(struct snd_ca0106 *chip)
|
||||
|
||||
@@ -281,16 +281,14 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
|
||||
struct snd_info_buffer *buffer)
|
||||
{
|
||||
struct snd_ca0106 *emu = entry->private_data;
|
||||
unsigned long flags;
|
||||
char line[64];
|
||||
u32 reg, val;
|
||||
while (!snd_info_get_line(buffer, line, sizeof(line))) {
|
||||
if (sscanf(line, "%x %x", ®, &val) != 2)
|
||||
continue;
|
||||
if (reg < 0x40 && val <= 0xffffffff) {
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
guard(spinlock_irqsave)(&emu->emu_lock);
|
||||
outl(val, emu->port + (reg & 0xfffffffc));
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,13 +298,13 @@ static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry,
|
||||
{
|
||||
struct snd_ca0106 *emu = entry->private_data;
|
||||
unsigned long value;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
snd_iprintf(buffer, "Registers:\n\n");
|
||||
for(i = 0; i < 0x20; i+=4) {
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
value = inl(emu->port + i);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &emu->emu_lock) {
|
||||
value = inl(emu->port + i);
|
||||
}
|
||||
snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
|
||||
}
|
||||
}
|
||||
@@ -316,13 +314,13 @@ static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry,
|
||||
{
|
||||
struct snd_ca0106 *emu = entry->private_data;
|
||||
unsigned int value;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
snd_iprintf(buffer, "Registers:\n\n");
|
||||
for(i = 0; i < 0x20; i+=2) {
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
value = inw(emu->port + i);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &emu->emu_lock) {
|
||||
value = inw(emu->port + i);
|
||||
}
|
||||
snd_iprintf(buffer, "Register %02X: %04X\n", i, value);
|
||||
}
|
||||
}
|
||||
@@ -332,13 +330,13 @@ static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry,
|
||||
{
|
||||
struct snd_ca0106 *emu = entry->private_data;
|
||||
unsigned int value;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
snd_iprintf(buffer, "Registers:\n\n");
|
||||
for(i = 0; i < 0x20; i+=1) {
|
||||
spin_lock_irqsave(&emu->emu_lock, flags);
|
||||
value = inb(emu->port + i);
|
||||
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &emu->emu_lock) {
|
||||
value = inb(emu->port + i);
|
||||
}
|
||||
snd_iprintf(buffer, "Register %02X: %02X\n", i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,58 +45,54 @@ static void ca_midi_interrupt(struct snd_ca_midi *midi, unsigned int status)
|
||||
return;
|
||||
}
|
||||
|
||||
spin_lock(&midi->input_lock);
|
||||
if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) {
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
|
||||
ca_midi_clear_rx(midi);
|
||||
} else {
|
||||
byte = ca_midi_read_data(midi);
|
||||
if(midi->substream_input)
|
||||
snd_rawmidi_receive(midi->substream_input, &byte, 1);
|
||||
|
||||
|
||||
scoped_guard(spinlock, &midi->input_lock) {
|
||||
if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) {
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
|
||||
ca_midi_clear_rx(midi);
|
||||
} else {
|
||||
byte = ca_midi_read_data(midi);
|
||||
if (midi->substream_input)
|
||||
snd_rawmidi_receive(midi->substream_input, &byte, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
spin_unlock(&midi->input_lock);
|
||||
|
||||
spin_lock(&midi->output_lock);
|
||||
if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) {
|
||||
if (midi->substream_output &&
|
||||
snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
|
||||
ca_midi_write_data(midi, byte);
|
||||
} else {
|
||||
midi->interrupt_disable(midi,midi->tx_enable);
|
||||
scoped_guard(spinlock, &midi->output_lock) {
|
||||
if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) {
|
||||
if (midi->substream_output &&
|
||||
snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
|
||||
ca_midi_write_data(midi, byte);
|
||||
} else {
|
||||
midi->interrupt_disable(midi, midi->tx_enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
spin_unlock(&midi->output_lock);
|
||||
|
||||
}
|
||||
|
||||
static void ca_midi_cmd(struct snd_ca_midi *midi, unsigned char cmd, int ack)
|
||||
{
|
||||
unsigned long flags;
|
||||
int timeout, ok;
|
||||
|
||||
spin_lock_irqsave(&midi->input_lock, flags);
|
||||
ca_midi_write_data(midi, 0x00);
|
||||
/* ca_midi_clear_rx(midi); */
|
||||
scoped_guard(spinlock_irqsave, &midi->input_lock) {
|
||||
ca_midi_write_data(midi, 0x00);
|
||||
/* ca_midi_clear_rx(midi); */
|
||||
|
||||
ca_midi_write_cmd(midi, cmd);
|
||||
if (ack) {
|
||||
ok = 0;
|
||||
timeout = 10000;
|
||||
while (!ok && timeout-- > 0) {
|
||||
if (ca_midi_input_avail(midi)) {
|
||||
if (ca_midi_read_data(midi) == midi->ack)
|
||||
ok = 1;
|
||||
ca_midi_write_cmd(midi, cmd);
|
||||
if (ack) {
|
||||
ok = 0;
|
||||
timeout = 10000;
|
||||
while (!ok && timeout-- > 0) {
|
||||
if (ca_midi_input_avail(midi)) {
|
||||
if (ca_midi_read_data(midi) == midi->ack)
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ok && ca_midi_read_data(midi) == midi->ack)
|
||||
if (!ok && ca_midi_read_data(midi) == midi->ack)
|
||||
ok = 1;
|
||||
} else {
|
||||
ok = 1;
|
||||
} else {
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&midi->input_lock, flags);
|
||||
if (!ok)
|
||||
pr_err("ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n",
|
||||
cmd,
|
||||
@@ -108,83 +104,69 @@ static void ca_midi_cmd(struct snd_ca_midi *midi, unsigned char cmd, int ack)
|
||||
static int ca_midi_input_open(struct snd_rawmidi_substream *substream)
|
||||
{
|
||||
struct snd_ca_midi *midi = substream->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
if (snd_BUG_ON(!midi->dev_id))
|
||||
return -ENXIO;
|
||||
spin_lock_irqsave(&midi->open_lock, flags);
|
||||
midi->midi_mode |= CA_MIDI_MODE_INPUT;
|
||||
midi->substream_input = substream;
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
ca_midi_cmd(midi, midi->reset, 1);
|
||||
ca_midi_cmd(midi, midi->enter_uart, 1);
|
||||
} else {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &midi->open_lock) {
|
||||
midi->midi_mode |= CA_MIDI_MODE_INPUT;
|
||||
midi->substream_input = substream;
|
||||
if (midi->midi_mode & CA_MIDI_MODE_OUTPUT)
|
||||
return 0;
|
||||
}
|
||||
ca_midi_cmd(midi, midi->reset, 1);
|
||||
ca_midi_cmd(midi, midi->enter_uart, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ca_midi_output_open(struct snd_rawmidi_substream *substream)
|
||||
{
|
||||
struct snd_ca_midi *midi = substream->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
if (snd_BUG_ON(!midi->dev_id))
|
||||
return -ENXIO;
|
||||
spin_lock_irqsave(&midi->open_lock, flags);
|
||||
midi->midi_mode |= CA_MIDI_MODE_OUTPUT;
|
||||
midi->substream_output = substream;
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
ca_midi_cmd(midi, midi->reset, 1);
|
||||
ca_midi_cmd(midi, midi->enter_uart, 1);
|
||||
} else {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &midi->open_lock) {
|
||||
midi->midi_mode |= CA_MIDI_MODE_OUTPUT;
|
||||
midi->substream_output = substream;
|
||||
if (midi->midi_mode & CA_MIDI_MODE_INPUT)
|
||||
return 0;
|
||||
}
|
||||
ca_midi_cmd(midi, midi->reset, 1);
|
||||
ca_midi_cmd(midi, midi->enter_uart, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ca_midi_input_close(struct snd_rawmidi_substream *substream)
|
||||
{
|
||||
struct snd_ca_midi *midi = substream->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
if (snd_BUG_ON(!midi->dev_id))
|
||||
return -ENXIO;
|
||||
spin_lock_irqsave(&midi->open_lock, flags);
|
||||
midi->interrupt_disable(midi,midi->rx_enable);
|
||||
midi->midi_mode &= ~CA_MIDI_MODE_INPUT;
|
||||
midi->substream_input = NULL;
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
ca_midi_cmd(midi, midi->reset, 0);
|
||||
} else {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &midi->open_lock) {
|
||||
midi->interrupt_disable(midi, midi->rx_enable);
|
||||
midi->midi_mode &= ~CA_MIDI_MODE_INPUT;
|
||||
midi->substream_input = NULL;
|
||||
if (midi->midi_mode & CA_MIDI_MODE_OUTPUT)
|
||||
return 0;
|
||||
}
|
||||
ca_midi_cmd(midi, midi->reset, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ca_midi_output_close(struct snd_rawmidi_substream *substream)
|
||||
{
|
||||
struct snd_ca_midi *midi = substream->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
if (snd_BUG_ON(!midi->dev_id))
|
||||
return -ENXIO;
|
||||
|
||||
spin_lock_irqsave(&midi->open_lock, flags);
|
||||
|
||||
midi->interrupt_disable(midi,midi->tx_enable);
|
||||
midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT;
|
||||
midi->substream_output = NULL;
|
||||
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
ca_midi_cmd(midi, midi->reset, 0);
|
||||
} else {
|
||||
spin_unlock_irqrestore(&midi->open_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &midi->open_lock) {
|
||||
midi->interrupt_disable(midi, midi->tx_enable);
|
||||
midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT;
|
||||
midi->substream_output = NULL;
|
||||
if (midi->midi_mode & CA_MIDI_MODE_INPUT)
|
||||
return 0;
|
||||
}
|
||||
ca_midi_cmd(midi, midi->reset, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -205,7 +187,6 @@ static void ca_midi_input_trigger(struct snd_rawmidi_substream *substream, int u
|
||||
static void ca_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
|
||||
{
|
||||
struct snd_ca_midi *midi = substream->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
if (snd_BUG_ON(!midi->dev_id))
|
||||
return;
|
||||
@@ -214,25 +195,23 @@ static void ca_midi_output_trigger(struct snd_rawmidi_substream *substream, int
|
||||
int max = 4;
|
||||
unsigned char byte;
|
||||
|
||||
spin_lock_irqsave(&midi->output_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &midi->output_lock) {
|
||||
|
||||
/* try to send some amount of bytes here before interrupts */
|
||||
while (max > 0) {
|
||||
if (ca_midi_output_ready(midi)) {
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) ||
|
||||
snd_rawmidi_transmit(substream, &byte, 1) != 1) {
|
||||
/* no more data */
|
||||
spin_unlock_irqrestore(&midi->output_lock, flags);
|
||||
return;
|
||||
/* try to send some amount of bytes here before interrupts */
|
||||
while (max > 0) {
|
||||
if (ca_midi_output_ready(midi)) {
|
||||
if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) ||
|
||||
snd_rawmidi_transmit(substream, &byte, 1) != 1) {
|
||||
/* no more data */
|
||||
return;
|
||||
}
|
||||
ca_midi_write_data(midi, byte);
|
||||
max--;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
ca_midi_write_data(midi, byte);
|
||||
max--;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&midi->output_lock, flags);
|
||||
midi->interrupt_enable(midi,midi->tx_enable);
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user