Skip to content

Commit

Permalink
ALSA: Don't assume i2c device probing always succeeds
Browse files Browse the repository at this point in the history
The client->driver pointer can be NULL when i2c-device probing fails
in i2c_new_device().  This patch adds the NULL checks for client->driver
and return the error instead of blind assumption of driver availability.

Reported-by: Tim Shepard <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Johannes Berg <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Oct 1, 2009
1 parent 5da5b6f commit 18c4078
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sound/aoa/codecs/tas.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter,
client = i2c_new_device(adapter, &info);
if (!client)
return -ENODEV;
/*
* We know the driver is already loaded, so the device should be
* already bound. If not it means binding failed, and then there
* is no point in keeping the device instantiated.
*/
if (!client->driver) {
i2c_unregister_device(client);
return -ENODEV;
}

/*
* Let i2c-core delete that device on driver removal.
Expand Down
12 changes: 12 additions & 0 deletions sound/ppc/keywest.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
strlcpy(info.type, "keywest", I2C_NAME_SIZE);
info.addr = keywest_ctx->addr;
keywest_ctx->client = i2c_new_device(adapter, &info);
if (!keywest_ctx->client)
return -ENODEV;
/*
* We know the driver is already loaded, so the device should be
* already bound. If not it means binding failed, and then there
* is no point in keeping the device instantiated.
*/
if (!keywest_ctx->client->driver) {
i2c_unregister_device(keywest_ctx->client);
keywest_ctx->client = NULL;
return -ENODEV;
}

/*
* Let i2c-core delete that device on driver removal.
Expand Down

0 comments on commit 18c4078

Please sign in to comment.