Commit 18c40784 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: Don't assume i2c device probing always succeeds

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: default avatarTim Shepard <shep@alum.mit.edu>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 5da5b6f9
...@@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter, ...@@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter,
client = i2c_new_device(adapter, &info); client = i2c_new_device(adapter, &info);
if (!client) if (!client)
return -ENODEV; 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. * Let i2c-core delete that device on driver removal.
......
...@@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter) ...@@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
strlcpy(info.type, "keywest", I2C_NAME_SIZE); strlcpy(info.type, "keywest", I2C_NAME_SIZE);
info.addr = keywest_ctx->addr; info.addr = keywest_ctx->addr;
keywest_ctx->client = i2c_new_device(adapter, &info); 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. * Let i2c-core delete that device on driver removal.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment