Re: [PATCH v4 2/4] input: apple_z2: Add a driver for Apple Z2 touchscreens
From: Sasha Finkelstein
Date: Thu Jan 16 2025 - 13:42:21 EST
On Thu, 16 Jan 2025 at 19:29, Christophe JAILLET
<christophe.jaillet@xxxxxxxxxx> wrote:
>
> >> + z2->tx_buf = devm_kzalloc(dev, sizeof(struct
> >> apple_z2_read_interrupt_cmd), GFP_KERNEL);
> >> + z2->rx_buf = devm_kzalloc(dev, 4096, GFP_KERNEL);
> >
> > This will allocate 8192 bytes because of the way the allocator works.
> > It needs around 40 bytes for the devm stuff + 4096 requested. So
> > rounding rules will allocate 8192 bytes.
> >
> > So either you could allocate "for free" much more space, or you could
> > allocate (and document...)
> > z2->rx_buf = devm_kzalloc(dev, 4096 - sizeof(struct devres),
> > GFP_KERNEL);
> >
> > or have an explicit devm_add_action_or_reset() that would require less
> > memory, but would add some LoC.
> >
>
> or leave it as-is, of course ;-)
>
> >
> > See https://elixir.bootlin.com/linux/v6.13-rc3/source/drivers/base/
> > devres.c#L97
> >
The precise size does not matter in this case, 4096 was picked semi-arbitrarily
as a "nice-looking" number that is definitely bigger than the maximum
message size.