Skip to content

Commit 4017671

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
mfd: omap-usb-tll: Use struct_size to allocate tll
Commit 16c2004 ("mfd: omap-usb-tll: Allocate driver data at once") changed the memory allocation of 'tll' to consolidate it into a single allocation, introducing an incorrect size calculation. In particular, the allocation for the array of pointers was converted into a single-pointer allocation. The memory allocation used to occur in two steps: tll = devm_kzalloc(dev, sizeof(struct usbtll_omap), GFP_KERNEL); tll->ch_clk = devm_kzalloc(dev, sizeof(struct clk *) * tll->nch, GFP_KERNEL); And it turned that into the following allocation: tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]), GFP_KERNEL); sizeof(tll->ch_clk[nch]) returns the size of a single pointer instead of the expected nch pointers. This bug went unnoticed because the allocation size was small enough to fit within the minimum size of a memory allocation for this particular case [1]. The complete allocation can still be done at once with the struct_size macro, which comes in handy for structures with a trailing flexible array. Fix the memory allocation to obtain the original size again. Link: https://lore.kernel.org/all/202406261121.2FFD65647@keescook/ [1] Fixes: 16c2004 ("mfd: omap-usb-tll: Allocate driver data at once") Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Javier Carrasco <[email protected]> Fixes: commit 16c2004 ("mfd: omap-usb-tll: Allocate driver data at once") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent b0a5cde commit 4017671

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/mfd/omap-usb-tll.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
230230
break;
231231
}
232232

233-
tll = devm_kzalloc(dev, sizeof(*tll) + sizeof(tll->ch_clk[nch]),
234-
GFP_KERNEL);
233+
tll = devm_kzalloc(dev, struct_size(tll, ch_clk, nch), GFP_KERNEL);
235234
if (!tll) {
236235
pm_runtime_put_sync(dev);
237236
pm_runtime_disable(dev);

0 commit comments

Comments
 (0)