Re: [RFC PATCH] perf/core: Prevent dereferencing NULL pointer

From: Peter Zijlstra
Date: Thu Feb 06 2025 - 03:05:41 EST


On Thu, Feb 06, 2025 at 03:06:08AM +0800, I Hsin Cheng wrote:
> According to coverity scan check, there's possible cases where
> "ring_buffer_get()" returns a NULL in "perf_mmap_close".

That makes no sense. Having a mmap should pin the buffer.

> Use a "BUG_ON()" to check for NULL pointer existence, panic if it does
> exist, otherwise it's safe to dereference "rb" and access its members.

How the hell is a BUG_ON() any better than a NULL deref?