Javier Carrasco 40176714c8 mfd: omap-usb-tll: Use struct_size to allocate tll
Commit 16c2004d9e4d ("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: 16c2004d9e4d ("mfd: omap-usb-tll: Allocate driver data at once")
Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Fixes: commit 16c2004d9e4d ("mfd: omap-usb-tll: Allocate driver data at once")
Link: https://lore.kernel.org/r/20240626-omap-usb-tll-counted_by-v2-1-4bedf20d1b51@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
2024-07-04 17:38:41 +01:00
..
2024-05-21 10:09:28 -07:00
2024-05-22 10:45:12 -07:00
2024-05-23 13:38:31 -07:00
2024-05-23 13:44:47 -07:00
2024-05-16 08:50:32 -07:00
2024-05-23 12:04:36 -07:00
2024-05-21 11:15:56 -07:00
2024-05-14 18:57:22 -07:00
2024-05-23 12:04:36 -07:00
2024-05-24 17:28:02 -07:00
2024-05-22 10:45:12 -07:00
2024-05-22 12:13:40 -07:00
2024-05-23 00:29:19 +02:00
2024-05-17 09:05:46 -07:00
2024-05-14 18:25:53 -07:00
2024-05-16 08:56:49 -07:00
2024-05-21 09:51:42 -07:00
2024-05-23 12:04:36 -07:00
2024-05-14 09:14:49 -06:00
2024-05-17 13:01:24 +02:00
2024-05-21 10:09:28 -07:00
2024-05-23 12:09:22 -07:00
2024-05-21 11:19:18 -07:00
2024-05-22 10:41:14 -07:00
2024-05-14 19:42:24 -07:00
2024-05-23 12:04:36 -07:00
2024-05-07 23:40:46 +02:00
2024-05-23 12:04:36 -07:00
2024-05-08 19:21:51 +01:00
2024-05-21 11:23:36 -07:00
2024-05-14 14:41:01 -07:00
2024-05-24 08:38:28 -07:00
2024-05-14 18:25:53 -07:00
2024-05-20 14:56:50 -07:00
2024-05-23 12:04:36 -07:00
2024-05-22 10:45:12 -07:00
2024-05-23 12:04:36 -07:00
2024-05-24 10:24:49 -07:00