linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: eero.nurkkala@offcode.fi
To: linux-arm-msm@vger.kernel.org
Cc: Eero Nurkkala <eero.nurkkala@offcode.fi>
Subject: [PATCH 1/4] msm: audio: qdsp6v2: simplify linked lists
Date: Tue, 15 Feb 2011 14:08:38 +0200	[thread overview]
Message-ID: <1297771721-17574-1-git-send-email-eero.nurkkala@offcode.fi> (raw)

From: Eero Nurkkala <eero.nurkkala@offcode.fi>

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@offcode.fi>
---
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


             reply	other threads:[~2011-02-15 12:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 12:08 eero.nurkkala [this message]
2011-02-15 12:08 ` [PATCH 2/4] msm: audio: qdsp6v2: remove unused mixer_post_event() eero.nurkkala
2011-02-15 12:08 ` [PATCH 3/4] msm: audio: qdsp6v2: fix potential memory corruption eero.nurkkala
2011-02-15 12:08 ` [PATCH/RFC 4/4] msm: audio: qdsp6v2: simplify broadcast_event() eero.nurkkala
2011-02-16 23:58   ` Patrick Lai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297771721-17574-1-git-send-email-eero.nurkkala@offcode.fi \
    --to=eero.nurkkala@offcode.fi \
    --cc=linux-arm-msm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).