firewire: core: use guard macro to maintain the list of card

The core function maintains registered cards by list. The concurrent
access to the list is protected by static mutex.

This commit uses guard macro to maintain the mutex.

Link: https://lore.kernel.org/r/20240805085408.251763-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit is contained in:
Takashi Sakamoto 2024-08-05 17:53:53 +09:00
parent 232f72b10d
commit 57b40ec6db

View File

@ -168,7 +168,6 @@ static size_t required_space(struct fw_descriptor *desc)
int fw_core_add_descriptor(struct fw_descriptor *desc)
{
size_t i;
int ret;
/*
* Check descriptor is valid; the length of all blocks in the
@ -182,29 +181,25 @@ int fw_core_add_descriptor(struct fw_descriptor *desc)
if (i != desc->length)
return -EINVAL;
mutex_lock(&card_mutex);
guard(mutex)(&card_mutex);
if (config_rom_length + required_space(desc) > 256) {
ret = -EBUSY;
} else {
list_add_tail(&desc->link, &descriptor_list);
config_rom_length += required_space(desc);
if (config_rom_length + required_space(desc) > 256)
return -EBUSY;
list_add_tail(&desc->link, &descriptor_list);
config_rom_length += required_space(desc);
descriptor_count++;
if (desc->immediate > 0)
descriptor_count++;
if (desc->immediate > 0)
descriptor_count++;
update_config_roms();
ret = 0;
}
update_config_roms();
mutex_unlock(&card_mutex);
return ret;
return 0;
}
EXPORT_SYMBOL(fw_core_add_descriptor);
void fw_core_remove_descriptor(struct fw_descriptor *desc)
{
mutex_lock(&card_mutex);
guard(mutex)(&card_mutex);
list_del(&desc->link);
config_rom_length -= required_space(desc);
@ -212,8 +207,6 @@ void fw_core_remove_descriptor(struct fw_descriptor *desc)
if (desc->immediate > 0)
descriptor_count--;
update_config_roms();
mutex_unlock(&card_mutex);
}
EXPORT_SYMBOL(fw_core_remove_descriptor);
@ -587,16 +580,16 @@ int fw_card_add(struct fw_card *card,
card->link_speed = link_speed;
card->guid = guid;
mutex_lock(&card_mutex);
guard(mutex)(&card_mutex);
generate_config_rom(card, tmp_config_rom);
ret = card->driver->enable(card, tmp_config_rom, config_rom_length);
if (ret == 0)
list_add_tail(&card->link, &card_list);
if (ret < 0)
return ret;
mutex_unlock(&card_mutex);
list_add_tail(&card->link, &card_list);
return ret;
return 0;
}
EXPORT_SYMBOL(fw_card_add);
@ -720,9 +713,8 @@ void fw_core_remove_card(struct fw_card *card)
PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
fw_schedule_bus_reset(card, false, true);
mutex_lock(&card_mutex);
list_del_init(&card->link);
mutex_unlock(&card_mutex);
scoped_guard(mutex, &card_mutex)
list_del_init(&card->link);
/* Switch off most of the card driver interface. */
dummy_driver.free_iso_context = card->driver->free_iso_context;