Commit 6d72fbc8 authored by Takashi Sakamoto's avatar Takashi Sakamoto

firewire: ohci: use guard macro to serialize accesses to phy registers

The 1394 OHCI driver protects concurrent accesses to phy registers by
mutex object in fw_ohci structure.

This commit uses guard macro to maintain the mutex.

Link: https://lore.kernel.org/r/20240805085408.251763-5-o-takashi@sakamocchi.jpSigned-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent 044ce581
...@@ -713,26 +713,20 @@ static int read_paged_phy_reg(struct fw_ohci *ohci, int page, int addr) ...@@ -713,26 +713,20 @@ static int read_paged_phy_reg(struct fw_ohci *ohci, int page, int addr)
static int ohci_read_phy_reg(struct fw_card *card, int addr) static int ohci_read_phy_reg(struct fw_card *card, int addr)
{ {
struct fw_ohci *ohci = fw_ohci(card); struct fw_ohci *ohci = fw_ohci(card);
int ret;
mutex_lock(&ohci->phy_reg_mutex); guard(mutex)(&ohci->phy_reg_mutex);
ret = read_phy_reg(ohci, addr);
mutex_unlock(&ohci->phy_reg_mutex);
return ret; return read_phy_reg(ohci, addr);
} }
static int ohci_update_phy_reg(struct fw_card *card, int addr, static int ohci_update_phy_reg(struct fw_card *card, int addr,
int clear_bits, int set_bits) int clear_bits, int set_bits)
{ {
struct fw_ohci *ohci = fw_ohci(card); struct fw_ohci *ohci = fw_ohci(card);
int ret;
mutex_lock(&ohci->phy_reg_mutex); guard(mutex)(&ohci->phy_reg_mutex);
ret = update_phy_reg(ohci, addr, clear_bits, set_bits);
mutex_unlock(&ohci->phy_reg_mutex);
return ret; return update_phy_reg(ohci, addr, clear_bits, set_bits);
} }
static inline dma_addr_t ar_buffer_bus(struct ar_context *ctx, unsigned int i) static inline dma_addr_t ar_buffer_bus(struct ar_context *ctx, unsigned int i)
...@@ -1882,13 +1876,15 @@ static int get_status_for_port(struct fw_ohci *ohci, int port_index, ...@@ -1882,13 +1876,15 @@ static int get_status_for_port(struct fw_ohci *ohci, int port_index,
{ {
int reg; int reg;
mutex_lock(&ohci->phy_reg_mutex); scoped_guard(mutex, &ohci->phy_reg_mutex) {
reg = write_phy_reg(ohci, 7, port_index); reg = write_phy_reg(ohci, 7, port_index);
if (reg >= 0) if (reg < 0)
return reg;
reg = read_phy_reg(ohci, 8); reg = read_phy_reg(ohci, 8);
mutex_unlock(&ohci->phy_reg_mutex); if (reg < 0)
if (reg < 0) return reg;
return reg; }
switch (reg & 0x0f) { switch (reg & 0x0f) {
case 0x06: case 0x06:
...@@ -1929,26 +1925,31 @@ static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id, ...@@ -1929,26 +1925,31 @@ static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id,
static bool initiated_reset(struct fw_ohci *ohci) static bool initiated_reset(struct fw_ohci *ohci)
{ {
int reg; int reg;
int ret = false;
mutex_lock(&ohci->phy_reg_mutex); guard(mutex)(&ohci->phy_reg_mutex);
reg = write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */
if (reg >= 0) { // Select page 7
reg = read_phy_reg(ohci, 8); reg = write_phy_reg(ohci, 7, 0xe0);
reg |= 0x40; if (reg < 0)
reg = write_phy_reg(ohci, 8, reg); /* set PMODE bit */ return reg;
if (reg >= 0) {
reg = read_phy_reg(ohci, 12); /* read register 12 */ reg = read_phy_reg(ohci, 8);
if (reg >= 0) { if (reg < 0)
if ((reg & 0x08) == 0x08) { return reg;
/* bit 3 indicates "initiated reset" */
ret = true; // set PMODE bit
} reg |= 0x40;
} reg = write_phy_reg(ohci, 8, reg);
} if (reg < 0)
} return reg;
mutex_unlock(&ohci->phy_reg_mutex);
return ret; // read register 12
reg = read_phy_reg(ohci, 12);
if (reg < 0)
return reg;
// bit 3 indicates "initiated reset"
return !!((reg & 0x08) == 0x08);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment