Skip to content

Commit c02b211

Browse files
pinchartlMauro Carvalho Chehab
authored and
Mauro Carvalho Chehab
committed
[media] media: i2c: Convert to devm_kzalloc()
Using the managed function the kfree() calls can be removed from the probe error path and the remove handler. Signed-off-by: Laurent Pinchart <[email protected]> Acked-by: Sylwester Nawrocki <[email protected]> Acked-by: Lad, Prabhakar <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Reviewed-by: Benoît Thébaudeau <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 9532336 commit c02b211

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+79
-202
lines changed

drivers/media/i2c/ad9389b.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -1188,15 +1188,14 @@ static int ad9389b_probe(struct i2c_client *client, const struct i2c_device_id *
11881188
v4l_dbg(1, debug, client, "detecting ad9389b client on address 0x%x\n",
11891189
client->addr << 1);
11901190

1191-
state = kzalloc(sizeof(struct ad9389b_state), GFP_KERNEL);
1191+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
11921192
if (!state)
11931193
return -ENOMEM;
11941194

11951195
/* Platform data */
11961196
if (pdata == NULL) {
11971197
v4l_err(client, "No platform data!\n");
1198-
err = -ENODEV;
1199-
goto err_free;
1198+
return -ENODEV;
12001199
}
12011200
memcpy(&state->pdata, pdata, sizeof(state->pdata));
12021201

@@ -1276,8 +1275,6 @@ static int ad9389b_probe(struct i2c_client *client, const struct i2c_device_id *
12761275
media_entity_cleanup(&sd->entity);
12771276
err_hdl:
12781277
v4l2_ctrl_handler_free(&state->hdl);
1279-
err_free:
1280-
kfree(state);
12811278
return err;
12821279
}
12831280

@@ -1302,7 +1299,6 @@ static int ad9389b_remove(struct i2c_client *client)
13021299
v4l2_device_unregister_subdev(sd);
13031300
media_entity_cleanup(&sd->entity);
13041301
v4l2_ctrl_handler_free(sd->ctrl_handler);
1305-
kfree(get_ad9389b_state(sd));
13061302
return 0;
13071303
}
13081304

drivers/media/i2c/adp1653.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int adp1653_probe(struct i2c_client *client,
417417
if (client->dev.platform_data == NULL)
418418
return -ENODEV;
419419

420-
flash = kzalloc(sizeof(*flash), GFP_KERNEL);
420+
flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
421421
if (flash == NULL)
422422
return -ENOMEM;
423423

@@ -443,7 +443,6 @@ static int adp1653_probe(struct i2c_client *client,
443443

444444
free_and_quit:
445445
v4l2_ctrl_handler_free(&flash->ctrls);
446-
kfree(flash);
447446
return ret;
448447
}
449448

@@ -455,7 +454,7 @@ static int adp1653_remove(struct i2c_client *client)
455454
v4l2_device_unregister_subdev(&flash->subdev);
456455
v4l2_ctrl_handler_free(&flash->ctrls);
457456
media_entity_cleanup(&flash->subdev.entity);
458-
kfree(flash);
457+
459458
return 0;
460459
}
461460

drivers/media/i2c/adv7170.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static int adv7170_probe(struct i2c_client *client,
359359
v4l_info(client, "chip found @ 0x%x (%s)\n",
360360
client->addr << 1, client->adapter->name);
361361

362-
encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL);
362+
encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
363363
if (encoder == NULL)
364364
return -ENOMEM;
365365
sd = &encoder->sd;
@@ -384,7 +384,6 @@ static int adv7170_remove(struct i2c_client *client)
384384
struct v4l2_subdev *sd = i2c_get_clientdata(client);
385385

386386
v4l2_device_unregister_subdev(sd);
387-
kfree(to_adv7170(sd));
388387
return 0;
389388
}
390389

drivers/media/i2c/adv7175.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static int adv7175_probe(struct i2c_client *client,
409409
v4l_info(client, "chip found @ 0x%x (%s)\n",
410410
client->addr << 1, client->adapter->name);
411411

412-
encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL);
412+
encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
413413
if (encoder == NULL)
414414
return -ENOMEM;
415415
sd = &encoder->sd;
@@ -434,7 +434,6 @@ static int adv7175_remove(struct i2c_client *client)
434434
struct v4l2_subdev *sd = i2c_get_clientdata(client);
435435

