Re: [PATCH 4/4] bcache: Release the cache kobject when cache_alloc() fails
From: David Laight
Date: Mon Nov 30 2026 - 13:25:21 EST
On Mon, 30 Nov 2026 23:08:20 +0800
"Coly Li" <colyli@xxxxxxx> wrote:
> > kfree(ca->prio_buckets);
> > vfree(ca->buckets);
>
> For the above 2 lines, also kfree() and vfree() checks NULL inside,
> normally I would suggest to check the following checks,
> if (ca->prio_buckets)
> kfree(ca->prio_buckets);
> if (ca->buckets)
> vfree(ca->buckets);
> Then the extra function jumps to kfree() and vfree() can be avoided.
I'd only do that if the common path has NULL pointers.
Otherwise you are optimising for something that doesn't happen and
stand a moderate chance of a mispredicted branch (and likely() may not
help) - that might actually cost 40 clocks.
With luck (and a following wind) the test inside kfree() will be
predicted for 'not NULL' - so you only get the penalty in a (usually)
error path that passes NULL (you might get a mispredict on the next
non-NULL call, but that is really part of the penalty for the NULL).
David