From nobody Fri Apr 3 00:00:18 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6314338F949 for ; Wed, 25 Mar 2026 23:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774479909; cv=none; b=S5wiO2xJerrbjrKM/Wmc56sW0Mp3pFRZDWbt8I0v01onJof8WWHkBRf520GJoCTkPWZh3+F6WB21g4jgAFhSe7RfI28fk7XUUqPGueau7EU4np8EiDjIzL4B0LVbnBbD5uOK7cj3xE/NZ7DH7gkgfIp16QWETz4N8/G+DX9XsrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774479909; c=relaxed/simple; bh=rf3vPXa7x1VywS4MiMkGOUIsNiVXVvgwlwYOCkZNs/E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hKfSwckMlyJlkXsydGdzVUX6v6SUmZUQw4bp6pOGdXBD7JKz/4E23BTCaeBmsaJQA9uBNbM2PaUJ85qD8vOYTj4R+libBkg6j1gdomMfTZDmGlitF3vMtYv9dT8vQjWp+8T5eiLjgNWhDHa0xMIhla657hD4irnQ9laySlKFftg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pE0mNjgV; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pE0mNjgV" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b980c65b97aso60015766b.0 for ; Wed, 25 Mar 2026 16:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774479907; x=1775084707; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jiwFETKkt3NdDNZkVN46Gf8wVpkOW4mHE9IXrg+0ugk=; b=pE0mNjgVJCH9WorPmcw0aPCC8x/RexjssFR1MdiY1AY93sJ76VaRWs8Cgret4xR5Zw hJEyCCURw3c4tGHIiHA227v0eaXIwYKjeVGYlXkbj6uFCKJCYPcR6jx5NSoEnXZrcS6t VEZ5QRqJdL0VSbRm3zN7H3mb5uG4NkFi+R1mcSR/6tsjj2rxzzSY/sJD3x9/SiL4eH3Y VKPgqUm+DSLgDcVO3yfn5lZd2r0oVuvqVwhs/kQZJrsCsmGdvia9IELxNbZypKT+Qauq cKb/6JngcUITGK3m9fsQt9cPm8Mg2fJL21LLD7oiO+odJPKCD20oozFIXgEWzCKkjzHH 8VuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774479907; x=1775084707; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jiwFETKkt3NdDNZkVN46Gf8wVpkOW4mHE9IXrg+0ugk=; b=Px0cEZewD5eV5fZJzw4b2b/U5EAYyBzZqsa5OCXt5v6T4KKDggf5JhGzS8gfMuUG8c RHtGP9Wye2a3ZbYkGzgeC3lPS2WZ7Cwhr6AguLef4IxAKR7V+Wa9z/UIQGVDZuBsEog5 cJo7pU0Wz0mriY9WEOeSASkGfe77asBOzDQHqb3z6Um2yfIO5x02eeIyZBxXZAvfrOIl V0i7CRAEvFNCjQCnMtjzHOHuPDbYPVLSAOVxrogInaChvVdMBP73bET8IJz12Sg3rPFG vH4Nzw6IjrVgoB6FpB4VIuHeZnSGht6Y6mKDtJCTWFp0khKa6E36Imc2iJE/FSheNSpF NsSw== X-Forwarded-Encrypted: i=1; AJvYcCUCbCW+U2TTH9fHhw/RYYdXrGaGvjYbq1A56PWovPrTwyZvCAP30BJFgvP+M5932QJ82RyXjMCV4NYhx/c=@vger.kernel.org X-Gm-Message-State: AOJu0YyOdrrrB+I9YRqKqERaQZZNP7/8hcAq+eqK7wJycBwl3v4QRA+W yjjrg2sFj52g7dnJEVENBsAvl2pAEpmNN3egOXiaTBO2pXyo/ZQPg28p X-Gm-Gg: ATEYQzxpJq3HwxK/D5An4ETQ1GnEsdSGfFkNTklURYt8Xwbumk+0LXyiytoKbWoHGwX W4UlU5tFS15yDCZQEW7xg+PD0UhIbAVN7n/mR9+LjTVMpXCL0EVvV4gWFaqGlAsPRTYZEuayram cuijHrqEUn9r4wHLEFeiCsshxJh8/exo5sH1JPFKe+0xlaTDZQzmhPjPH8gwI2nl6q+KraCs1Yp zHfJM7P4XPICsmqlTa4vJbKtN8FGdZHE2++tTUiiQ/kmbSQ2uie/YEYlG5UpQzGk3qI4VowqFTG SPxMBy5kl4o4OyYNQT1M+lmiE529nXAc08YdcKvhIVn51Qdk8eXwvnVEzqKrlz3iWSZxM+2tG2S CizAn1UyOfXfaeT7wDVh5qgmhfjT3pA7XocRsY1Fk8Nz6XOQo+Lw7GteJDUT39CyoKh5BK+JSMs iJ5lpkHcavfeZUaTkXQl4C2jWDYLp4rMIhR9wzVTYZ/SJYOA== X-Received: by 2002:a17:907:8694:b0:b96:996c:8605 with SMTP id a640c23a62f3a-b9a3f1adbd8mr393398866b.23.1774479906060; Wed, 25 Mar 2026 16:05:06 -0700 (PDT) Received: from localhost.localdomain ([2a00:f41:185f:dfa7:bca5:80ff:fe60:41d2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9b203ef860sm35371766b.48.2026.03.25.16.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 16:05:05 -0700 (PDT) From: "Jose A. Perez de Azpillaga" To: linux-staging@lists.linux.dev Cc: Hans de Goede , Mauro Carvalho Chehab , Sakari Ailus , Andy Shevchenko , Greg Kroah-Hartman , Kees Cook , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] staging: media: atomisp: refactor ia_css_stream_destroy Date: Thu, 26 Mar 2026 00:04:48 +0100 Message-ID: <20260325230453.848584-1-azpijr@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the ISP2401 cleanup logic into a separate helper function. Fix a logic bug where the loop variable 'i' was being shadowed and overwritten by a nested loop, potentially causing incorrect cleanup behavior. Replace an early 'return -EINVAL' with 'continue' within the cleanup loop. In a destruction path, it is better to proceed with cleaning up as many resources as possible rather than aborting early, which would result in memory leaks for the remaining pipes. Remove 'assert(entry)' in favor of an explicit null pointer check ('if (!entry) continue;'). This avoids a macro-based assertions and ensuring the system remains stable even if a pointer is unexpectedly null during cleanup. Signed-off-by: Jose A. Perez de Azpillaga --- drivers/staging/media/atomisp/pci/sh_css.c | 89 ++++++++++++---------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/m= edia/atomisp/pci/sh_css.c index 6cda5925fa45..076a75c9d0fb 100644 --- a/drivers/staging/media/atomisp/pci/sh_css.c +++ b/drivers/staging/media/atomisp/pci/sh_css.c @@ -8189,6 +8189,51 @@ ia_css_stream_create(const struct ia_css_stream_conf= ig *stream_config, return err; } =20 +static void ia_css_stream_destroy_isp2401(struct ia_css_stream *stream) +{ + int i, j; + + for (i =3D 0; i < stream->num_pipes; i++) { + struct ia_css_pipe *entry =3D stream->pipes[i]; + unsigned int sp_thread_id; + struct sh_css_sp_pipeline_terminal *terminal; + + if (!entry) + continue; + + /* get the SP thread id */ + if (!ia_css_pipeline_get_sp_thread_id(ia_css_pipe_get_pipe_num(entry), + &sp_thread_id)) + continue; + + /* get the target input terminal */ + terminal =3D &sh_css_sp_group.pipe_io[sp_thread_id].input; + + for (j =3D 0; j < IA_CSS_STREAM_MAX_ISYS_STREAM_PER_CH; j++) { + ia_css_isys_stream_h isys_stream =3D + &terminal->context.virtual_input_system_stream[j]; + + if (stream->config.isys_config[j].valid && isys_stream->valid) + ia_css_isys_stream_destroy(isys_stream); + } + } + + if (stream->config.mode =3D=3D IA_CSS_INPUT_MODE_BUFFERED_SENSOR) { + for (i =3D 0; i < stream->num_pipes; i++) { + /* + * free any mipi frames that are remaining: + * some test stream create-destroy cycles do + * not generate output frames + * and the mipi buffer is not freed in the + * deque function + */ + if (stream->pipes[i]) + free_mipi_frames(stream->pipes[i]); + } + } + stream_unregister_with_csi_rx(stream); +} + int ia_css_stream_destroy(struct ia_css_stream *stream) { @@ -8206,48 +8251,8 @@ ia_css_stream_destroy(struct ia_css_stream *stream) =20 if ((stream->last_pipe) && ia_css_pipeline_is_mapped(stream->last_pipe->pipe_num)) { - if (IS_ISP2401) { - for (i =3D 0; i < stream->num_pipes; i++) { - struct ia_css_pipe *entry =3D stream->pipes[i]; - unsigned int sp_thread_id; - struct sh_css_sp_pipeline_terminal *sp_pipeline_input_terminal; - - assert(entry); - if (entry) { - /* get the SP thread id */ - if (!ia_css_pipeline_get_sp_thread_id( - ia_css_pipe_get_pipe_num(entry), &sp_thread_id)) - return -EINVAL; - - /* get the target input terminal */ - sp_pipeline_input_terminal =3D - &sh_css_sp_group.pipe_io[sp_thread_id].input; - - for (i =3D 0; i < IA_CSS_STREAM_MAX_ISYS_STREAM_PER_CH; i++) { - ia_css_isys_stream_h isys_stream =3D - &sp_pipeline_input_terminal->context.virtual_input_system_stream[i]; - if (stream->config.isys_config[i].valid && isys_stream->valid) - ia_css_isys_stream_destroy(isys_stream); - } - } - } - - if (stream->config.mode =3D=3D IA_CSS_INPUT_MODE_BUFFERED_SENSOR) { - for (i =3D 0; i < stream->num_pipes; i++) { - struct ia_css_pipe *entry =3D stream->pipes[i]; - /* - * free any mipi frames that are remaining: - * some test stream create-destroy cycles do - * not generate output frames - * and the mipi buffer is not freed in the - * deque function - */ - if (entry) - free_mipi_frames(entry); - } - } - stream_unregister_with_csi_rx(stream); - } + if (IS_ISP2401) + ia_css_stream_destroy_isp2401(stream); =20 for (i =3D 0; i < stream->num_pipes; i++) { struct ia_css_pipe *curr_pipe =3D stream->pipes[i]; --=20 2.53.0