Skip to content

Commit

Permalink
i2c: i2c_use_client() defends against NULL
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Brownell authored and Jean Delvare committed Jul 14, 2008
1 parent a1cdeda commit 6ea438e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 6ea438e

Please sign in to comment.