Commit fb5cc65f authored by Nuno Sa's avatar Nuno Sa Committed by Dmitry Torokhov

Input: adp5589-keys - fix NULL pointer dereference

We register a devm action to call adp5589_clear_config() and then pass
the i2c client as argument so that we can call i2c_get_clientdata() in
order to get our device object. However, i2c_set_clientdata() is only
being set at the end of the probe function which means that we'll get a
NULL pointer dereference in case the probe function fails early.

Fixes: 30df385e ("Input: adp5589-keys - use devm_add_action_or_reset() for register clear")
Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20241001-b4-dev-adp5589-fw-conversion-v1-1-fca0149dfc47@analog.com
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent a3f9a74d
...@@ -936,10 +936,9 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid) ...@@ -936,10 +936,9 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid)
static void adp5589_clear_config(void *data) static void adp5589_clear_config(void *data)
{ {
struct i2c_client *client = data; struct adp5589_kpad *kpad = data;
struct adp5589_kpad *kpad = i2c_get_clientdata(client);
adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0); adp5589_write(kpad->client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
} }
static int adp5589_probe(struct i2c_client *client) static int adp5589_probe(struct i2c_client *client)
...@@ -983,7 +982,7 @@ static int adp5589_probe(struct i2c_client *client) ...@@ -983,7 +982,7 @@ static int adp5589_probe(struct i2c_client *client)
} }
error = devm_add_action_or_reset(&client->dev, adp5589_clear_config, error = devm_add_action_or_reset(&client->dev, adp5589_clear_config,
client); kpad);
if (error) if (error)
return error; return error;
...@@ -1010,8 +1009,6 @@ static int adp5589_probe(struct i2c_client *client) ...@@ -1010,8 +1009,6 @@ static int adp5589_probe(struct i2c_client *client)
if (error) if (error)
return error; return error;
i2c_set_clientdata(client, kpad);
dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
return 0; return 0;
} }
......
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