[PATCH 1/4] msm: audio: qdsp6v2: simplify linked lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Eero Nurkkala <eero.nurkkala@xxxxxxxxxx>

There's no point in introducing linked lists as they're
already provided by the kernel. Remove the proprietary
linked lists which may actually introduce risks.

Signed-off-by: Eero Nurkkala <eero.nurkkala@xxxxxxxxxx>
---
branch: android-msm-2.6.35
 .../mach-msm/include/mach/qdsp6v2/audio_dev_ctl.h  |    5 +-
 arch/arm/mach-msm/qdsp6v2/audio_dev_ctl.c          |  110 +++++---------------
 2 files changed, 27 insertions(+), 88 deletions(-)

diff --git a/arch/arm/mach-msm/include/mach/qdsp6v2/audio_dev_ctl.h b/arch/arm/mach-msm/include/mach/qdsp6v2/audio_dev_ctl.h
index a72d21a..53a641b 100644
--- a/arch/arm/mach-msm/include/mach/qdsp6v2/audio_dev_ctl.h
+++ b/arch/arm/mach-msm/include/mach/qdsp6v2/audio_dev_ctl.h
@@ -193,12 +193,11 @@ struct msm_snd_evt_listner {
 	void (*auddev_evt_listener)(u32 evt_id,
 		union auddev_evt_data *evt_payload,
 		void *private_data);
-	struct msm_snd_evt_listner *cb_next;
-	struct msm_snd_evt_listner *cb_prev;
+	struct list_head list;
 };
 
 struct event_listner {
-	struct msm_snd_evt_listner *cb;
+	struct list_head list;
 	u32 num_listner;
 	int state; /* Call state */ /* TODO remove this if not req*/
 };
