Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: lm8333 - convert to use devm_* api

Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Link: https://lore.kernel.org/r/20230714080611.81302-1-frank.li@vivo.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Yangtao Li and committed by
Dmitry Torokhov
2b6aa9e7 bf93349b

+14 -30
+14 -30
drivers/input/keyboard/lm8333.c
··· 142 142 return -EINVAL; 143 143 } 144 144 145 - lm8333 = kzalloc(sizeof(*lm8333), GFP_KERNEL); 146 - input = input_allocate_device(); 147 - if (!lm8333 || !input) { 148 - err = -ENOMEM; 149 - goto free_mem; 150 - } 145 + lm8333 = devm_kzalloc(&client->dev, sizeof(*lm8333), GFP_KERNEL); 146 + if (!lm8333) 147 + return -ENOMEM; 148 + 149 + input = devm_input_allocate_device(&client->dev); 150 + if (!input) 151 + return -ENOMEM; 151 152 152 153 lm8333->client = client; 153 154 lm8333->input = input; 154 155 155 156 input->name = client->name; 156 - input->dev.parent = &client->dev; 157 157 input->id.bustype = BUS_I2C; 158 158 159 159 input_set_capability(input, EV_MSC, MSC_SCAN); ··· 162 162 LM8333_NUM_ROWS, LM8333_NUM_COLS, 163 163 lm8333->keycodes, input); 164 164 if (err) 165 - goto free_mem; 165 + return err; 166 166 167 167 if (pdata->debounce_time) { 168 168 err = lm8333_write8(lm8333, LM8333_DEBOUNCE, ··· 178 178 dev_warn(&client->dev, "Unable to set active time\n"); 179 179 } 180 180 181 - err = request_threaded_irq(client->irq, NULL, lm8333_irq_thread, 182 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 183 - "lm8333", lm8333); 181 + err = devm_request_threaded_irq(&client->dev, client->irq, 182 + NULL, lm8333_irq_thread, 183 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 184 + "lm8333", lm8333); 184 185 if (err) 185 - goto free_mem; 186 + return err; 186 187 187 188 err = input_register_device(input); 188 189 if (err) 189 - goto free_irq; 190 + return err; 190 191 191 192 i2c_set_clientdata(client, lm8333); 192 193 return 0; 193 - 194 - free_irq: 195 - free_irq(client->irq, lm8333); 196 - free_mem: 197 - input_free_device(input); 198 - kfree(lm8333); 199 - return err; 200 - } 201 - 202 - static void lm8333_remove(struct i2c_client *client) 203 - { 204 - struct lm8333 *lm8333 = i2c_get_clientdata(client); 205 - 206 - free_irq(client->irq, lm8333); 207 - input_unregister_device(lm8333->input); 208 - kfree(lm8333); 209 194 } 210 195 211 196 static const struct i2c_device_id lm8333_id[] = { ··· 204 219 .name = "lm8333", 205 220 }, 206 221 .probe = lm8333_probe, 207 - .remove = lm8333_remove, 208 222 .id_table = lm8333_id, 209 223 }; 210 224 module_i2c_driver(lm8333_driver);