From nobody Tue Feb 10 20:29:35 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 7F7B634EF06 for ; Wed, 7 Jan 2026 14:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767797002; cv=none; b=omhC5q3FRNGlkV+vpp8s+9wvbM9uSlYTHArE+Hmw1zq2I+Fyn87SaEbWWDWaxPuBs50hGFaABcUhWS0Ifr8ZS64t4T18J6TrVhx4V2aMxqc4PjMgWwUNdq++geGPJw65DDmGpj2VELY/osoHtdpWHsTeZTBSCb1Gm0JRf9ohdYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767797002; c=relaxed/simple; bh=TKdeBU8mKT5yWGknDxcWZj3m54VDH36yEoT5RzaujbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fOcLtUCs7rAeCBlCjXDpoYh8yFSGvwlzAnjO7qHplurMxQwZ8Z61CCenGAzRo92ZOioS5BOmXE1kEWYmN1cIxV9inmCeCDcxfH8iw/YoQeNe5Irnr1L8+9cnAd4k+YvbqS5wP0fBx+jg99NCyd/hjPy+yiXNvdmk1w58+HHWCjg= 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=SQ7FuTOb; arc=none smtp.client-ip=209.85.210.174 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="SQ7FuTOb" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7b852bb31d9so2015145b3a.0 for ; Wed, 07 Jan 2026 06:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767797000; x=1768401800; 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=fkj6vssmN7l7h2hvFyd91TLIHv8AfgSmQLvANyZ3hxM=; b=SQ7FuTObXGP0eMqGtgpgya13rNARC5lEdApr0sal72+gUr8C03S/kcMopQVQq9xnR+ affgWN7V9IVA3Tw02eN7J+rzallgGoarmfLXjcZ85bi26LFGnfkJPSTXU4Qn3CxKKo9j jb/dfy13t5K9YiPAVtu/fpnThM4VZgmQRstT+menAi/YzS7BeRQQnVJ9oqZNEGiBFug4 6aj5D7M9B7Sgdy+33+JWX7c7btayQcm/0NC0WSj6bCwp4F8H4LkJQtOpu5uaKutsJUEZ LYzGcTZiJbeJwkO3JtN/KMhJCU5Sll2cNN07sjFLTfh6coLapZxvx3c7/AAWCPuTE3lA 5oAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767797000; x=1768401800; 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=fkj6vssmN7l7h2hvFyd91TLIHv8AfgSmQLvANyZ3hxM=; b=w8xdtaJQYCuud5BYP168eyp+3FBbfRwDmN3cwmSS1o6lH0iW+TnKWs4FcZXLLGTuBs vdoepGn+70no3oAdmDlkFMpYCMHgOjqx+TrADShN6dLXcNhNpOTk52F0caZaaQs0RMul /FaBt5YO1+nqkgzb+XnewxWTCiy5DNAdI0tl76AWDGIU1Wc5z0Hf3wLRRpBS4Oa9Q5fQ Bn29rsxthgktvwyhzJ88mdGdvw9yowr/BA4cYG7YFjnb9O2tuB0KVL/6MnS0eywPzqdC s67RQMjEMJPU8F4iJkoWT7g7YMWY1T6t6MuC3bpxd0pUymKWX0wTRcN2/tAh55Gsr5eE Vmrw== X-Forwarded-Encrypted: i=1; AJvYcCXR/YuFBuW/ETfoi34OljU6ZD+0Dvs1lvgiiVxXg8Ju4/pIFaooJxAssLKe0lr1Qznoe+aWk8Fv7Y27c9A=@vger.kernel.org X-Gm-Message-State: AOJu0YwwAp6mV2tZzEMnNT1A1AuF1mmfq0QX/lDjqKxfiYatgJQZQ9hk 1m9ESvsaiQ1ow7SLC5Igaod9rHULswwlGrak9fKoP3Xwa9mvjBxeYihr X-Gm-Gg: AY/fxX7qOzFnStWSrNdUORgrQJaA8EjAOPwWNLM5gNXgY1LbouXxIzclxsPXRs9aUxW NUx0qZwLk5AfC/+2/U05gJ4VOPMUcPMLlOrwGAbwsmgo8F0tFOedtalFVseQ9761kJJxosTEWQ4 tHHd/UtdIGWFQaoHtF8QG7JfrvzRlK946GOXrl9kNVLB2c7+PrmIO6U3hSuSqMB6+iODjP/0fzm CCNGkdCrLxOWTQIgOnDZkazHu+i+QpnqJQc8MRTijoLmfEQE53l+BsHgIS0vTWe2G8yKavR3UTE QE5qCwgNwak+cnnNe5/QaKmUmNDXm65SWym4ybiOTTkhshAiCBPU5GNhhafgy7VXrqJM2PHezLP HnSMNxczLm9e+z+NGxlVY8lKH9TKVqpeKBw2yqmNDq7Q/sLIaVhbZoHnLJfqBXNy48kNspYjwB/ yR/xq1ig5Yl8s= X-Google-Smtp-Source: AGHT+IFNKIgoAsSsAaMWMKXlRyQndBGHQdjiItfcgOkO3GbHXWCSaLvMXIyZsGQ/A7OHZizbcUKpFg== X-Received: by 2002:a05:6a00:ad06:b0:81a:857b:f944 with SMTP id d2e1a72fcca58-81b7dc5b474mr2840179b3a.26.1767796999769; Wed, 07 Jan 2026 06:43:19 -0800 (PST) Received: from karthik.. ([43.247.159.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c59da826sm5168936b3a.46.2026.01.07.06.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 06:43:19 -0800 (PST) From: Karthikey D Kadati To: Hans de Goede , Mauro Carvalho Chehab Cc: Dan Carpenter , Sakari Ailus , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Karthikey D Kadati Subject: [PATCH v3 2/3] media: atomisp: consolidate statistics buffer allocation Date: Wed, 7 Jan 2026 20:12:51 +0530 Message-ID: <20260107144252.74666-3-karthikey3608@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260107144252.74666-1-karthikey3608@gmail.com> References: <20260107144252.74666-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 the actual error code on failure (instead of hardcoded -ENOMEM), 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 | 127 ++++++++++++------ 1 file changed, 85 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..c81773a75 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -678,13 +678,82 @@ 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; + int ret; + + 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; + + ret =3D atomisp_css_allocate_stat_buffers(asd, + stream_id, + s3a_buf, + NULL, + NULL); + if (ret) { + kfree(s3a_buf); + return ret; + } + 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; + + ret =3D atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + dis_buf, + NULL); + if (ret) { + kfree(dis_buf); + return ret; + } + 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; + + ret =3D atomisp_css_allocate_stat_buffers(asd, + stream_id, + NULL, + NULL, + md_buf); + if (ret) { + kfree(md_buf); + return ret; + } + 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 +764,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 +788,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