Skip to content

Commit 18c4078

Browse files
committed
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: Tim Shepard <shep@alum.mit.edu> Cc: Jean Delvare <khali@linux-fr.org> Cc: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 5da5b6f commit 18c4078

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎sound/aoa/codecs/tas.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter,
897897
client = i2c_new_device(adapter, &info);
898898
if (!client)
899899
return -ENODEV;
900+
/*
901+
* We know the driver is already loaded, so the device should be
902+
* already bound. If not it means binding failed, and then there
903+
* is no point in keeping the device instantiated.
904+
*/
905+
if (!client->driver) {
906+
i2c_unregister_device(client);
907+
return -ENODEV;
908+
}
900909

901910
/*
902911
* Let i2c-core delete that device on driver removal.

‎sound/ppc/keywest.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
5959
strlcpy(info.type, "keywest", I2C_NAME_SIZE);
6060
info.addr = keywest_ctx->addr;
6161
keywest_ctx->client = i2c_new_device(adapter, &info);
62+
if (!keywest_ctx->client)
63+
return -ENODEV;
64+
/*
65+
* We know the driver is already loaded, so the device should be
66+
* already bound. If not it means binding failed, and then there
67+
* is no point in keeping the device instantiated.
68+
*/
69+
if (!keywest_ctx->client->driver) {
70+
i2c_unregister_device(keywest_ctx->client);
71+
keywest_ctx->client = NULL;
72+
return -ENODEV;
73+
}
6274

6375
/*
6476
* Let i2c-core delete that device on driver removal.

0 commit comments

Comments
 (0)