Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions drivers/soundwire/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,8 +1788,12 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)

/* Update the Slave driver */
if (slave_notify) {
if (slave->prop.use_domain_irq && slave->irq)
handle_nested_irq(slave->irq);
if (slave->prop.use_domain_irq) {
mutex_lock(&slave->irq_lock);
if (slave->irq)
handle_nested_irq(slave->irq);
mutex_unlock(&slave->irq_lock);
}

mutex_lock(&slave->sdw_dev_lock);

Expand Down
9 changes: 8 additions & 1 deletion drivers/soundwire/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ void sdw_irq_delete(struct sdw_bus *bus)
static void sdw_irq_dispose_mapping(void *data)
{
struct sdw_slave *slave = data;
int irq;

irq_dispose_mapping(slave->irq);
mutex_lock(&slave->irq_lock);
irq = slave->irq;
slave->irq = 0;
mutex_unlock(&slave->irq_lock);

if (irq)
irq_dispose_mapping(irq);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a dumb question but shouldn't the lock be used in sdw_irq_create mapping, line 58 just below?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, not a dumb question. As per our understanding, the lock is not needed in sdw_irq_create_mapping() because slave->prop.use_domain_irq is always false at that point.
All drivers that use the domain IRQ set this flag in their read_prop callback, which is invoked after drv->probe() completes . The alert handler in sdw_handle_slave_alerts() guards the entire slave->irq access with if (slave->prop.use_domain_irq),
so it cannot reach the irq_lock block or read slave->irq during the creation window.
No concurrent access to slave->irq is possible at that stage.

The lock in sdw_irq_dispose_mapping() serializes against the alert handler during teardown — a later phase where use_domain_irq is already true and the race is real.

Please correct us if we have missed something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Probably best to ask @charleskeepax to take a look

}

void sdw_irq_create_mapping(struct sdw_slave *slave)
Expand Down
2 changes: 2 additions & 0 deletions drivers/soundwire/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static void sdw_slave_release(struct device *dev)

of_node_put(slave->dev.of_node);
mutex_destroy(&slave->sdw_dev_lock);
mutex_destroy(&slave->irq_lock);
kfree(slave);
}

Expand Down Expand Up @@ -65,6 +66,7 @@ int sdw_slave_add(struct sdw_bus *bus,
slave->probed = false;
slave->first_interrupt_done = false;
mutex_init(&slave->sdw_dev_lock);
mutex_init(&slave->irq_lock);

for (i = 0; i < SDW_MAX_PORTS; i++)
init_completion(&slave->port_ready[i]);
Expand Down
1 change: 1 addition & 0 deletions include/linux/soundwire/sdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ struct sdw_slave {
bool first_interrupt_done;
bool is_mockup_device;
struct mutex sdw_dev_lock; /* protect callbacks/remove races */
struct mutex irq_lock; /* serialize handle_nested_irq and irq_dispose_mapping */
struct sdca_device_data sdca_data;
};

Expand Down
Loading