[PATCH 0/2] btrfs: Prevent open-coded arithmetic on kmalloc

From: Miquel Sabaté Solà

Date: Fri Sep 19 2025 - 10:59:38 EST


Hello,

There were a couple of instances in btrfs code in which kmalloc was being
used with open-coded arithmetic. This can lead into unfortunate overflow
situations as describbed here [1]. The solution is to use kmalloc_array in
these cases, which is what it's being done in my first patch.

The second patch is a small cleanup after fixing up my first patch, in
which I realized that the __free(kfree) attribute would come in handy in a
couple of particularly large functions with multiple exit points. This
second patch is probably more of a cosmetic thing, and it's not an
exhaustive exercise by any means. All of this to say that even if I feel
like it should be included, I don't mind if it has to be dropped.

Cheers,
Miquel

[1] Documentation/process/deprecated.rst

Miquel Sabaté Solà (2):
btrfs: Prevent open-coded arithmetic in kmalloc
btrfs: Prefer using the __free cleanup attribute

fs/btrfs/delayed-inode.c | 18 ++++++++----------
fs/btrfs/tree-log.c | 30 +++++++++++-------------------
2 files changed, 19 insertions(+), 29 deletions(-)

--
2.51.0