436436
v4l2_device_unregister_subdev(sd);
437-
kfree(to_adv7175(sd));
438437
return 0;
439438
}
440439

drivers/media/i2c/adv7180.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int adv7180_probe(struct i2c_client *client,
555555
v4l_info(client, "chip found @ 0x%02x (%s)\n",
556556
client->addr, client->adapter->name);
557557

558-
state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL);
558+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
559559
if (state == NULL) {
560560
ret = -ENOMEM;
561561
goto err;
@@ -582,7 +582,6 @@ static int adv7180_probe(struct i2c_client *client,
582582
err_unreg_subdev:
583583
mutex_destroy(&state->mutex);
584584
v4l2_device_unregister_subdev(sd);
585-
kfree(state);
586585
err:
587586
printk(KERN_ERR KBUILD_MODNAME ": Failed to probe: %d\n", ret);
588587
return ret;
@@ -607,7 +606,6 @@ static int adv7180_remove(struct i2c_client *client)
607606

608607
mutex_destroy(&state->mutex);
609608
v4l2_device_unregister_subdev(sd);
610-
kfree(to_state(sd));
611609
return 0;
612610
}
613611

drivers/media/i2c/adv7183.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int adv7183_probe(struct i2c_client *client,
573573
if (pin_array == NULL)
574574
return -EINVAL;
575575

576-
decoder = kzalloc(sizeof(struct adv7183), GFP_KERNEL);
576+
decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
577577
if (decoder == NULL)
578578
return -ENOMEM;
579579

@@ -583,8 +583,7 @@ static int adv7183_probe(struct i2c_client *client,
583583
if (gpio_request_one(decoder->reset_pin, GPIOF_OUT_INIT_LOW,
584584
"ADV7183 Reset")) {
585585
v4l_err(client, "failed to request GPIO %d\n", decoder->reset_pin);
586-
ret = -EBUSY;
587-
goto err_free_decoder;
586+
return -EBUSY;
588587
}
589588

590589
if (gpio_request_one(decoder->oe_pin, GPIOF_OUT_INIT_HIGH,
@@ -646,8 +645,6 @@ static int adv7183_probe(struct i2c_client *client,
646645
gpio_free(decoder->oe_pin);
647646
err_free_reset:
648647
gpio_free(decoder->reset_pin);
649-
err_free_decoder:
650-
kfree(decoder);
651648
return ret;
652649
}
653650

@@ -660,7 +657,6 @@ static int adv7183_remove(struct i2c_client *client)
660657
v4l2_ctrl_handler_free(sd->ctrl_handler);
661658
gpio_free(decoder->oe_pin);
662659
gpio_free(decoder->reset_pin);
663-
kfree(decoder);
664660
return 0;
665661
}
666662

drivers/media/i2c/adv7393.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int adv7393_probe(struct i2c_client *client,
410410
v4l_info(client, "chip found @ 0x%x (%s)\n",
411411
client->addr << 1, client->adapter->name);
412412

413-
state = kzalloc(sizeof(struct adv7393_state), GFP_KERNEL);
413+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
414414
if (state == NULL)
415415
return -ENOMEM;
416416

@@ -444,16 +444,13 @@ static int adv7393_probe(struct i2c_client *client,
444444
int err = state->hdl.error;
445445

446446
v4l2_ctrl_handler_free(&state->hdl);
447-
kfree(state);
448447
return err;
449448
}
450449
v4l2_ctrl_handler_setup(&state->hdl);
451450

452451
err = adv7393_initialize(&state->sd);
453-
if (err) {
452+
if (err)
454453
v4l2_ctrl_handler_free(&state->hdl);
455-
kfree(state);
456-
}
457454
return err;
458455
}
459456

@@ -464,7 +461,6 @@ static int adv7393_remove(struct i2c_client *client)
464461

465462
v4l2_device_unregister_subdev(sd);
466463
v4l2_ctrl_handler_free(&state->hdl);
467-
kfree(state);
468464

469465
return 0;
470466
}

drivers/media/i2c/adv7604.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ static int adv7604_probe(struct i2c_client *client,
19681968
v4l_dbg(1, debug, client, "detecting adv7604 client on address 0x%x\n",
19691969
client->addr << 1);
19701970

1971-
state = kzalloc(sizeof(struct adv7604_state), GFP_KERNEL);
1971+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
19721972
if (!state) {
19731973
v4l_err(client, "Could not allocate adv7604_state memory!\n");
19741974
return -ENOMEM;
@@ -1977,8 +1977,7 @@ static int adv7604_probe(struct i2c_client *client,
19771977
/* platform data */
19781978
if (!pdata) {
19791979
v4l_err(client, "No platform data!\n");
1980-
err = -ENODEV;
1981-
goto err_state;
1980+
return -ENODEV;
19821981
}
19831982
memcpy(&state->pdata, pdata, sizeof(state->pdata));
19841983

@@ -1991,8 +1990,7 @@ static int adv7604_probe(struct i2c_client *client,
19911990
if (adv_smbus_read_byte_data_check(client, 0xfb, false) != 0x68) {
19921991
v4l2_info(sd, "not an adv7604 on address 0x%x\n",
19931992
client->addr << 1);
1994-
err = -ENODEV;
1995-
goto err_state;
1993+
return -ENODEV;
19961994
}
19971995

19981996
/* control handlers */
@@ -2093,8 +2091,6 @@ static int adv7604_probe(struct i2c_client *client,
20932091
adv7604_unregister_clients(state);
20942092
err_hdl:
20952093
v4l2_ctrl_handler_free(hdl);
2096-
err_state:
2097-
kfree(state);
20982094
return err;
20992095
}
21002096

@@ -2111,7 +2107,6 @@ static int adv7604_remove(struct i2c_client *client)
21112107
media_entity_cleanup(&sd->entity);
21122108
adv7604_unregister_clients(to_state(sd));
21132109
v4l2_ctrl_handler_free(sd->ctrl_handler);
2114-
kfree(to_state(sd));
21152110
return 0;
21162111
}
21172112

drivers/media/i2c/ak881x.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int ak881x_probe(struct i2c_client *client,
264264
return -EIO;
265265
}
266266

267-
ak881x = kzalloc(sizeof(struct ak881x), GFP_KERNEL);
267+
ak881x = devm_kzalloc(&client->dev, sizeof(*ak881x), GFP_KERNEL);
268268
if (!ak881x)
269269
return -ENOMEM;
270270

@@ -282,7 +282,6 @@ static int ak881x_probe(struct i2c_client *client,
282282
default:
283283
dev_err(&client->dev,
284284
"No ak881x chip detected, register read %x\n", data);
285-
kfree(ak881x);
286285
return -ENODEV;
287286
}
288287

@@ -331,7 +330,6 @@ static int ak881x_remove(struct i2c_client *client)
331330
struct ak881x *ak881x = to_ak881x(client);
332331

333332
v4l2_device_unregister_subdev(&ak881x->subdev);
334-
kfree(ak881x);
335333

336334
return 0;
337335
}

drivers/media/i2c/as3645a.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ static int as3645a_probe(struct i2c_client *client,
813813
if (client->dev.platform_data == NULL)
814814
return -ENODEV;
815815

816-
flash = kzalloc(sizeof(*flash), GFP_KERNEL);
816+
flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
817817
if (flash == NULL)
818818
return -ENOMEM;
819819

@@ -838,10 +838,8 @@ static int as3645a_probe(struct i2c_client *client,
838838
flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
839839

840840
done:
841-
if (ret < 0) {
841+
if (ret < 0)
842842
v4l2_ctrl_handler_free(&flash->ctrls);
843-
kfree(flash);
844-
}
845843

846844
return ret;
847845
}
@@ -855,7 +853,6 @@ static int as3645a_remove(struct i2c_client *client)
855853
v4l2_ctrl_handler_free(&flash->ctrls);
856854
media_entity_cleanup(&flash->subdev.entity);
857855
mutex_destroy(&flash->power_lock);
858-
kfree(flash);
859856

860857
return 0;
861858
}

drivers/media/i2c/bt819.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static int bt819_probe(struct i2c_client *client,
425425
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
426426
return -ENODEV;
427427

428-
decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL);
428+
decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
429429
if (decoder == NULL)
430430
return -ENOMEM;
431431
sd = &decoder->sd;
@@ -476,7 +476,6 @@ static int bt819_probe(struct i2c_client *client,
476476
int err = decoder->hdl.error;
477477

478478
v4l2_ctrl_handler_free(&decoder->hdl);
479-
kfree(decoder);
480479
return err;
481480
}
482481
v4l2_ctrl_handler_setup(&decoder->hdl);
@@ -490,7 +489,6 @@ static int bt819_remove(struct i2c_client *client)
490489

491490
v4l2_device_unregister_subdev(sd);
492491
v4l2_ctrl_handler_free(&decoder->hdl);
493-
kfree(decoder);
494492
return 0;
495493
}
496494

drivers/media/i2c/bt856.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int bt856_probe(struct i2c_client *client,
216216
v4l_info(client, "chip found @ 0x%x (%s)\n",
217217
client->addr << 1, client->adapter->name);
218218

219-
encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL);
219+
encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
220220
if (encoder == NULL)
221221
return -ENOMEM;
222222
sd = &encoder->sd;
@@ -250,7 +250,6 @@ static int bt856_remove(struct i2c_client *client)
250250
struct v4l2_subdev *sd = i2c_get_clientdata(client);
251251

252252
v4l2_device_unregister_subdev(sd);
253-
kfree(to_bt856(sd));
254253
return 0;
255254
}
256255

drivers/media/i2c/bt866.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int bt866_probe(struct i2c_client *client,
207207
v4l_info(client, "chip found @ 0x%x (%s)\n",
208208
client->addr << 1, client->adapter->name);
209209

210-
encoder = kzalloc(sizeof(*encoder), GFP_KERNEL);
210+
encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
211211
if (encoder == NULL)
212212
return -ENOMEM;
213213
sd = &encoder->sd;
@@ -220,7 +220,6 @@ static int bt866_remove(struct i2c_client *client)
220220
struct v4l2_subdev *sd = i2c_get_clientdata(client);
221221

222222
v4l2_device_unregister_subdev(sd);
223-
kfree(to_bt866(sd));
224223
return 0;
225224
}
226225

drivers/media/i2c/cs5345.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int cs5345_probe(struct i2c_client *client,
190190
v4l_info(client, "chip found @ 0x%x (%s)\n",
191191
client->addr << 1, client->adapter->name);
192192

193-
state = kzalloc(sizeof(struct cs5345_state), GFP_KERNEL);
193+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
194194
if (state == NULL)
195195
return -ENOMEM;
196196
sd = &state->sd;
@@ -206,7 +206,6 @@ static int cs5345_probe(struct i2c_client *client,
206206
int err = state->hdl.error;
207207

208208
v4l2_ctrl_handler_free(&state->hdl);
209-
kfree(state);
210209
return err;
211210
}
212211
/* set volume/mute */
@@ -227,7 +226,6 @@ static int cs5345_remove(struct i2c_client *client)
227226

228227
v4l2_device_unregister_subdev(sd);
229228
v4l2_ctrl_handler_free(&state->hdl);
230-
kfree(state);
231229
return 0;
232230
}
233231

drivers/media/i2c/cs53l32a.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int cs53l32a_probe(struct i2c_client *client,
175175
v4l_info(client, "chip found @ 0x%x (%s)\n",
176176
client->addr << 1, client->adapter->name);
177177

178-
state = kzalloc(sizeof(struct cs53l32a_state), GFP_KERNEL);
178+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
179179
if (state == NULL)
180180
return -ENOMEM;
181181
sd = &state->sd;
@@ -197,7 +197,6 @@ static int cs53l32a_probe(struct i2c_client *client,
197197
int err = state->hdl.error;
198198

199199
v4l2_ctrl_handler_free(&state->hdl);
200-
kfree(state);
201200
return err;
202201
}
203202

@@ -228,7 +227,6 @@ static int cs53l32a_remove(struct i2c_client *client)
228227

229228
v4l2_device_unregister_subdev(sd);
230229
v4l2_ctrl_handler_free(&state->hdl);
231-
kfree(state);
232230
return 0;
233231
}
234232

0 commit comments

Comments
 (0)