]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firewire: ohci: use guard macro to maintain image of configuration ROM
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 5 Aug 2024 08:54:07 +0000 (17:54 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 5 Aug 2024 08:54:07 +0000 (17:54 +0900)
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>
drivers/firewire/ohci.c

index 5cb7c7603c2cada2020986fc7d0572034585a2fb..368420e4b4140f612a419c6d7b27573359937b47 100644 (file)
@@ -2139,53 +2139,42 @@ static void bus_reset_work(struct work_struct *work)
        at_context_flush(&ohci->at_request_ctx);
        at_context_flush(&ohci->at_response_ctx);
 
-       spin_lock_irq(&ohci->lock);
-
-       ohci->generation = generation;
-       reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
-       reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
-
-       if (ohci->quirks & QUIRK_RESET_PACKET)
-               ohci->request_generation = generation;
-
-       /*
-        * This next bit is unrelated to the AT context stuff but we
-        * have to do it under the spinlock also.  If a new config rom
-        * was set up before this reset, the old one is now no longer
-        * in use and we can free it. Update the config rom pointers
-        * to point to the current config rom and clear the
-        * next_config_rom pointer so a new update can take place.
-        */
-
-       if (ohci->next_config_rom != NULL) {
-               if (ohci->next_config_rom != ohci->config_rom) {
-                       free_rom      = ohci->config_rom;
-                       free_rom_bus  = ohci->config_rom_bus;
+       scoped_guard(spinlock_irq, &ohci->lock) {
+               ohci->generation = generation;
+               reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
+               reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
+
+               if (ohci->quirks & QUIRK_RESET_PACKET)
+                       ohci->request_generation = generation;
+
+               // This next bit is unrelated to the AT context stuff but we have to do it under the
+               // spinlock also. If a new config rom was set up before this reset, the old one is
+               // now no longer in use and we can free it. Update the config rom pointers to point
+               // to the current config rom and clear the next_config_rom pointer so a new update
+               // can take place.
+               if (ohci->next_config_rom != NULL) {
+                       if (ohci->next_config_rom != ohci->config_rom) {
+                               free_rom      = ohci->config_rom;
+                               free_rom_bus  = ohci->config_rom_bus;
+                       }
+                       ohci->config_rom      = ohci->next_config_rom;
+                       ohci->config_rom_bus  = ohci->next_config_rom_bus;
+                       ohci->next_config_rom = NULL;
+
+                       // Restore config_rom image and manually update config_rom registers.
+                       // Writing the header quadlet will indicate that the config rom is ready,
+                       // so we do that last.
+                       reg_write(ohci, OHCI1394_BusOptions, be32_to_cpu(ohci->config_rom[2]));
+                       ohci->config_rom[0] = ohci->next_header;
+                       reg_write(ohci, OHCI1394_ConfigROMhdr, be32_to_cpu(ohci->next_header));
                }
-               ohci->config_rom      = ohci->next_config_rom;
-               ohci->config_rom_bus  = ohci->next_config_rom_bus;
-               ohci->next_config_rom = NULL;
 
-               /*
-                * Restore config_rom image and manually update
-                * config_rom registers.  Writing the header quadlet
-                * will indicate that the config rom is ready, so we
-                * do that last.
-                */
-               reg_write(ohci, OHCI1394_BusOptions,
-                         be32_to_cpu(ohci->config_rom[2]));
-               ohci->config_rom[0] = ohci->next_header;
-               reg_write(ohci, OHCI1394_ConfigROMhdr,
-                         be32_to_cpu(ohci->next_header));
-       }
-
-       if (param_remote_dma) {
-               reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
-               reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
+               if (param_remote_dma) {
+                       reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
+                       reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
+               }
        }
 
-       spin_unlock_irq(&ohci->lock);
-
        if (free_rom)
                dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_rom_bus);
 
@@ -2626,33 +2615,26 @@ static int ohci_set_config_rom(struct fw_card *card,
        if (next_config_rom == NULL)
                return -ENOMEM;
 
-       spin_lock_irq(&ohci->lock);
-
-       /*
-        * If there is not an already pending config_rom update,
-        * push our new allocation into the ohci->next_config_rom
-        * and then mark the local variable as null so that we
-        * won't deallocate the new buffer.
-        *
-        * OTOH, if there is a pending config_rom update, just
-        * use that buffer with the new config_rom data, and
-        * let this routine free the unused DMA allocation.
-        */
-
-       if (ohci->next_config_rom == NULL) {
-               ohci->next_config_rom = next_config_rom;
-               ohci->next_config_rom_bus = next_config_rom_bus;
-               next_config_rom = NULL;
-       }
+       scoped_guard(spinlock_irq, &ohci->lock) {
+               // If there is not an already pending config_rom update, push our new allocation
+               // into the ohci->next_config_rom and then mark the local variable as null so that
+               // we won't deallocate the new buffer.
+               //
+               // OTOH, if there is a pending config_rom update, just use that buffer with the new
+               // config_rom data, and let this routine free the unused DMA allocation.
+               if (ohci->next_config_rom == NULL) {
+                       ohci->next_config_rom = next_config_rom;
+                       ohci->next_config_rom_bus = next_config_rom_bus;
+                       next_config_rom = NULL;
+               }
 
-       copy_config_rom(ohci->next_config_rom, config_rom, length);
+               copy_config_rom(ohci->next_config_rom, config_rom, length);
 
-       ohci->next_header = config_rom[0];
-       ohci->next_config_rom[0] = 0;
+               ohci->next_header = config_rom[0];
+               ohci->next_config_rom[0] = 0;
 
-       reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
-
-       spin_unlock_irq(&ohci->lock);
+               reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
+       }
 
        /* If we didn't use the DMA allocation, delete it. */
        if (next_config_rom != NULL) {