Message ID | 20230227021720.1578781-1-void0red@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | hwmon: add a check of devm_add_action | expand |
On 2/26/23 18:17, Kang Chen wrote: > devm_add_action may fails, do the cleanup when if fails. > > Signed-off-by: Kang Chen <void0red@gmail.com> > --- > drivers/hwmon/g762.c | 6 +++++- > drivers/hwmon/nzxt-smart2.c | 4 +++- Two patches, please. Guenter > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c > index 64a0599b2..d06d8bf20 100644 > --- a/drivers/hwmon/g762.c > +++ b/drivers/hwmon/g762.c > @@ -620,7 +620,11 @@ static int g762_of_clock_enable(struct i2c_client *client) > data = i2c_get_clientdata(client); > data->clk = clk; > > - devm_add_action(&client->dev, g762_of_clock_disable, data); > + ret = devm_add_action(&client->dev, g762_of_clock_disable, data); > + if (ret) { > + dev_err(&client->dev, "failed to add disable clock action\n"); > + goto clk_unprep; > + } > return 0; > > clk_unprep: > diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c > index 2b93ba896..725974cb3 100644 > --- a/drivers/hwmon/nzxt-smart2.c > +++ b/drivers/hwmon/nzxt-smart2.c > @@ -737,8 +737,10 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, > init_waitqueue_head(&drvdata->wq); > > mutex_init(&drvdata->mutex); > - devm_add_action(&hdev->dev, (void (*)(void *))mutex_destroy, > + ret = devm_add_action(&hdev->dev, (void (*)(void *))mutex_destroy, > &drvdata->mutex); > + if (ret) > + return ret; > > ret = hid_parse(hdev); > if (ret)
diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index 64a0599b2..d06d8bf20 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c @@ -620,7 +620,11 @@ static int g762_of_clock_enable(struct i2c_client *client) data = i2c_get_clientdata(client); data->clk = clk; - devm_add_action(&client->dev, g762_of_clock_disable, data); + ret = devm_add_action(&client->dev, g762_of_clock_disable, data); + if (ret) { + dev_err(&client->dev, "failed to add disable clock action\n"); + goto clk_unprep; + } return 0; clk_unprep: diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c index 2b93ba896..725974cb3 100644 --- a/drivers/hwmon/nzxt-smart2.c +++ b/drivers/hwmon/nzxt-smart2.c @@ -737,8 +737,10 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, init_waitqueue_head(&drvdata->wq); mutex_init(&drvdata->mutex); - devm_add_action(&hdev->dev, (void (*)(void *))mutex_destroy, + ret = devm_add_action(&hdev->dev, (void (*)(void *))mutex_destroy, &drvdata->mutex); + if (ret) + return ret; ret = hid_parse(hdev); if (ret)
devm_add_action may fails, do the cleanup when if fails. Signed-off-by: Kang Chen <void0red@gmail.com> --- drivers/hwmon/g762.c | 6 +++++- drivers/hwmon/nzxt-smart2.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-)