]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
i2c: i2c_use_client() defends against NULL
authorDavid Brownell <david-b@pacbell.net>
Mon, 14 Jul 2008 20:38:24 +0000 (22:38 +0200)
committerJean Delvare <khali@mahadeva.delvare>
Mon, 14 Jul 2008 20:38:24 +0000 (22:38 +0200)
Defend the i2c refcount calls against NULL pointers, as is important
(and conventional) for such calls.  Note that none of the current
callers of i2c_use_client() use its return value.

[JD: I hate this but apparently all the other subsystems do it so...]

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
drivers/i2c/i2c-core.c

index 527d51319f3c50c17262a21bdf172653057ca85f..b995502400b832181912e56982af6a1ca6116687 100644 (file)
@@ -866,8 +866,9 @@ EXPORT_SYMBOL(i2c_detach_client);
  */
 struct i2c_client *i2c_use_client(struct i2c_client *client)
 {
-       get_device(&client->dev);
-       return client;
+       if (client && get_device(&client->dev))
+               return client;
+       return NULL;
 }
 EXPORT_SYMBOL(i2c_use_client);
 
@@ -879,7 +880,8 @@ EXPORT_SYMBOL(i2c_use_client);
  */
 void i2c_release_client(struct i2c_client *client)
 {
-       put_device(&client->dev);
+       if (client)
+               put_device(&client->dev);
 }
 EXPORT_SYMBOL(i2c_release_client);