summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/dvb-core
diff options
context:
space:
mode:
authorHolger Waechtler <devnull@localhost>2002-11-18 14:57:06 +0000
committerHolger Waechtler <devnull@localhost>2002-11-18 14:57:06 +0000
commit6c6060f3632163ab6029960adfdabf7b3e0f16f0 (patch)
tree074f45e6c2a1ef712335aa8125249557a22a30d6 /linux/drivers/media/dvb/dvb-core
parent5e15253f91666b7384120c01625e41c24a35b7c3 (diff)
downloadmediapointer-dvb-s2-6c6060f3632163ab6029960adfdabf7b3e0f16f0.tar.gz
mediapointer-dvb-s2-6c6060f3632163ab6029960adfdabf7b3e0f16f0.tar.bz2
code review and simplification
Diffstat (limited to 'linux/drivers/media/dvb/dvb-core')
-rw-r--r--linux/drivers/media/dvb/dvb-core/dvb_i2c.c101
1 files changed, 49 insertions, 52 deletions
diff --git a/linux/drivers/media/dvb/dvb-core/dvb_i2c.c b/linux/drivers/media/dvb/dvb-core/dvb_i2c.c
index e9a48ba1a..c25e846a9 100644
--- a/linux/drivers/media/dvb/dvb-core/dvb_i2c.c
+++ b/linux/drivers/media/dvb/dvb-core/dvb_i2c.c
@@ -93,15 +93,17 @@ static
void unregister_i2c_client_from_bus (struct dvb_i2c_device *dev,
struct dvb_i2c_bus *i2c)
{
- struct list_head *entry;
+ struct list_head *entry, *n;
- list_for_each (entry, &i2c->client_list) {
+ list_for_each_safe (entry, n, &i2c->client_list) {
struct dvb_i2c_device *client;
client = list_entry (entry, struct dvb_i2c_device, list_head);
- if (client->detach == dev->detach)
+ if (client->detach == dev->detach) {
+ list_del (entry);
detach_device (i2c, dev);
+ }
}
}
@@ -109,9 +111,9 @@ void unregister_i2c_client_from_bus (struct dvb_i2c_device *dev,
static
void unregister_i2c_client_from_all_busses (struct dvb_i2c_device *dev)
{
- struct list_head *entry;
+ struct list_head *entry, *n;
- list_for_each (entry, &dvb_i2c_buslist) {
+ list_for_each_safe (entry, n, &dvb_i2c_buslist) {
struct dvb_i2c_bus *i2c;
i2c = list_entry (entry, struct dvb_i2c_bus, list_head);
@@ -127,18 +129,15 @@ void unregister_all_clients_from_bus (struct dvb_i2c_bus *i2c)
struct list_head *entry, *n;
list_for_each_safe (entry, n, &(i2c->client_list)) {
- struct dvb_i2c_device *client;
-
- client = list_entry (entry, struct dvb_i2c_device, list_head);
+ struct dvb_i2c_device *dev;
- detach_device (i2c, client);
+ dev = list_entry (entry, struct dvb_i2c_device, list_head);
- list_del (entry);
+ unregister_i2c_client_from_bus (dev, i2c);
}
}
-
static
void probe_device_on_all_busses (struct dvb_i2c_device *dev)
{
@@ -169,15 +168,40 @@ void probe_devices_on_bus (struct dvb_i2c_bus *i2c)
}
-struct dvb_i2c_bus*
-dvb_register_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
- struct i2c_msg msgs[], int num),
- void *data,
- struct dvb_adapter *adapter,
- int id)
+static
+struct dvb_i2c_bus* dvb_find_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
+ struct i2c_msg msgs[],
+ int num),
+ struct dvb_adapter *adapter,
+ int id)
+{
+ struct list_head *entry;
+
+ list_for_each (entry, &dvb_i2c_buslist) {
+ struct dvb_i2c_bus *i2c;
+
+ i2c = list_entry (entry, struct dvb_i2c_bus, list_head);
+
+ if (i2c->xfer == xfer && i2c->adapter == adapter && i2c->id == id)
+ return i2c;
+ }
+
+ return NULL;
+}
+
+
+struct dvb_i2c_bus* dvb_register_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
+ struct i2c_msg msgs[],
+ int num),
+ void *data,
+ struct dvb_adapter *adapter,
+ int id)
{
struct dvb_i2c_bus *i2c;
+ if (down_interruptible (&dvb_i2c_mutex))
+ return NULL;
+
if (!(i2c = kmalloc (sizeof (struct dvb_i2c_bus), GFP_KERNEL)))
return NULL;
@@ -193,54 +217,28 @@ dvb_register_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
list_add_tail (&i2c->list_head, &dvb_i2c_buslist);
- return i2c;
-}
-
-
-struct dvb_i2c_bus*
-dvb_find_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
- struct i2c_msg msgs[], int num),
- struct dvb_adapter *adapter,
- int id)
-{
- struct list_head *entry;
-
- if (down_interruptible (&dvb_i2c_mutex))
- return NULL;
-
- list_for_each (entry, &dvb_i2c_buslist) {
- struct dvb_i2c_bus *i2c;
-
- i2c = list_entry (entry, struct dvb_i2c_bus, list_head);
-
- if (i2c->xfer == xfer &&
- i2c->adapter == adapter &&
- i2c->id == id)
- {
- up (&dvb_i2c_mutex);
- return i2c;
- }
- }
-
up (&dvb_i2c_mutex);
- return NULL;
+ return i2c;
}
-
void dvb_unregister_i2c_bus (int (*xfer) (struct dvb_i2c_bus *i2c,
struct i2c_msg msgs[], int num),
struct dvb_adapter *adapter,
int id)
{
- struct dvb_i2c_bus *i2c = dvb_find_i2c_bus (xfer, adapter, id);
+ struct dvb_i2c_bus *i2c;
- if (i2c) {
+ down (&dvb_i2c_mutex);
+
+ if ((i2c = dvb_find_i2c_bus (xfer, adapter, id))) {
unregister_all_clients_from_bus (i2c);
list_del (&i2c->list_head);
kfree (i2c);
}
+
+ up (&dvb_i2c_mutex);
}
@@ -276,8 +274,7 @@ int dvb_unregister_i2c_device (int (*attach) (struct dvb_i2c_bus *i2c))
{
struct list_head *entry, *n;
- if (down_interruptible (&dvb_i2c_mutex))
- return -ERESTARTSYS;
+ down (&dvb_i2c_mutex);
list_for_each_safe (entry, n, &dvb_i2c_devicelist) {
struct dvb_i2c_device *dev;