From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Dawei Feng <dawei.feng@seu.edu.cn>
Cc: andy@kernel.org, error27@gmail.com, hansg@kernel.org,
mchehab@kernel.org, sakari.ailus@linux.intel.com,
gregkh@linuxfoundation.org, abdelrahmanfekry375@gmail.com,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-staging@lists.linux.dev, jianhao.xu@seu.edu.cn,
Zilin Guan <zilin@seu.edu.cn>
Subject: Re: [PATCH v3 1/2] media: atomisp: fix memory leak in atomisp_pci_probe()
Date: Wed, 17 Jun 2026 12:40:20 +0300 [thread overview]
Message-ID: <ajJrhE3cjwKPom5a@ashevche-desk.local> (raw)
In-Reply-To: <20260616134319.3969928-2-dawei.feng@seu.edu.cn>
On Tue, Jun 16, 2026 at 09:43:18PM +0800, Dawei Feng wrote:
> atomisp_initialize_modules() creates CSI2 and ISP subdev media entities
> before atomisp_pci_probe() registers them. Its counterpart,
> atomisp_uninitialize_modules(), only releases part of that module-owned
> state and leaves some media entity cleanup to the entity unregister path.
>
> That ownership split is incomplete for probe error paths. If
> atomisp_pci_probe() fails after module initialization but before all
> entities are registered, the unwind path cannot rely on unregister
> helpers to release media entity state whose lifetime started in module
> initialization. The CSI2 and ISP subdev media entities can therefore be
> left allocated.
>
> Refactor the cleanup boundary so module cleanup releases media entities
> created by module initialization, while unregister helpers only undo
> registered V4L2 and media device state. Move CSI2 and ISP subdev media
> entity cleanup into atomisp_mipi_csi2_cleanup() and the new
> atomisp_subdev_cleanup(), and run media_device_cleanup() after module
> cleanup in the probe unwind and remove paths.
>
> If atomisp_mipi_csi2_init() itself fails, it has already unwound its
> partial setup, so return the error directly. Only the later
> atomisp_subdev_init() failure path needs to clean up CSI2 from the
> caller.
...
> void atomisp_mipi_csi2_cleanup(struct atomisp_device *isp)
> {
> + unsigned int i;
> +
> + for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++)
In case you need a new version
for (unsigned int i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++)
> + media_entity_cleanup(&isp->csi2_port[i].subdev.entity);
> }
Or maybe Sakari can tweak this whilst applying.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-06-17 9:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 13:43 [PATCH v3 0/2] media: atomisp: fix probe memory leaks Dawei Feng
2026-06-16 13:43 ` [PATCH v3 1/2] media: atomisp: fix memory leak in atomisp_pci_probe() Dawei Feng
2026-06-17 9:40 ` Andy Shevchenko [this message]
2026-06-16 13:43 ` [PATCH v3 2/2] media: atomisp: fix memory leak in atomisp_csi2_bridge_parse_firmware() Dawei Feng
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=ajJrhE3cjwKPom5a@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=abdelrahmanfekry375@gmail.com \
--cc=andy@kernel.org \
--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=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--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
all inboxes | Powered by JetHome®