SourceForge: dxr3/em8300: changeset 691:e8d3a5470329
Lock the module for the video encoder chip.
authorNicolas Boullis <nboullis@debian.org>
Sat Sep 26 23:55:15 2009 +0200 (8 weeks ago)
changeset 691e8d3a5470329
parent 69096e093a3d8ec
child 6922e948ecefdf1
Lock the module for the video encoder chip.
modules/em8300_i2c.c
     1.1 --- a/modules/em8300_i2c.c	Sat Sep 26 23:19:51 2009 +0200
     1.2 +++ b/modules/em8300_i2c.c	Sat Sep 26 23:55:15 2009 +0200
     1.3 @@ -116,6 +116,35 @@
     1.4  	.timeout = 100,
     1.5  };
     1.6  
     1.7 +static int em8300_i2c_lock_client(struct i2c_client *client)
     1.8 +{
     1.9 +	struct em8300_s *em = i2c_get_adapdata(client->adapter);
    1.10 +
    1.11 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
    1.12 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
    1.13 +	if (!try_module_get(client->driver->driver.owner))
    1.14 +#else
    1.15 +	if (!try_module_get(client->driver->owner))
    1.16 +#endif
    1.17 +	{
    1.18 +		printk(KERN_ERR "em8300-%d: i2c: Unable to lock client module\n", em->card_nr);
    1.19 +		return -ENODEV;
    1.20 +	}
    1.21 +#endif
    1.22 +	return 0;
    1.23 +}
    1.24 +
    1.25 +static void em8300_i2c_unlock_client(struct i2c_client *client)
    1.26 +{
    1.27 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
    1.28 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
    1.29 +	module_put(client->driver->driver.owner);
    1.30 +#else
    1.31 +	module_put(client->driver->owner);
    1.32 +#endif
    1.33 +#endif
    1.34 +}
    1.35 +
    1.36  static void em8300_adv717x_setup(struct em8300_s *em,
    1.37  				 struct i2c_client *client)
    1.38  {
    1.39 @@ -211,6 +240,7 @@
    1.40  			printk(KERN_WARNING "em8300-%d: unknown i2c chip found @0x6a\n", em->card_nr);
    1.41  			return -ENODEV;
    1.42  		}
    1.43 +		em8300_i2c_lock_client(client);
    1.44  		em8300_adv717x_setup(em, client);
    1.45  		em->encoder = client;
    1.46  		if (sysfs_create_link(&em->dev->dev.kobj, &client->dev.kobj, "encoder"))
    1.47 @@ -222,6 +252,7 @@
    1.48  			return -ENODEV;
    1.49  		}
    1.50  		em->encoder_type = ENCODER_BT865;
    1.51 +		em8300_i2c_lock_client(client);
    1.52  		em->encoder = client;
    1.53  		if (sysfs_create_link(&em->dev->dev.kobj, &client->dev.kobj, "encoder"))
    1.54  			printk(KERN_WARNING "em8300-%d: unable to create the encoder link\n", em->card_nr);
    1.55 @@ -244,6 +275,7 @@
    1.56  	}
    1.57  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
    1.58  	else if (client == em->encoder) {
    1.59 +		em8300_i2c_unlock_client(em->encoder);
    1.60  		em->encoder = NULL;
    1.61  		sysfs_remove_link(&em->dev->dev.kobj, "encoder");
    1.62  	}
    1.63 @@ -412,6 +444,7 @@
    1.64  	if (!em->encoder->driver)
    1.65  		printk(KERN_WARNING "em8300-%d: encoder chip found but no driver found within 5 seconds\n", em->card_nr);
    1.66  
    1.67 +	em8300_i2c_lock_client(em->encoder);
    1.68  	if (!strncmp(em->encoder->name, "ADV7175", 7)) {
    1.69  		em->encoder_type = ENCODER_ADV7175;
    1.70  		em8300_adv717x_setup(em, em->encoder);
    1.71 @@ -440,6 +473,7 @@
    1.72  #endif
    1.73  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
    1.74  	if (em->encoder) {
    1.75 +		em8300_i2c_unlock_client(em->encoder);
    1.76  		sysfs_remove_link(&em->dev->dev.kobj, "encoder");
    1.77  		i2c_unregister_device(em->encoder);
    1.78  		em->encoder = NULL;