From a72eb7843abf451e6134273ee71d76ae4d21af32 Mon Sep 17 00:00:00 2001 From: Ramprasad Katkam Date: Tue, 28 Aug 2018 02:56:15 +0530 Subject: [PATCH] asoc: swr: Fix logic to retrieve swr slave device handle Fix issue in the loop logic of retrieving swr slave device handle by passing device node. Change-Id: I5c31259b1257de730748b8522537afa9870f24e4 Signed-off-by: Ramprasad Katkam --- soc/soundwire.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/soc/soundwire.c b/soc/soundwire.c index fff5c1546145..573d39dcd7b9 100644 --- a/soc/soundwire.c +++ b/soc/soundwire.c @@ -796,18 +796,24 @@ struct swr_device *get_matching_swr_slave_device(struct device_node *np) { struct swr_device *swr = NULL; struct swr_master *master; + bool found = false; mutex_lock(&board_lock); list_for_each_entry(master, &swr_master_list, list) { mutex_lock(&master->mlock); list_for_each_entry(swr, &master->devices, dev_list) { - if (swr->dev.of_node == np) - break; + if (swr->dev.of_node == np) { + found = true; + mutex_unlock(&master->mlock); + goto exit; + } } mutex_unlock(&master->mlock); } +exit: mutex_unlock(&board_lock); - + if (!found) + return NULL; return swr; } EXPORT_SYMBOL(get_matching_swr_slave_device); @@ -888,7 +894,6 @@ int swr_register_master(struct swr_master *master) id = idr_alloc(&master_idr, master, master->bus_num, master->bus_num + 1, GFP_KERNEL); mutex_unlock(&swr_lock); - if (id < 0) return id;