Skip to content

Commit 86baade

Browse files
committed
firewire: ohci: use guard macro to maintain image of configuration ROM
The 1394 OHCI driver uses spinlock for the process to update local configuration ROM. This commit uses guard macro to maintain the spinlock. Link: https://lore.kernel.org/r/20240805085408.251763-17-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent b10e56f commit 86baade

1 file changed

Lines changed: 49 additions & 67 deletions

File tree

drivers/firewire/ohci.c

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,53 +2139,42 @@ static void bus_reset_work(struct work_struct *work)
21392139
at_context_flush(&ohci->at_request_ctx);
21402140
at_context_flush(&ohci->at_response_ctx);
21412141

2142-
spin_lock_irq(&ohci->lock);
2143-
2144-
ohci->generation = generation;
2145-
reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
2146-
reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
2147-
2148-
if (ohci->quirks & QUIRK_RESET_PACKET)
2149-
ohci->request_generation = generation;
2150-
2151-
/*
2152-
* This next bit is unrelated to the AT context stuff but we
2153-
* have to do it under the spinlock also. If a new config rom
2154-
* was set up before this reset, the old one is now no longer
2155-
* in use and we can free it. Update the config rom pointers
2156-
* to point to the current config rom and clear the
2157-
* next_config_rom pointer so a new update can take place.
2158-
*/
2159-
2160-
if (ohci->next_config_rom != NULL) {
2161-
if (ohci->next_config_rom != ohci->config_rom) {
2162-
free_rom = ohci->config_rom;
2163-
free_rom_bus = ohci->config_rom_bus;
2142+
scoped_guard(spinlock_irq, &ohci->lock) {
2143+
ohci->generation = generation;
2144+
reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
2145+
reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
2146+
2147+
if (ohci->quirks & QUIRK_RESET_PACKET)
2148+
ohci->request_generation = generation;
2149+
2150+
// This next bit is unrelated to the AT context stuff but we have to do it under the
2151+
// spinlock also. If a new config rom was set up before this reset, the old one is
2152+
// now no longer in use and we can free it. Update the config rom pointers to point
2153+
// to the current config rom and clear the next_config_rom pointer so a new update
2154+
// can take place.
2155+
if (ohci->next_config_rom != NULL) {
2156+
if (ohci->next_config_rom != ohci->config_rom) {
2157+
free_rom = ohci->config_rom;
2158+
free_rom_bus = ohci->config_rom_bus;
2159+
}
2160+
ohci->config_rom = ohci->next_config_rom;
2161+
ohci->config_rom_bus = ohci->next_config_rom_bus;
2162+
ohci->next_config_rom = NULL;
2163+
2164+
// Restore config_rom image and manually update config_rom registers.
2165+
// Writing the header quadlet will indicate that the config rom is ready,
2166+
// so we do that last.
2167+
reg_write(ohci, OHCI1394_BusOptions, be32_to_cpu(ohci->config_rom[2]));
2168+
ohci->config_rom[0] = ohci->next_header;
2169+
reg_write(ohci, OHCI1394_ConfigROMhdr, be32_to_cpu(ohci->next_header));
21642170
}
2165-
ohci->config_rom = ohci->next_config_rom;
2166-
ohci->config_rom_bus = ohci->next_config_rom_bus;
2167-
ohci->next_config_rom = NULL;
21682171

2169-
/*
2170-
* Restore config_rom image and manually update
2171-
* config_rom registers. Writing the header quadlet
2172-
* will indicate that the config rom is ready, so we
2173-
* do that last.
2174-
*/
2175-
reg_write(ohci, OHCI1394_BusOptions,
2176-
be32_to_cpu(ohci->config_rom[2]));
2177-
ohci->config_rom[0] = ohci->next_header;
2178-
reg_write(ohci, OHCI1394_ConfigROMhdr,
2179-
be32_to_cpu(ohci->next_header));
2180-
}
2181-
2182-
if (param_remote_dma) {
2183-
reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
2184-
reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
2172+
if (param_remote_dma) {
2173+
reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
2174+
reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
2175+
}
21852176
}
21862177

2187-
spin_unlock_irq(&ohci->lock);
2188-
21892178
if (free_rom)
21902179
dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_rom_bus);
21912180

@@ -2626,33 +2615,26 @@ static int ohci_set_config_rom(struct fw_card *card,
26262615
if (next_config_rom == NULL)
26272616
return -ENOMEM;
26282617

2629-
spin_lock_irq(&ohci->lock);
2630-
2631-
/*
2632-
* If there is not an already pending config_rom update,
2633-
* push our new allocation into the ohci->next_config_rom
2634-
* and then mark the local variable as null so that we
2635-
* won't deallocate the new buffer.
2636-
*
2637-
* OTOH, if there is a pending config_rom update, just
2638-
* use that buffer with the new config_rom data, and
2639-
* let this routine free the unused DMA allocation.
2640-
*/
2641-
2642-
if (ohci->next_config_rom == NULL) {
2643-
ohci->next_config_rom = next_config_rom;
2644-
ohci->next_config_rom_bus = next_config_rom_bus;
2645-
next_config_rom = NULL;
2646-
}
2618+
scoped_guard(spinlock_irq, &ohci->lock) {
2619+
// If there is not an already pending config_rom update, push our new allocation
2620+
// into the ohci->next_config_rom and then mark the local variable as null so that
2621+
// we won't deallocate the new buffer.
2622+
//
2623+
// OTOH, if there is a pending config_rom update, just use that buffer with the new
2624+
// config_rom data, and let this routine free the unused DMA allocation.
2625+
if (ohci->next_config_rom == NULL) {
2626+
ohci->next_config_rom = next_config_rom;
2627+
ohci->next_config_rom_bus = next_config_rom_bus;
2628+
next_config_rom = NULL;
2629+
}
26472630

2648-
copy_config_rom(ohci->next_config_rom, config_rom, length);
2631+
copy_config_rom(ohci->next_config_rom, config_rom, length);
26492632

2650-
ohci->next_header = config_rom[0];
2651-
ohci->next_config_rom[0] = 0;
2633+
ohci->next_header = config_rom[0];
2634+
ohci->next_config_rom[0] = 0;
26522635

2653-
reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
2654-
2655-
spin_unlock_irq(&ohci->lock);
2636+
reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
2637+
}
26562638

26572639
/* If we didn't use the DMA allocation, delete it. */
26582640
if (next_config_rom != NULL) {

0 commit comments

Comments
 (0)