From nobody Sun Feb 8 23:04:05 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 28AD235F8D4 for ; Wed, 7 Jan 2026 15:09:35 +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=1767798576; cv=none; b=ccnAidog/bIw6dt0v/9GBX50hfiiZ/51hBnIc2E6HjXkrnGTaVi+p0ugCPz4WFJFxidhu17ITWG7jVY+AOGmTpmBEjAdGqpSquen8K7bMQk6WmRQD27KKV9yqVAkQiwaqdOAS7XnrJgfhhuX90QYf3RbxU8b+HX8NlQBegsWMiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767798576; c=relaxed/simple; bh=iGThI7AMvpXUH2QvGeoBUTMOmlzpo8uINvbPcxu0oHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vFvggd7G1FaajPG8Fi4FLRlbe34wl2hHQn6ofBmA+vB2iEPMGnMw0+bQAIaN6ocIaV+qdK3fNbcpEN7Qx0ThaoXd8s/lbdcYDvCxqcBL9T/rm2rxQdDT/ggbZbNGNkxXHFT/0Rg21bo5sS1/al4tKL3C2hOGG2tKQqO6+3VNxAE= 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=dTv8eUix; 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="dTv8eUix" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7b8eff36e3bso2511259b3a.2 for ; Wed, 07 Jan 2026 07:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767798574; x=1768403374; 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=839scXuIahBjk14ZPBwF1ot2Ofseckln89nJ0huuhEU=; b=dTv8eUixXPWQIz8vXukRw2gjb24E5bhcWjl2tJ60kGhZvvVoNlmzlNMLTboqrpuFAq LuxMOhENQWNEkW7YcN9JixMluMfwate5O7oPfoynynWNB0OHCH8qWKVmGr8I0aLcoISa oJYOSKVdVp7WPgKLC7/vVNZTPHkost/iEPUIj02g0xHM7hZjsBih/qTir2C5cIba9lpV 9WwWxtECctydUinw8eDMGJ4yBwicZpbE528qEe7Qm005Zl5YfbtoD6iXJk124jgamHUN SUToLVPF40xQaTkn7Q4Lget6N1rHYUEIsdvq5sJIKyiz2RsChshKp+BZMCm/Zpy4cpDD v9IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767798574; x=1768403374; 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=839scXuIahBjk14ZPBwF1ot2Ofseckln89nJ0huuhEU=; b=wshEmgpBNNSluIAmgSIezyivK9Flygb2KfptletlQpE6JLt5mNupL1SoI6pFeS0MvK tHDwiNp+am3yrrdjqk1sv6H4xOAiPfJtXvl3P/e4frWeoX/6n5ZNdrIOeAxGRgMoAkS2 2nDQPDiO1AkDjAGbkMTHlJR96GXmYBjqrHUrRw3kNtoItI1kwP0lIeBfLsFxLINnrg1s FE4kYKMX6CmiZxcCJ2HHO2VWzYfiAnJilU4ry+1xhOGsLprJICtRH8L2KEou5QHUxE2n IG6t3ZWwh4faZjc0wOqk6HSJU2eudwBQBiO71KMFCcP/xd1fhA+T1vyZY7dvxDwGVjBB IsyA== X-Forwarded-Encrypted: i=1; AJvYcCVN5Y/I2577twBSAOL4tQ6xUdLpeuGvbO5mrwZw51aCANR7TWvKW0bGMUZgzCHNAYC8sMcPta+MAJaKJZA=@vger.kernel.org X-Gm-Message-State: AOJu0YyK0DtDVtZcCOX27WLlR7L9kiHRIpHIDQhPQfZbPhSblCJIFr+B V+dWXnKSZSLTbiyQ43bxj6dMLKs+etkFQcra2lWSjIDMMQjNeS9E2AvF X-Gm-Gg: AY/fxX5W1JMOnyCuJkKuQIlHYPg1aGK5ssYmR4Wx55FnHkrVHIRw/068MOkNqYWEBuW UekN9OwloflEE+zOOKBMOXflY8SHMGooe20VqiS6u6HFlYVcw4PfaGFmYrb2JdudT3aTF1X8jTF i5WAC42LAZZE6ZcogU200fo2Un3TLlbOsmJ5iyfZPiihaic9ox4Dpqjdg69r+3tMBNNc9XoLZkc 87ZXl81CmaYVxGdWTRrxuj8tpiN4xYTNUI7UcL4IaU9JionJ9QgH6+uoU/+WsTx6kf+GTpiuScD Bl6tH77i64rTx2oaVxMvRPAVK9z5lslsrw/ZekDiFj+QRMVKvjB6lZEzJ+PzLZUhRtIl6RgQbAv +PcX+mAOpaF6yE+27DUumojj9asjcK5av/0IquJB5f+fwW+RvHXJwkt5ETzRGFc+NWjEEi0Np7m lyViLdgalJauU= X-Google-Smtp-Source: AGHT+IHBpXqkh/7RGbwjPDPLci2dCtXCz7QKcOwf/IAx50TXMsFMeoxMZ4/+sP8T0Bj6SQUlodTgPg== X-Received: by 2002:a05:6a00:f04:b0:7a9:c21a:559a with SMTP id d2e1a72fcca58-81b7d86249cmr2486687b3a.8.1767798574470; Wed, 07 Jan 2026 07:09:34 -0800 (PST) Received: from karthik.. ([43.247.159.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c59df961sm5246114b3a.47.2026.01.07.07.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 07:09:34 -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 v4 2/3] media: atomisp: consolidate statistics buffer allocation Date: Wed, 7 Jan 2026 20:38:57 +0530 Message-ID: <20260107150858.79818-3-karthikey3608@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260107150858.79818-1-karthikey3608@gmail.com> References: <20260107150858.79818-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