--- zzzz-none-000/linux-3.10.107/drivers/misc/bh1780gli.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/misc/bh1780gli.c 2021-02-04 17:41:59.000000000 +0000 @@ -23,6 +23,7 @@ #include #include #include +#include #define BH1780_REG_CONTROL 0x80 #define BH1780_REG_PARTID 0x8A @@ -107,7 +108,7 @@ unsigned long val; int error; - error = strict_strtoul(buf, 0, &val); + error = kstrtoul(buf, 0, &val); if (error) return error; @@ -148,50 +149,35 @@ const struct i2c_device_id *id) { int ret; - struct bh1780_data *ddata = NULL; + struct bh1780_data *ddata; struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { - ret = -EIO; - goto err_op_failed; - } + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) + return -EIO; - ddata = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL); - if (ddata == NULL) { - ret = -ENOMEM; - goto err_op_failed; - } + ddata = devm_kzalloc(&client->dev, sizeof(struct bh1780_data), + GFP_KERNEL); + if (ddata == NULL) + return -ENOMEM; ddata->client = client; i2c_set_clientdata(client, ddata); ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID"); if (ret < 0) - goto err_op_failed; + return ret; dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n", (ret & BH1780_REVMASK)); mutex_init(&ddata->lock); - ret = sysfs_create_group(&client->dev.kobj, &bh1780_attr_group); - if (ret) - goto err_op_failed; - - return 0; - -err_op_failed: - kfree(ddata); - return ret; + return sysfs_create_group(&client->dev.kobj, &bh1780_attr_group); } static int bh1780_remove(struct i2c_client *client) { - struct bh1780_data *ddata; - - ddata = i2c_get_clientdata(client); sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group); - kfree(ddata); return 0; } @@ -244,6 +230,17 @@ { }, }; +MODULE_DEVICE_TABLE(i2c, bh1780_id); + +#ifdef CONFIG_OF +static const struct of_device_id of_bh1780_match[] = { + { .compatible = "rohm,bh1780gli", }, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_bh1780_match); +#endif + static struct i2c_driver bh1780_driver = { .probe = bh1780_probe, .remove = bh1780_remove, @@ -251,6 +248,7 @@ .driver = { .name = "bh1780", .pm = &bh1780_pm, + .of_match_table = of_match_ptr(of_bh1780_match), }, };