Re: [PATCH v2] staging: media: atomisp: remove debug sysfs attributes active_bo and free_bo

From: Dan Carpenter
Date: Thu Jun 26 2025 - 15:20:19 EST


Thank you. This is good analysis.

On Thu, Jun 26, 2025 at 06:19:40PM +0300, Abdelrahman Fekry wrote:
> Hello Dan , Thanks for your review
>
> On Tue, Jun 24, 2025 at 9:31 PM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> > Yes. Nothing is checking for if hmm_init() fails. Step through the
> > code and verify that nothing crashes or bad happens as a result.
> >
> > For example, I think hmm_bo_alloc() will print "hmm_bo_device not inited
> > yet." and return. So that's kind of annoying but it's not a crash.
> > Search through the rest of the driver and verify how it will behave.
> >
>
> So, I have been searching through the code as you suggested,
> and found a couple of interesting things to look at.
>
> Firstly, no function that calls hmm_init() checks its return code,
> and it doesn’t crash anywhere because of this, so it's not a problem.
> But the thing is, the hmm_initialized flag inside the hmm_init() function
> is set even if hmm_bo_device_init() fails, and this can be misleading for
> functions like __hm_alloc() that check this flag later.

Yeah.

>
> Secondly, the function hmm_bo_alloc() and others don’t check
> the return code of hmm_init().

hmm_init() is called from two places, atomisp_pci_probe() and
__hmm_alloc(). Is it really possible to call __hmm_alloc() before
atomisp_pci_probe() has succeeded? That's an important question.
Please try to read the code and find the answer.

It would be better to only call hmm_init() from the probe function
and delete the call in __hmm_alloc() but I don't know if that's
possible.

> Instead, they check the flag
> HMM_BO_DEVICE_INITED inside bdev, which is set by the function
> hmm_bo_device_init(). The problem is, if we inspect hmm_bo_device_init(),
> we find that the HMM_BO_DEVICE_INITED flag is set before the calls to
> kmem_cache_create(), kmem_cache_alloc(), and __bo_init().
> This means that if any of these functions fail, the flag will still be set,
> which can lead to misbehavior in functions that rely on it, like hmm_bo_alloc().
>

Yeah. That seems correct to me too.

> Should I tackle these problems after submitting the original patch of
> removing the debug sysfs attr. ?

Perfect. Sounds good.

regards,
dan carpenter