mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Arnd Bergmann <arnd@kernel.org>,
	Cosmin Tanislav <cosmin.tanislav@analog.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ceclan Dumitru <dumitru.ceclan@analog.com>
Subject: Re: [PATCH] media: i2c: maxim-serdes: reduce max_des_update_streams() stack usage
Date: Mon, 26 Oct 2026 10:48:25 +0200	[thread overview]
Message-ID: <at8T2QchGh_YGegL@kekkonen.localdomain> (raw)
In-Reply-To: <901b5203-7095-4c8f-8644-bef6847a8bf7@app.fastmail.com>

Hi Arnd,

On Thu, Oct 15, 2026 at 12:06:28PM +0200, Arnd Bergmann wrote:
> On Thu, Oct 15, 2026, at 11:40, Sakari Ailus wrote:
> > On Thu, Oct 15, 2026 at 08:45:26AM +0200, Arnd Bergmann wrote:
> >> On Wed, Oct 14, 2026, at 13:33, Sakari Ailus wrote:
> >> > On Wed, Oct 14, 2026 at 12:31:33PM +0200, Arnd Bergmann wrote:
> >> Right. I see there are more allocations in max_des_update_pipe_remaps(),
> >> and max_des_update_pipe_vc_remaps() called through max_des_update_links()
> >> that could fail as well, and may have the additional problem of
> >> leaking allocations every time a stream is enabled and disabled.
> >> 
> >> Can you tell if those should be fixed as well?
> >
> > There seem to be devm_*alloc*() functions being used but that doesn't look
> > like a memory leak -- there's devm_kfree() use as well for the same
> > pointers.
> 
> I see. Yes, that is a bit unusual but not a bug.
> 
> Seeing that the max_serdes_vc_remap array is only eight bytes long, the
> devm_kzalloc() does seem like a very heavyweight operation here, that one
> can just go on the stack and into struct max_des_pipe in place of
> the pointer ;-)

Indeed.

> 
> >> Are ->enable_streams() and ->disable_streams() always serialized
> >> or can they be called concurrently on the same subdev? If there
> >> is only one of them at a time, the allocation could just be
> >> done ahead of time in max_des_allocate().
> >
> > Access to sub-device state which these ops operate on is serialised using
> > the sub-device state mutex i.e. these aren't called concurrently (on the
> > same sub-device).
> >
> > Also cc Dumitru.
> 
> Ok, so maybe the easiest way would be to just put everything into 
> max_des_priv, including all the currently dynamically allocated
> arrays. Since all the maximum sizes are 4 or 8 in the driver
> and most of the structures are short, using fixed-length arrays
> will make it use less memory than the minimum of two cache lines
> per devres object.

We're also trying to remove state outside sub-device state. I guess this is
still driver internal and not visible in the try states so it's not
strictly mandatory yet but still preferred.

I haven't fully read the code so I don't know if it'd be feasible to use
the information gathered directly rather than through an intermediate data
structure that is now the case.

I'd try smaller types now to see if the data structure would fit nicely
into the stack and leave the rest for later.

-- 
Regards,

Sakari Ailus

      reply	other threads:[~2026-10-26  8:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 10:31 Arnd Bergmann
2026-10-14 11:33 ` Sakari Ailus
2026-10-15  6:45   ` Arnd Bergmann
2026-10-15  9:40     ` Sakari Ailus
2026-10-15  9:48       ` Sakari Ailus
2026-10-15 10:06       ` Arnd Bergmann
2026-10-26  8:48         ` Sakari Ailus [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=at8T2QchGh_YGegL@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=cosmin.tanislav@analog.com \
    --cc=dumitru.ceclan@analog.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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

all inboxes | Powered by JetHome®