diff --git a/arch/arm/mach-msm/qdsp6v2/audio_dev_ctl.c b/arch/arm/mach-msm/qdsp6v2/audio_dev_ctl.c
index 38cf132..8ac8c63 100644
--- a/arch/arm/mach-msm/qdsp6v2/audio_dev_ctl.c
+++ b/arch/arm/mach-msm/qdsp6v2/audio_dev_ctl.c
@@ -664,7 +664,6 @@ int auddev_register_evt_listner(u32 evt_id, u32 clnt_type, u32 clnt_id,
 		void *private_data)
 {
 	int rc;
-	struct msm_snd_evt_listner *callback = NULL;
 	struct msm_snd_evt_listner *new_cb;
 
 	new_cb = kzalloc(sizeof(struct msm_snd_evt_listner), GFP_KERNEL);
@@ -674,28 +673,12 @@ int auddev_register_evt_listner(u32 evt_id, u32 clnt_type, u32 clnt_id,
 	}
 
 	mutex_lock(&session_lock);
-	new_cb->cb_next = NULL;
 	new_cb->auddev_evt_listener = listner;
 	new_cb->evt_id = evt_id;
 	new_cb->clnt_type = clnt_type;
 	new_cb->clnt_id = clnt_id;
 	new_cb->private_data = private_data;
-	if (event.cb == NULL) {
-		event.cb = new_cb;
-		new_cb->cb_prev = NULL;
-	} else {
-		callback = event.cb;
-		for (; ;) {
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
-		}
-		callback->cb_next = new_cb;
-		new_cb->cb_prev = callback;
-	}
+	list_add_tail(&new_cb->list, &event.list);
 	event.num_listner++;
 	mutex_unlock(&session_lock);
 	rc = 0;
@@ -705,34 +688,23 @@ EXPORT_SYMBOL(auddev_register_evt_listner);
 
 int auddev_unregister_evt_listner(u32 clnt_type, u32 clnt_id)
 {
-	struct msm_snd_evt_listner *callback = event.cb;
+	struct msm_snd_evt_listner *callback;
 	struct msm_snddev_info *info;
 	u64 session_mask = 0;
 	int i = 0;
 
 	mutex_lock(&session_lock);
-	while (callback != NULL) {
-		if ((callback->clnt_type == clnt_type)
-			&& (callback->clnt_id == clnt_id))
-			break;
-		 callback = callback->cb_next;
-	}
-	if (callback == NULL) {
-		mutex_unlock(&session_lock);
-		return -EINVAL;
-	}
 
-	if ((callback->cb_next == NULL) && (callback->cb_prev == NULL))
-		event.cb = NULL;
-	else if (callback->cb_next == NULL)
-		callback->cb_prev->cb_next = NULL;
-	else if (callback->cb_prev == NULL) {
-		callback->cb_next->cb_prev = NULL;
-		event.cb = callback->cb_next;
-	} else {
-		callback->cb_prev->cb_next = callback->cb_next;
-		callback->cb_next->cb_prev = callback->cb_prev;
+	list_for_each_entry(callback, &event.list, list) {
+		if ((callback->clnt_type == clnt_type) &&
+			(callback->clnt_id == clnt_id))
+			goto found_listner;
 	}
+	mutex_unlock(&session_lock);
+	return -EINVAL;
+
+found_listner:
+	list_del(&callback->list);
 	kfree(callback);
 
 	session_mask = (((u64)0x1) << clnt_id) << (MAX_BIT_PER_CLIENT * \
@@ -1046,10 +1018,9 @@ void broadcast_event(u32 evt_id, u32 dev_id, u64 session_id)
 		&& (evt_id != AUDDEV_EVT_VOICE_STATE_CHG))
 		dev_info = audio_dev_ctrl_find_dev(dev_id);
 
-	if (event.cb != NULL)
-		callback = event.cb;
-	else
+	if (list_empty(&event.list))
 		return;
+
 	mutex_lock(&session_lock);
 
 	if (evt_id == AUDDEV_EVT_VOICE_STATE_CHG)
@@ -1058,15 +1029,10 @@ void broadcast_event(u32 evt_id, u32 dev_id, u64 session_id)
 	evt_payload = kzalloc(sizeof(union auddev_evt_data),
 			GFP_KERNEL);
 
-	for (; ;) {
-		if (!(evt_id & callback->evt_id)) {
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
-		}
+	list_for_each_entry(callback, &event.list, list) {
+		if (!(evt_id & callback->evt_id))
+			continue;
+
 		clnt_id = callback->clnt_id;
 		memset(evt_payload, 0, sizeof(union auddev_evt_data));
 
@@ -1091,14 +1057,9 @@ void broadcast_event(u32 evt_id, u32 dev_id, u64 session_id)
 
 		if ((!session_id && !(dev_info->sessions & session_mask)) ||
 			(session_id && ((dev_info->sessions & session_mask) !=
-						session_id))) {
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
-		}
+						session_id)))
+			continue;
+
 		if (evt_id == AUDDEV_EVT_DEV_CHG_VOICE)
 			goto voc_events;
 
@@ -1143,13 +1104,7 @@ sent_dec:
 				(evt_id != AUDDEV_EVT_VOICE_STATE_CHG))
 				routing_info.dec_freq[clnt_id].freq
 						= dev_info->set_sample_rate;
-
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
+			continue;
 		}
 		if (callback->clnt_type == AUDDEV_CLNT_ENC) {
 			pr_debug("AUDDEV_CLNT_ENC\n");
@@ -1176,12 +1131,7 @@ sent_dec:
 					evt_payload,
 					callback->private_data);
 sent_enc:
-			if (callback->cb_next == NULL)
-					break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
+			continue;
 		}
 aud_cal:
 		if (callback->clnt_type == AUDDEV_CLNT_AUDIOCAL) {
@@ -1210,12 +1160,7 @@ aud_cal:
 				callback->private_data);
 
 sent_aud_cal:
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
+			continue;
 		}
 skip_check:
 voc_events:
@@ -1300,12 +1245,7 @@ voc_events:
 			if (evt_id == AUDDEV_EVT_DEV_RLS)
 				dev_info->sessions &= ~(0xFFFF);
 sent_voc:
-			if (callback->cb_next == NULL)
-				break;
-			else {
-				callback = callback->cb_next;
-				continue;
-			}
+			continue;
 		}
 	}
 	kfree(evt_payload);
@@ -1360,7 +1300,7 @@ static int __init audio_dev_ctrl_init(void)
 {
 	init_waitqueue_head(&audio_dev_ctrl.wait);
 
-	event.cb = NULL;
+	INIT_LIST_HEAD(&event.list);
 
 	atomic_set(&audio_dev_ctrl.opened, 0);
 	audio_dev_ctrl.num_dev = 0;
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux