Skip to content

Commit e1af5c8

Browse files
andy-shevpavelmachek
authored andcommitted
leds: is31fl319x: Fix devm vs. non-devm ordering
When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org> Signed-off-by: Pavel Machek <pavel@ucw.cz>
1 parent 0d77252 commit e1af5c8

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

drivers/leds/leds-is31fl319x.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,13 @@ static int is31fl319x_probe(struct i2c_client *client,
511511
return -ENOMEM;
512512

513513
mutex_init(&is31->lock);
514+
err = devm_add_action(dev, (void (*)(void *))mutex_destroy, &is31->lock);
515+
if (err)
516+
return err;
514517

515518
err = is31fl319x_parse_fw(&client->dev, is31);
516519
if (err)
517-
goto free_mutex;
520+
return err;
518521

519522
if (is31->shutdown_gpio) {
520523
gpiod_direction_output(is31->shutdown_gpio, 0);
@@ -524,19 +527,15 @@ static int is31fl319x_probe(struct i2c_client *client,
524527

525528
is31->client = client;
526529
is31->regmap = devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regmap_config);
527-
if (IS_ERR(is31->regmap)) {
528-
err = dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate register map\n");
529-
goto free_mutex;
530-
}
530+
if (IS_ERR(is31->regmap))
531+
return dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate register map\n");
531532

532533
i2c_set_clientdata(client, is31);
533534

534535
/* check for write-reply from chip (we can't read any registers) */
535536
err = regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00);
536-
if (err < 0) {
537-
err = dev_err_probe(dev, err, "no response from chip write\n");
538-
goto free_mutex;
539-
}
537+
if (err < 0)
538+
return dev_err_probe(dev, err, "no response from chip write\n");
540539

541540
/*
542541
* Kernel conventions require per-LED led-max-microamp property.
@@ -568,22 +567,10 @@ static int is31fl319x_probe(struct i2c_client *client,
568567

569568
err = devm_led_classdev_register(&client->dev, &led->cdev);
570569
if (err < 0)
571-
goto free_mutex;
570+
return err;
572571
}
573572

574573
return 0;
575-
576-
free_mutex:
577-
mutex_destroy(&is31->lock);
578-
return err;
579-
}
580-
581-
static int is31fl319x_remove(struct i2c_client *client)
582-
{
583-
struct is31fl319x_chip *is31 = i2c_get_clientdata(client);
584-
585-
mutex_destroy(&is31->lock);
586-
return 0;
587574
}
588575

589576
/*
@@ -611,7 +598,6 @@ static struct i2c_driver is31fl319x_driver = {
611598
.of_match_table = of_is31fl319x_match,
612599
},
613600
.probe = is31fl319x_probe,
614-
.remove = is31fl319x_remove,
615601
.id_table = is31fl319x_id,
616602
};
617603

0 commit comments

Comments
 (0)