From nobody Mon Feb 9 07:20:47 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 C29B6331A77 for ; Wed, 7 Jan 2026 13:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767793757; cv=none; b=Gp9kSb+A086V3xBZTmGLH//sXMspKOWmmxmHA3skjP7l+Q4G10Dj/w6GZYKJW8gnf7vnXh4Ula5utOe49FaXIlMIZfY/sm7IHqWrU5RMhb67alAl76pWJUf8KCMItkXwyDpJZNrp7qc3XWx/MKQS5ec2Mbcspqowbzi8j+8RrCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767793757; c=relaxed/simple; bh=7aFJtkTCn/RUyXBqDN5A8Rl1FrpL/MQORLd7fWn3cOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YjI5CYFgOdZo3Ewrs1QFpHWE+Q8LGvuG4Bi1EYHmVkMzhQInS0n+AfFzlLxPLsDyhKm4sjw7e1If8+8S/mQbBuB7Srems9Pb+FNGXXd/dE5nL9ywuZtHfOPO1fY2CvXcNilD+f719x6sB2GUHThUcrCGA2HbxE3sXxGg0+WNYw0= 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=i5xWl8vC; arc=none smtp.client-ip=209.85.214.182 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="i5xWl8vC" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2a0bb2f093aso17395425ad.3 for ; Wed, 07 Jan 2026 05:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767793755; x=1768398555; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0L8w8zzA7n7ZIE7wj1Nj7dJ97iLU993N1NE76Z8Jakg=; b=i5xWl8vCXaigEqSuE1V5RY8bQkqBbNHHINBNQ+Rs2XSi8P08eAbLPQ4gjojz6YDJtR xnp6pMFT0XjdoK7IIgh05/tIqE+/Ie1EwrWz22k8Ef7qnZMM6ao8tkShQNDtE6dUT4Jo AhQ5zsJVwIHAsCCY3uZ3UQGE1Q6y1YwjkdmnLI8Als3+rk29pkwvurQSso7QoFZYQMlb SGonTbEPpHbVObh+d0t8uJvjwFmJjimlPCmEJ0xV195QkgZLallu5lu7VLs5WFqMLmzz R8w8p44uTsAuWybosPLUr7hQMShPJmNmmlahY8NFP8ysdK0HxJqba8iEAZFEM6492Qdd DZfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767793755; x=1768398555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0L8w8zzA7n7ZIE7wj1Nj7dJ97iLU993N1NE76Z8Jakg=; b=cVql/vkECylTAQj8NCZzrvMGxpuNTDHPl/rrMDY+EXksaFyytVTopHeoybXTRGLjD6 Ep/Psb/Yy8zITVuufROZ2KnOrYVY4WQMHMZV/K3QVGb/ce9CR4Mk25obAfV/UyvVvu9A dF9XNuvxJ6tEzQVr+5rYLMccOTncUz1e0MKRyuJW2RfNFW8Se44VqkfNLQy3pwKx1Mov XFhA4AkslmsF4xDJ8QJdFUOVB0//r3932F8as/Qql9s9aRhgg2wFy5PmAfItEHcyEtlF hrMbA5ac0qTXMNdBIZyMr6Vd7pjph+i40k5+dQ5TosVwYH2QKRwsw7apsQsSW0+KaJQz g6OA== X-Forwarded-Encrypted: i=1; AJvYcCWEQsU/s05O/a2kbO7hphAE81+lthJeqCfGoVc4mNH8+4kw8S9l6lPPyCVIJewB9uX5yQ75G6GWCzoZJbM=@vger.kernel.org X-Gm-Message-State: AOJu0YxFKnE6CZ2VZ6NJhe1YyiykS8x9jAtqrgEl5rwgC+r5yiHBBmeh +GqORQwHG9pv0nMcQ+LfeT/elCyHpnthuVnN1XrC6OSoe0q0npAheoAO X-Gm-Gg: AY/fxX5fsFYdQ5nog6jrLl3GzGFyoUIOosiDlc6A0znADavWHL+HH4g0cdy0WjymQnG aW+nbiq+5feOCf4oXt9tfX5uSTIy8YM448BTk9dE7ADrg+FHk5Y21p6vKWoYnQzW/T2LAVhU2PS Nk1ZTz7BHulRcU3eMb7a3GPsvHU0DSuBBGQYZ/P6TsbqNWVwNyAFk0mzj0aUnWI2nIkNTB0sDy8 T3T47CdGHUUPSYSSTsdDpCu2f+RWUNkqroD5dsmnwBxWc4eyHhHs494J1dh2NX86TJe7xrjy6Pu euRgMj6sJACj9dvwY93AgcKBupf8qWFN2xfiUnNhoUd37SU1sp3x+sKJlIMyMKbTdqT9TT5d394 OZI9YEch7NLhAwJrJKbfMlUBIeONOaBPyk1is8OaAXm9g2AgSI2kZJwypry3dSRAj6BL8H/91BQ 8E1W0yrtj5wHlCjt8l/K3nQw== X-Google-Smtp-Source: AGHT+IE7J+DUw5Iqs5C2fpYR9e3jAQUDZORywRhmTE7GqrIw5ManxpPFTH52JMOGUB9mdhbFJlJkqQ== X-Received: by 2002:a17:90b:2251:b0:33e:30e8:81cb with SMTP id 98e67ed59e1d1-34f68b65ff0mr2290395a91.13.1767793755014; Wed, 07 Jan 2026 05:49:15 -0800 (PST) Received: from karthik.. ([43.247.159.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c5302c61sm5109577b3a.42.2026.01.07.05.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 05:49:14 -0800 (PST) From: Karthikey D Kadati To: Hans de Goede , Mauro Carvalho Chehab Cc: Sakari Ailus , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Karthikey D Kadati Subject: [PATCH v2 RESEND v2 2/3] media: atomisp: consolidate statistics buffer allocation Date: Wed, 7 Jan 2026 19:18:43 +0530 Message-ID: <20260107134844.68074-3-karthikey3608@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260107134844.68074-1-karthikey3608@gmail.com> References: <81e2d12c-342b-4b88-88a0-3e24115541aa@kernel.org> <20260107134844.68074-1-karthikey3608@gmail.com> 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 atomisp_alloc_css_stat_bufs() to use a new helper function atomisp_alloc_stat_bufs_list(). This reduces code duplication for allocating 3A, DIS, and metadata buffers and centralizes the allocation loop logic. The helper returns -ENOMEM on failure, triggering the existing cleanup path in the caller which correctly frees any partially allocated lists. Signed-off-by: Karthikey D Kadati --- .../staging/media/atomisp/pci/atomisp_ioctl.c | 123 ++++++++++++------ 1 file changed, 81 insertions(+), 42 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/st= aging/media/atomisp/pci/atomisp_ioctl.c index 5c0a1d92b..9e572b3e6 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -678,13 +678,78 @@ static int atomisp_g_fmt_cap(struct file *file, void = *fh, return atomisp_try_fmt_cap(file, fh, f); } =20 +static int atomisp_alloc_stat_bufs_list(struct atomisp_sub_device *asd, + u16 stream_id, + struct list_head *buf_list, + int count, + enum ia_css_buffer_type type) +{ + struct atomisp_s3a_buf *s3a_buf; + struct atomisp_dis_buf *dis_buf; + struct atomisp_metadata_buf *md_buf; + + while (count--) { + switch (type) { + case IA_CSS_BUFFER_TYPE_3A_STATISTICS: + s3a_buf =3D kzalloc(sizeof(*s3a_buf), GFP_KERNEL); + if (!s3a_buf) + return -ENOMEM; + + if (atomisp_css_allocate_stat_buffers(asd, + stream_id, + s3a_buf, + NULL, + NULL)) { + kfree(s3a_buf); + return -ENOMEM; + } + list_add_tail(&s3a_buf->list, buf_list); + break; + case IA_CSS_BUFFER_TYPE_DIS_STATISTICS: + dis_buf =3D kzalloc(sizeof(*dis_buf), GFP_KERNEL); + if (!dis_buf) + return -ENOMEM; + + if (atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + dis_buf, + NULL)) { + kfree(dis_buf); + return -ENOMEM; + } + list_add_tail(&dis_buf->list, buf_list); + break; + case IA_CSS_BUFFER_TYPE_METADATA: + md_buf =3D kzalloc(sizeof(*md_buf), GFP_KERNEL); + if (!md_buf) + return -ENOMEM; + + if (atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + NULL, + md_buf)) { + kfree(md_buf); + return -ENOMEM; + } + list_add_tail(&md_buf->list, buf_list); + break; + default: + return -EINVAL; + } + } + + return 0; +} + int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd, - uint16_t stream_id) + u16 stream_id) { struct atomisp_device *isp =3D asd->isp; - struct atomisp_s3a_buf *s3a_buf =3D NULL, *_s3a_buf; - struct atomisp_dis_buf *dis_buf =3D NULL, *_dis_buf; - struct atomisp_metadata_buf *md_buf =3D NULL, *_md_buf; + struct atomisp_dis_buf *dis_buf, *_dis_buf; + struct atomisp_s3a_buf *s3a_buf, *_s3a_buf; + struct atomisp_metadata_buf *md_buf, *_md_buf; int count; struct ia_css_dvs_grid_info *dvs_grid_info =3D atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info); @@ -695,37 +760,20 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_de= vice *asd, count =3D ATOMISP_CSS_Q_DEPTH + ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL; dev_dbg(isp->dev, "allocating %d 3a buffers\n", count); - while (count--) { - s3a_buf =3D kzalloc(sizeof(struct atomisp_s3a_buf), GFP_KERNEL); - if (!s3a_buf) - goto error; - - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, s3a_buf, NULL, NULL)) { - kfree(s3a_buf); - goto error; - } - - list_add_tail(&s3a_buf->list, &asd->s3a_stats); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->s3a_stats, count, + IA_CSS_BUFFER_TYPE_3A_STATISTICS)) + goto error; } =20 if (list_empty(&asd->dis_stats) && dvs_grid_info && dvs_grid_info->enable) { count =3D ATOMISP_CSS_Q_DEPTH + 1; dev_dbg(isp->dev, "allocating %d dis buffers\n", count); - while (count--) { - dis_buf =3D kzalloc(sizeof(struct atomisp_dis_buf), GFP_KERNEL); - if (!dis_buf) - goto error; - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, NULL, dis_buf, NULL)) { - kfree(dis_buf); - goto error; - } - - list_add_tail(&dis_buf->list, &asd->dis_stats); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->dis_stats, count, + IA_CSS_BUFFER_TYPE_DIS_STATISTICS)) + goto error; } =20 for (i =3D 0; i < ATOMISP_METADATA_TYPE_NUM; i++) { @@ -736,19 +784,10 @@ int atomisp_alloc_css_stat_bufs(struct atomisp_sub_de= vice *asd, ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL; dev_dbg(isp->dev, "allocating %d metadata buffers for type %d\n", count, i); - while (count--) { - md_buf =3D kzalloc(sizeof(struct atomisp_metadata_buf), - GFP_KERNEL); - if (!md_buf) - goto error; - - if (atomisp_css_allocate_stat_buffers( - asd, stream_id, NULL, NULL, md_buf)) { - kfree(md_buf); - goto error; - } - list_add_tail(&md_buf->list, &asd->metadata[i]); - } + if (atomisp_alloc_stat_bufs_list(asd, stream_id, + &asd->metadata[i], count, + IA_CSS_BUFFER_TYPE_METADATA)) + goto error; } } return 0; --=20 2.43.0