Skip to content

Commit 06f0bba

Browse files
committed
use managed memory allocation
Use managed memory allocation where possible to simplify release and error paths. Also use devm_kzalloc where kmalloc is used, since devm_kmalloc came as late as 3.13.
1 parent 6da6543 commit 06f0bba

File tree

4 files changed

+22
-53
lines changed

4 files changed

+22
-53
lines changed

fb_ssd1351.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ static void register_onboard_backlight(struct fbtft_par *par)
215215

216216
fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
217217

218-
bl_ops = kzalloc(sizeof(struct backlight_ops), GFP_KERNEL);
218+
bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
219+
GFP_KERNEL);
219220
if (!bl_ops) {
220221
dev_err(par->info->device,
221222
"%s: could not allocate memory for backlight operations.\n",
@@ -233,16 +234,12 @@ static void register_onboard_backlight(struct fbtft_par *par)
233234
dev_err(par->info->device,
234235
"cannot register backlight device (%ld)\n",
235236
PTR_ERR(bd));
236-
goto failed;
237+
return;
237238
}
238239
par->info->bl_dev = bd;
239240

240241
if (!par->fbtftops.unregister_backlight)
241242
par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
242-
243-
return;
244-
failed:
245-
kfree(bl_ops);
246243
}
247244
#else
248245
static void register_onboard_backlight(struct fbtft_par *par) { };

fb_watterott.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ static void register_chip_backlight(struct fbtft_par *par)
265265

266266
fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
267267

268-
bl_ops = kzalloc(sizeof(struct backlight_ops), GFP_KERNEL);
268+
bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
269+
GFP_KERNEL);
269270
if (!bl_ops) {
270271
dev_err(par->info->device,
271272
"%s: could not allocate memory for backlight operations.\n",
@@ -285,16 +286,12 @@ static void register_chip_backlight(struct fbtft_par *par)
285286
dev_err(par->info->device,
286287
"cannot register backlight device (%ld)\n",
287288
PTR_ERR(bd));
288-
goto failed;
289+
return;
289290
}
290291
par->info->bl_dev = bd;
291292

292293
if (!par->fbtftops.unregister_backlight)
293294
par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
294-
295-
return;
296-
failed:
297-
kfree(bl_ops);
298295
}
299296
#else
300297
#define register_chip_backlight NULL

fbtft-core.c

+12-35
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ void fbtft_unregister_backlight(struct fbtft_par *par)
235235
bl_ops = par->info->bl_dev->ops;
236236
backlight_device_unregister(par->info->bl_dev);
237237
par->info->bl_dev = NULL;
238-
kfree(bl_ops);
239238
}
240239
}
241240

@@ -253,7 +252,8 @@ void fbtft_register_backlight(struct fbtft_par *par)
253252
return;
254253
}
255254

256-
bl_ops = kzalloc(sizeof(struct backlight_ops), GFP_KERNEL);
255+
bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
256+
GFP_KERNEL);
257257
if (!bl_ops) {
258258
dev_err(par->info->device,
259259
"%s: could not allocate memeory for backlight operations.\n",
@@ -275,17 +275,12 @@ void fbtft_register_backlight(struct fbtft_par *par)
275275
dev_err(par->info->device,
276276
"cannot register backlight device (%ld)\n",
277277
PTR_ERR(bd));
278-
goto failed;
278+
return;
279279
}
280280
par->info->bl_dev = bd;
281281

282282
if (!par->fbtftops.unregister_backlight)
283283
par->fbtftops.unregister_backlight = fbtft_unregister_backlight;
284-
285-
return;
286-
287-
failed:
288-
kfree(bl_ops);
289284
}
290285
#else
291286
void fbtft_register_backlight(struct fbtft_par *par) { };
@@ -715,20 +710,21 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
715710
if (!vmem)
716711
goto alloc_fail;
717712

718-
fbops = kzalloc(sizeof(struct fb_ops), GFP_KERNEL);
713+
fbops = devm_kzalloc(dev, sizeof(struct fb_ops), GFP_KERNEL);
719714
if (!fbops)
720715
goto alloc_fail;
721716

722-
fbdefio = kzalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
717+
fbdefio = devm_kzalloc(dev, sizeof(struct fb_deferred_io), GFP_KERNEL);
723718
if (!fbdefio)
724719
goto alloc_fail;
725720

