Re: [PATCH 1/2] btrfs: Prevent open-coded arithmetic in kmalloc

From: David Sterba

Date: Mon Sep 22 2025 - 06:28:54 EST


On Fri, Sep 19, 2025 at 04:58:15PM +0200, Miquel Sabaté Solà wrote:
> As pointed out in the documentation, calling 'kmalloc' with open-coded
> arithmetic can lead to unfortunate overflows and this particular way of
> using it has been deprecated. Instead, it's preferred to use
> 'kmalloc_array' in cases where it might apply so an overflow check is
> performed.

So this is an API cleanup and it makes sense to use the checked
multiplication but it should be also said that this is not fixing any
overflow because in all cases the multipliers are bounded small numbers
derived from number of items in leaves/nodes.

> Signed-off-by: Miquel Sabaté Solà <mssola@xxxxxxxxxx>

Reviewed-by: David Sterba <dsterba@xxxxxxxx>