Re: [PATCH] checkpatch: add uninitialized pointer with __free attribute check

From: ally heev

Date: Thu Oct 23 2025 - 06:31:26 EST


On Tue, 2025-10-21 at 09:43 -0700, dan.j.williams@xxxxxxxxx wrote:
[...]
> Looks good to me, but I why WARN and not ERROR? Is there ever a valid
> reason to ignore this warning?

makes sense. I will make it an ERROR

>
> I would go futher and suggest that the pattern of:
>
> type foo __free(free_foo) = NULL;
>
> ...be made into a warning because that easily leads to situations where
> declaration order is out of sync with allocation order. I.e. can be made
> technically correct, but at a level of cleverness that undermines the
> benefit.

But, does this pattern cause any real issue? I found allocating memory
later useful in cases like below

arch/powerpc/perf/vpa-dtl.c
```

struct vpa_pmu_buf *buf __free(kfree) = NULL;
struct page **pglist __free(kfree) = NULL;

/* We need at least one page for this to work. */
if (!nr_pages)
return NULL;

if (cpu == -1)
cpu = raw_smp_processor_id();

buf = kzalloc_node(sizeof(*buf), GFP_KERNEL,
cpu_to_node(cpu));
```