Linux Media Controller development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Dan Carpenter <error27@gmail.com>
Cc: Dawei Feng <dawei.feng@seu.edu.cn>,
	hansg@kernel.org, mchehab@kernel.org,
	sakari.ailus@linux.intel.com, andy@kernel.org,
	gregkh@linuxfoundation.org, azpijr@gmail.com, kees@kernel.org,
	arnd@arndb.de, pontescpedro@gmail.com,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-staging@lists.linux.dev, jianhao.xu@seu.edu.cn,
	zilin@seu.edu.cn
Subject: Re: [PATCH] media: atomisp: fix CAS scaler descriptor leaks
Date: Mon, 29 Jun 2026 17:45:37 +0300	[thread overview]
Message-ID: <akKFEf73wisw6Qrn@ashevche-desk.local> (raw)
In-Reply-To: <akJehriJCKiJNo2I@stanley.mountain>

On Mon, Jun 29, 2026 at 03:01:10PM +0300, Dan Carpenter wrote:
> On Mon, Jun 29, 2026 at 02:16:21PM +0300, Andy Shevchenko wrote:
> > On Mon, Jun 29, 2026 at 11:30:40AM +0300, Dan Carpenter wrote:
> > > On Sat, Jun 27, 2026 at 02:01:51PM +0800, Dawei Feng wrote:

...

> > > free_output_stage:
> > > 	if (need_scalar) {
> > > 		kfree(mycs->is_output_stage);
> > > 		mycs->is_output_stage = NULL;
> > > 	}
> > > free_scalar_binary:
> > > 	if (need_scalar) {
> > > 		kfree(mycs->yuv_scaler_binary);
> > > 		mycs->yuv_scaler_binary = NULL;
> > > 	}
> > 
> > If we go this way, double check that the checks are needed as we have kfree()
> > to be NULL-aware.
> 
> Dawei, Andy is the one reviewing atomisp so his opinion matters more
> than mine here.  So do what he says.
> 
> But I don't really agree...
> 
> In this case, sure, hopefully the caller zeroes the ->yuv_scaler_binary
> pointer, but if we just follow the simple rule of only undoing things
> which we have done then we don't need to check.  The function is
> self contained and self explanatory.
> 
> And more generally, I've always hated patches which delete NULL
> checks before a ionmap() or whatever.  Hiding the NULL check inside the
> free function makes the code less self contained.  The real fix is to
> stop mixing allocated and unallocated pointers.  Then you don't need a
> NULL check because you already know.  (Also I think those iounmap()
> patches were wrong because some arches have a warning when you unmap
> a NULL).

I fully agree with the statement against iounmap(), but for regular memory
freeing it's almost an idiomatic to just call it with valid pointer (note that
NULL *is* valid pointer, just may not be dereferenced). You can also read recent
discussion with Linus with Kees on some other topic where it was explained the
malloc(0) to give a valid pointer (as an "empty" something). Ah, now I remember
what was that, it was about ARRAY_END() macro.

So, having unconditional kfree() for (optional) memory allocations is perfectly
fine.

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-06-29 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27  6:01 [PATCH] media: atomisp: fix CAS scaler descriptor leaks Dawei Feng
2026-06-29  8:30 ` Dan Carpenter
2026-06-29 11:16   ` Andy Shevchenko
2026-06-29 12:01     ` Dan Carpenter
2026-06-29 14:45       ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=akKFEf73wisw6Qrn@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=azpijr@gmail.com \
    --cc=dawei.feng@seu.edu.cn \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=pontescpedro@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=zilin@seu.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox