* [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() @ 2017-04-26 9:20 ` SF Markus Elfring 2017-05-11 14:27 ` Bartlomiej Zolnierkiewicz 0 siblings, 1 reply; 4+ messages in thread From: SF Markus Elfring @ 2017-04-26 9:20 UTC (permalink / raw) To: linux-fbdev, linux-omap, Bartlomiej Zolnierkiewicz, Tomi Valkeinen Cc: LKML, kernel-janitors From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 26 Apr 2017 11:08:30 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kcalloc". * Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/omap2/omapfb/vrfb.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/video/fbdev/omap2/omapfb/vrfb.c b/drivers/video/fbdev/omap2/omapfb/vrfb.c index f346b02eee1d..54b51a7a290a 100644 --- a/drivers/video/fbdev/omap2/omapfb/vrfb.c +++ b/drivers/video/fbdev/omap2/omapfb/vrfb.c @@ -358,11 +358,7 @@ static int __init vrfb_probe(struct platform_device *pdev) return PTR_ERR(vrfb_base); num_ctxs = pdev->num_resources - 1; - - ctxs = devm_kzalloc(&pdev->dev, - sizeof(struct vrfb_ctx) * num_ctxs, - GFP_KERNEL); - + ctxs = devm_kcalloc(&pdev->dev, num_ctxs, sizeof(*ctxs), GFP_KERNEL); if (!ctxs) return -ENOMEM; -- 2.12.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() 2017-04-26 9:20 ` [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() SF Markus Elfring @ 2017-05-11 14:27 ` Bartlomiej Zolnierkiewicz 2017-05-11 15:22 ` Bartlomiej Zolnierkiewicz 0 siblings, 1 reply; 4+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2017-05-11 14:27 UTC (permalink / raw) To: SF Markus Elfring Cc: linux-fbdev, linux-omap, Tomi Valkeinen, LKML, kernel-janitors Hi, On Wednesday, April 26, 2017 11:20:07 AM SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 26 Apr 2017 11:08:30 +0200 > > * A multiplication for the size determination of a memory allocation > indicated that an array data structure should be processed. > Thus use the corresponding function "devm_kcalloc". > > * Replace the specification of a data structure by a pointer dereference > to make the corresponding size determination a bit safer according to > the Linux coding style convention. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/video/fbdev/omap2/omapfb/vrfb.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/video/fbdev/omap2/omapfb/vrfb.c b/drivers/video/fbdev/omap2/omapfb/vrfb.c > index f346b02eee1d..54b51a7a290a 100644 > --- a/drivers/video/fbdev/omap2/omapfb/vrfb.c > +++ b/drivers/video/fbdev/omap2/omapfb/vrfb.c > @@ -358,11 +358,7 @@ static int __init vrfb_probe(struct platform_device *pdev) > return PTR_ERR(vrfb_base); > > num_ctxs = pdev->num_resources - 1; > - > - ctxs = devm_kzalloc(&pdev->dev, > - sizeof(struct vrfb_ctx) * num_ctxs, > - GFP_KERNEL); > - > + ctxs = devm_kcalloc(&pdev->dev, num_ctxs, sizeof(*ctxs), GFP_KERNEL); This change makes the resulting binary larger by 24 bytes (probably because of the need to have an additional function argument) and I don't see an improvement from a security POV (pdev->num_resources is based on the size of static tables from arch/arm/mach-omap2/fb.c). I'm sorry but I'm not applying this patch. > if (!ctxs) > return -ENOMEM; Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() 2017-05-11 14:27 ` Bartlomiej Zolnierkiewicz @ 2017-05-11 15:22 ` Bartlomiej Zolnierkiewicz 2017-05-12 7:07 ` Geert Uytterhoeven 0 siblings, 1 reply; 4+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2017-05-11 15:22 UTC (permalink / raw) To: SF Markus Elfring Cc: linux-fbdev, linux-omap, Tomi Valkeinen, LKML, kernel-janitors On Thursday, May 11, 2017 04:27:19 PM Bartlomiej Zolnierkiewicz wrote: > > @@ -358,11 +358,7 @@ static int __init vrfb_probe(struct platform_device *pdev) > > return PTR_ERR(vrfb_base); > > > > num_ctxs = pdev->num_resources - 1; > > - > > - ctxs = devm_kzalloc(&pdev->dev, > > - sizeof(struct vrfb_ctx) * num_ctxs, > > - GFP_KERNEL); > > - > > + ctxs = devm_kcalloc(&pdev->dev, num_ctxs, sizeof(*ctxs), GFP_KERNEL); > > This change makes the resulting binary larger by 24 bytes (probably > because of the need to have an additional function argument) and 24 bytes seemed too much for just an additional function argument so I've checked the source: static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) { return devm_kmalloc(dev, size, gfp | __GFP_ZERO); } static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags) { if (size != 0 && n > SIZE_MAX / size) return NULL; return devm_kmalloc(dev, n * size, flags); } static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags) { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } The extra kcalloc() checks are inlined currently into each instance. Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() 2017-05-11 15:22 ` Bartlomiej Zolnierkiewicz @ 2017-05-12 7:07 ` Geert Uytterhoeven 0 siblings, 0 replies; 4+ messages in thread From: Geert Uytterhoeven @ 2017-05-12 7:07 UTC (permalink / raw) To: Bartlomiej Zolnierkiewicz Cc: SF Markus Elfring, Linux Fbdev development list, linux-omap@vger.kernel.org, Tomi Valkeinen, LKML, kernel-janitors@vger.kernel.org On Thu, May 11, 2017 at 5:22 PM, Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> wrote: > On Thursday, May 11, 2017 04:27:19 PM Bartlomiej Zolnierkiewicz wrote: > >> > @@ -358,11 +358,7 @@ static int __init vrfb_probe(struct platform_device *pdev) >> > return PTR_ERR(vrfb_base); >> > >> > num_ctxs = pdev->num_resources - 1; >> > - >> > - ctxs = devm_kzalloc(&pdev->dev, >> > - sizeof(struct vrfb_ctx) * num_ctxs, >> > - GFP_KERNEL); >> > - >> > + ctxs = devm_kcalloc(&pdev->dev, num_ctxs, sizeof(*ctxs), GFP_KERNEL); >> >> This change makes the resulting binary larger by 24 bytes (probably >> because of the need to have an additional function argument) and > > 24 bytes seemed too much for just an additional function argument > so I've checked the source: > > static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) > { > return devm_kmalloc(dev, size, gfp | __GFP_ZERO); > } > static inline void *devm_kmalloc_array(struct device *dev, > size_t n, size_t size, gfp_t flags) > { > if (size != 0 && n > SIZE_MAX / size) > return NULL; > return devm_kmalloc(dev, n * size, flags); > } > static inline void *devm_kcalloc(struct device *dev, > size_t n, size_t size, gfp_t flags) > { > return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); > } > > The extra kcalloc() checks are inlined currently into each instance. And in this case the compiler cannot optimize them away as n is not known at compile time. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-12 7:07 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <CGME20170426092018epcas4p343e69e32255faa796e7c55c3e89e40f2@epcas4p3.samsung.com> 2017-04-26 9:20 ` [PATCH] omapfb: Use devm_kcalloc() in vrfb_probe() SF Markus Elfring 2017-05-11 14:27 ` Bartlomiej Zolnierkiewicz 2017-05-11 15:22 ` Bartlomiej Zolnierkiewicz 2017-05-12 7:07 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).