public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Walls <awalls@md.metrocast.net>
To: linux-media@vger.kernel.org
Subject: [PATCH 03/13] lirc_zilog: Convert ir_device instance array to a linked list
Date: Thu, 17 Feb 2011 20:14:35 -0500	[thread overview]
Message-ID: <1297991675.9399.19.camel@localhost> (raw)
In-Reply-To: <1297991502.9399.16.camel@localhost>


Signed-off-by: Andy Walls <awalls@md.metrocast.net>
---
 drivers/staging/lirc/lirc_zilog.c |   59 +++++++++++++++++++-----------------
 1 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 3a91257..39f7b53 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -89,6 +89,8 @@ struct IR_tx {
 };
 
 struct IR {
+	struct list_head list;
+
 	struct lirc_driver l;
 
 	struct mutex ir_lock;
@@ -99,9 +101,9 @@ struct IR {
 	struct IR_tx *tx;
 };
 
-/* Minor -> data mapping */
-static struct mutex ir_devices_lock;
-static struct IR *ir_devices[MAX_IRCTL_DEVICES];
+/* IR transceiver instance object list */
+static DEFINE_MUTEX(ir_devices_lock);
+static LIST_HEAD(ir_devices_list);
 
 /* Block size for IR transmitter */
 #define TX_BLOCK_SIZE	99
@@ -1063,10 +1065,16 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 /* ir_devices_lock must be held */
 static struct IR *find_ir_device_by_minor(unsigned int minor)
 {
-	if (minor >= MAX_IRCTL_DEVICES)
+	struct IR *ir;
+
+	if (list_empty(&ir_devices_list))
 		return NULL;
 
-	return ir_devices[minor];
+	list_for_each_entry(ir, &ir_devices_list, list)
+		if (ir->l.minor == minor)
+			return ir;
+
+	return NULL;
 }
 
 /*
@@ -1172,25 +1180,21 @@ static void destroy_rx_kthread(struct IR_rx *rx)
 /* ir_devices_lock must be held */
 static int add_ir_device(struct IR *ir)
 {
-	int i;
-
-	for (i = 0; i < MAX_IRCTL_DEVICES; i++)
-		if (ir_devices[i] == NULL) {
-			ir_devices[i] = ir;
-			break;
-		}
-
-	return i == MAX_IRCTL_DEVICES ? -ENOMEM : i;
+	list_add_tail(&ir->list, &ir_devices_list);
+	return 0;
 }
 
 /* ir_devices_lock must be held */
 static void del_ir_device(struct IR *ir)
 {
-	int i;
+	struct IR *p;
+
+	if (list_empty(&ir_devices_list))
+		return;
 
-	for (i = 0; i < MAX_IRCTL_DEVICES; i++)
-		if (ir_devices[i] == ir) {
-			ir_devices[i] = NULL;
+	list_for_each_entry(p, &ir_devices_list, list)
+		if (p == ir) {
+			list_del(&p->list);
 			break;
 		}
 }
@@ -1237,17 +1241,16 @@ static int ir_remove(struct i2c_client *client)
 /* ir_devices_lock must be held */
 static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
 {
-	int i;
-	struct IR *ir = NULL;
+	struct IR *ir;
 
-	for (i = 0; i < MAX_IRCTL_DEVICES; i++)
-		if (ir_devices[i] != NULL &&
-		    ir_devices[i]->adapter == adapter) {
-			ir = ir_devices[i];
-			break;
-		}
+	if (list_empty(&ir_devices_list))
+		return NULL;
+
+	list_for_each_entry(ir, &ir_devices_list, list)
+		if (ir->adapter == adapter)
+			return ir;
 
-	return ir;
+	return NULL;
 }
 
 static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -1284,6 +1287,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 			goto out_no_ir;
 		}
 		/* store for use in ir_probe() again, and open() later on */
+		INIT_LIST_HEAD(&ir->list);
 		ret = add_ir_device(ir);
 		if (ret)
 			goto out_free_ir;
@@ -1421,7 +1425,6 @@ static int __init zilog_init(void)
 	zilog_notify("Zilog/Hauppauge IR driver initializing\n");
 
 	mutex_init(&tx_data_lock);
-	mutex_init(&ir_devices_lock);
 
 	request_module("firmware_class");
 
-- 
1.7.2.1




  parent reply	other threads:[~2011-02-18  1:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  1:11 [PATCH 0/13] lirc_zilog: Ref-counting and locking cleanup Andy Walls
2011-02-18  1:12 ` [PATCH 01/13] lirc_zilog: Restore checks for existence of the IR_tx object Andy Walls
2011-02-18  1:13 ` [PATCH 02/13] lirc_zilog: Remove broken, ineffective reference counting Andy Walls
2011-02-18  1:14 ` Andy Walls [this message]
2011-02-18  1:15 ` [PATCH 04/13] lirc_zilog: Convert the instance open count to an atomic_t Andy Walls
2011-02-18  1:15 ` [PATCH 05/13] lirc_zilog: Use kernel standard methods for marking device non-seekable Andy Walls
2011-02-18  1:16 ` [PATCH 06/13] lirc_zilog: Don't acquire the rx->buf_lock in the poll() function Andy Walls
2011-02-18  1:17 ` [PATCH 07/13] lirc_zilog: Remove unneeded rx->buf_lock Andy Walls
2011-02-18  1:18 ` [PATCH 08/13] lirc_zilog: Always allocate a Rx lirc_buffer object Andy Walls
2011-02-18  1:19 ` [PATCH 09/13] lirc_zilog: Move constants from ir_probe() into the lirc_driver template Andy Walls
2011-02-18  1:20 ` [PATCH 10/13] lirc_zilog: Add ref counting of struct IR, IR_tx, and IR_rx Andy Walls
2011-02-18  1:20 ` [PATCH 11/13] lirc_zilog: Add locking of the i2c_clients when in use Andy Walls
2011-02-18  1:21 ` [PATCH 12/13] lirc_zilog: Fix somewhat confusing information messages in ir_probe() Andy Walls
2011-02-18  1:22 ` [PATCH 13/13] lirc_zilog: Update TODO list based on work completed and revised plans Andy Walls
2011-03-06  4:00 ` [PATCH 0/13] lirc_zilog: Ref-counting and locking cleanup Jarod Wilson

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=1297991675.9399.19.camel@localhost \
    --to=awalls@md.metrocast.net \
    --cc=linux-media@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