726-
buf = kmalloc(128, GFP_KERNEL);
721+
buf = devm_kzalloc(dev, 128, GFP_KERNEL);
727722
if (!buf)
728723
goto alloc_fail;
729724

730725
if (display->gamma_num && display->gamma_len) {
731-
gamma_curves = kzalloc(display->gamma_num * display->gamma_len * sizeof(gamma_curves[0]), GFP_KERNEL);
726+
gamma_curves = devm_kzalloc(dev, display->gamma_num * display->gamma_len * sizeof(gamma_curves[0]),
727+
GFP_KERNEL);
732728
if (!gamma_curves)
733729
goto alloc_fail;
734730
}
@@ -815,9 +811,9 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
815811
if (txbuflen > 0) {
816812
if (dma) {
817813
dev->coherent_dma_mask = ~0;
818-
txbuf = dma_alloc_coherent(dev, txbuflen, &par->txbuf.dma, GFP_DMA);
814+
txbuf = dmam_alloc_coherent(dev, txbuflen, &par->txbuf.dma, GFP_DMA);
819815
} else {
820-
txbuf = kmalloc(txbuflen, GFP_KERNEL);
816+
txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
821817
}
822818
if (!txbuf)
823819
goto alloc_fail;
@@ -846,10 +842,6 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
846842

847843
alloc_fail:
848844
vfree(vmem);
849-
kfree(buf);
850-
kfree(fbops);
851-
kfree(fbdefio);
852-
kfree(gamma_curves);
853845

854846
return NULL;
855847
}
@@ -863,20 +855,8 @@ EXPORT_SYMBOL(fbtft_framebuffer_alloc);
863855
*/
864856
void fbtft_framebuffer_release(struct fb_info *info)
865857
{
866-
struct fbtft_par *par = info->par;
867-
868858
fb_deferred_io_cleanup(info);
869859
vfree(info->screen_base);
870-
if (par->txbuf.buf) {
871-
if (par->txbuf.dma)
872-
dma_free_coherent(info->device, par->txbuf.len, par->txbuf.buf, par->txbuf.dma);
873-
else
874-
kfree(par->txbuf.buf);
875-
}
876-
kfree(par->buf);
877-
kfree(info->fbops);
878-
kfree(info->fbdefio);
879-
kfree(par->gamma.curves);
880860
framebuffer_release(info);
881861
}
882862
EXPORT_SYMBOL(fbtft_framebuffer_release);
@@ -1273,7 +1253,7 @@ int fbtft_probe_common(struct fbtft_display *display,
12731253
if (ret)
12741254
goto out_release;
12751255
/* allocate buffer with room for dc bits */
1276-
par->extra = kmalloc(
1256+
par->extra = devm_kzalloc(par->info->device,
12771257
par->txbuf.len + (par->txbuf.len / 8) + 8,
12781258
GFP_KERNEL);
12791259
if (!par->extra) {
@@ -1327,12 +1307,9 @@ int fbtft_remove_common(struct device *dev, struct fb_info *info)
13271307
if (!info)
13281308
return -EINVAL;
13291309
par = info->par;
1330-
if (par) {
1310+
if (par)
13311311
fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par,
13321312
"%s()\n", __func__);
1333-
if (par->extra)
1334-
kfree(par->extra);
1335-
}
13361313
fbtft_unregister_framebuffer(info);
13371314
fbtft_framebuffer_release(info);
13381315

flexfb.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,9 @@ static int flexfb_probe_common(struct spi_device *sdev, struct platform_device *
433433
if (ret)
434434
goto out_release;
435435
/* allocate buffer with room for dc bits */
436-
par->extra = vzalloc(par->txbuf.len +
437-
(par->txbuf.len / 8) + 8);
436+
par->extra = devm_kzalloc(par->info->device,
437+
par->txbuf.len + (par->txbuf.len / 8) + 8,
438+
GFP_KERNEL);
438439
if (!par->extra) {
439440
ret = -ENOMEM;
440441
goto out_release;
@@ -508,12 +509,9 @@ static int flexfb_remove_common(struct device *dev, struct fb_info *info)
508509
if (!info)
509510
return -EINVAL;
510511
par = info->par;
511-
if (par) {
512+
if (par)
512513
fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par,
513514
"%s()\n", __func__);
514-
if (par->extra)
515-
vfree(par->extra);
516-
}
517515
fbtft_unregister_framebuffer(info);
518516
fbtft_framebuffer_release(info);
519517

0 commit comments

Comments
 (0)