--- zzzz-none-000/linux-3.10.107/drivers/regulator/lp3971.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/regulator/lp3971.c 2021-02-04 17:41:59.000000000 +0000 @@ -25,8 +25,6 @@ struct device *dev; struct mutex io_lock; struct i2c_client *i2c; - int num_regulators; - struct regulator_dev **rdev; }; static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg); @@ -329,7 +327,7 @@ return -EIO; ret = i2c_smbus_read_byte_data(i2c, reg); if (ret < 0) - return -EIO; + return ret; *dest = ret; return 0; @@ -383,49 +381,34 @@ { int i, err; - lp3971->num_regulators = pdata->num_regulators; - lp3971->rdev = kcalloc(pdata->num_regulators, - sizeof(struct regulator_dev *), GFP_KERNEL); - if (!lp3971->rdev) { - err = -ENOMEM; - goto err_nomem; - } - /* Instantiate the regulators */ for (i = 0; i < pdata->num_regulators; i++) { struct regulator_config config = { }; struct lp3971_regulator_subdev *reg = &pdata->regulators[i]; + struct regulator_dev *rdev; config.dev = lp3971->dev; config.init_data = reg->initdata; config.driver_data = lp3971; - lp3971->rdev[i] = regulator_register(®ulators[reg->id], - &config); - if (IS_ERR(lp3971->rdev[i])) { - err = PTR_ERR(lp3971->rdev[i]); + rdev = devm_regulator_register(lp3971->dev, + ®ulators[reg->id], &config); + if (IS_ERR(rdev)) { + err = PTR_ERR(rdev); dev_err(lp3971->dev, "regulator init failed: %d\n", err); - goto error; + return err; } } return 0; - -error: - while (--i >= 0) - regulator_unregister(lp3971->rdev[i]); - kfree(lp3971->rdev); - lp3971->rdev = NULL; -err_nomem: - return err; } static int lp3971_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct lp3971 *lp3971; - struct lp3971_platform_data *pdata = i2c->dev.platform_data; + struct lp3971_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret; u16 val; @@ -434,7 +417,7 @@ return -ENODEV; } - lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL); + lp3971 = devm_kzalloc(&i2c->dev, sizeof(struct lp3971), GFP_KERNEL); if (lp3971 == NULL) return -ENOMEM; @@ -449,48 +432,28 @@ ret = -ENODEV; if (ret < 0) { dev_err(&i2c->dev, "failed to detect device\n"); - goto err_detect; + return ret; } ret = setup_regulators(lp3971, pdata); if (ret < 0) - goto err_detect; + return ret; i2c_set_clientdata(i2c, lp3971); return 0; - -err_detect: - kfree(lp3971); - return ret; -} - -static int lp3971_i2c_remove(struct i2c_client *i2c) -{ - struct lp3971 *lp3971 = i2c_get_clientdata(i2c); - int i; - - for (i = 0; i < lp3971->num_regulators; i++) - regulator_unregister(lp3971->rdev[i]); - - kfree(lp3971->rdev); - kfree(lp3971); - - return 0; } static const struct i2c_device_id lp3971_i2c_id[] = { - { "lp3971", 0 }, - { } + { "lp3971", 0 }, + { } }; MODULE_DEVICE_TABLE(i2c, lp3971_i2c_id); static struct i2c_driver lp3971_i2c_driver = { .driver = { .name = "LP3971", - .owner = THIS_MODULE, }, .probe = lp3971_i2c_probe, - .remove = lp3971_i2c_remove, .id_table = lp3971_i2c_id, };