From nobody Mon Feb 9 13:03:00 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 45C0E331A6D for ; Wed, 7 Jan 2026 13:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767793754; cv=none; b=l+Z1aF8VvaxIZX5t4snhHPgoxUuZEtyw0a8L2YH39JUIDasq5ETYRrRLIArQ+/c9WofXk5lWbmQS7eliCDpptw4r/jh1RHxmclIwj5o7UIPA8U2VB5p+HZmE8a1whE8HBApJn6P4b5ZBg0euYIqO3vu8UprEzAk6uNNjHh05v4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767793754; c=relaxed/simple; bh=TKIKwvBOWkccmdrv2iMfjupuseLH7sbcozqajmk2NEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMSDxofX3CR5gF9qtkuPJganVDPpVDLaIBnQBX8LRPd/cSZu8QdXuLzgSJxE27p50123YGKq/+fb6rRwwbxPrCkmgml4S6DgbIncX9xNclPbpBCva1VzIZ7YI6tplpp6SBrO1uR662qRC/rePyBe7KOa6TFj4OPAOg/zRS8XiMs= 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=TYWoSomd; arc=none smtp.client-ip=209.85.210.178 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="TYWoSomd" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-803474aaa8bso501590b3a.0 for ; Wed, 07 Jan 2026 05:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767793751; x=1768398551; 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=w43P1JW4wQheNkrfXzMs1sXhL7mJiuv4h8HUQUHGvjE=; b=TYWoSomdteo5bClMZf4MKCH2GGvcW6HZFY7GXzs39bg9zE46eodTrlS9qHRsM4sTse wkYuATdN9I2bcgNluh8wr1RrSF6VZ4PLtYbuXT9Lb7p0uksYc2BVcd10+323h9piM0Rw 7HLN4HwO3oA8EFmF95pUJDCMd1A6j1oT/RBdRGIvTaDnHYidL6qqk1jtD50sQeTWDHtM NWRGb6GsxE2CkRsG1DacNzbYM9I1w4t0vBBgGNHIdhxGD7NGxj0zKT9wT+3/e06xEhXY 4mnwEKgVJduGksnwrDiExoC89dXWwhx8ebNseSUQHhU8hfy2ehLUbhim5XW0h/U6lpZi 4qxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767793751; x=1768398551; 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=w43P1JW4wQheNkrfXzMs1sXhL7mJiuv4h8HUQUHGvjE=; b=NogIVaQA79TmvtkWYpUsJcp3I1v4RiqeVGTv0AQn+uig6RBdMI9UytY4wBbgTNbqHM As0YVJqv532jvcqJiwdVbOm58CvTBweAKPGHNDbR3+Xxad5JSeMY74F0RZQb8odf+11H Eyj1XICxYa3YvArGNakA4+onxnkmFCsezMYZ6uo05/bcaPlfxXTZdQ7ID9RDsGtyqAfC SOYubyuzEOSe/bzo2qcWe/woul0+cownC8cuTa+zHUVg2uKBrUPgfvwLRwMnUQEwQabg vNcEAfw0fw0pY3Tpd4xBaTUPxnUYbxNqOzJ+dtsUCrTmZdqVv9NJgl5ZTbe0B5YYhq2t xJLw== X-Forwarded-Encrypted: i=1; AJvYcCXEHOnezHBM301bFf8lwuZJFsbiYByqz9UGDJahaJVRqKNd6RQWhzZfWLeUdutiWTSWBqoCDpq1g5cQTyw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxnr+yvdyMei47gRDj3m/JikreGSuzd/+tOqz9afEpIBpM7uOSH hhmO8jaVEktrMfwqsSw/+Cy62jQY2EIvIC6f9b39tQVULwr0AEHrgBY7 X-Gm-Gg: AY/fxX7Zghc9RhM8ruKtpTQoylSz41jorRwDeSPOp9jdnx0p/NbjaTpjLHlyNjENV2j FUJpQh2GSyJrzxN+l9tGFsKWVJi9iGObAaTRnS6aA5N0edJS/wVTinBvIPgMohBJuTiagm0jS8O D/J2OGtFCKF7M/8Y62ul3V90FDmpmehDnOevVF3lLXAULnoeu+3y9hCQa5gUIg2WYWF10HG8I6/ 3JCzmp7InbMNyknc83AXZDTQHiJxQ6YtkYvDCjuABN7ChA8jJw2xVDDqc5R/Vf42qs+EdW8lzNg XB35f1PItNaVEf50KQi0xIsNGyVPK/zlYjLxjuE3qVPmvSR+CJJRa52BLrpUILYGtKhyXvz8PMm WiFYB7QH4golX9RprivPl72+oC0agU4WN61D3AXgXhhUjVduj/s1qyvUGdnBbYhk/f2wgJBcTTl zo8rwdF64M7vQWPzt5cEbbuA== X-Google-Smtp-Source: AGHT+IFQ4GDmNAoC50jk0wNrLfNYdKjs2GMJ5j6/dQToki8zi994DWS8NNBarDyaS4anHOX2nPSk2A== X-Received: by 2002:a05:6a00:908e:b0:81b:1a87:9eb8 with SMTP id d2e1a72fcca58-81b789a9c08mr2586363b3a.28.1767793751268; Wed, 07 Jan 2026 05:49:11 -0800 (PST) Received: from karthik.. ([43.247.159.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c5302c61sm5109577b3a.42.2026.01.07.05.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 05:49:10 -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 1/3] media: atomisp: replace shadow zoom structs with v4l2_rect Date: Wed, 7 Jan 2026 19:18:42 +0530 Message-ID: <20260107134844.68074-2-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" Remove custom atomisp_zoom_point and atomisp_zoom_region structs and usage in favor of standard v4l2_rect within atomisp_dz_config. This aligns the driver with V4L2 standards and removes unnecessary custom types. Also standardizes the internal ia_css_region struct members to match V4L2 naming conventions (left, top, width, height) to facilitate the bridge mapping. Updates atomisp_cmd.c and sh_css_params.c to use the new member names and ensures safe math using long long casts to prevent overflow during resolution scaling. Signed-off-by: Karthikey D Kadati --- .../media/atomisp/include/linux/atomisp.h | 19 +-- .../staging/media/atomisp/pci/atomisp_cmd.c | 130 +++++++++--------- .../staging/media/atomisp/pci/ia_css_types.h | 6 +- .../staging/media/atomisp/pci/sh_css_params.c | 16 +-- 4 files changed, 79 insertions(+), 92 deletions(-) diff --git a/drivers/staging/media/atomisp/include/linux/atomisp.h b/driver= s/staging/media/atomisp/include/linux/atomisp.h index fcf116cc4..b5cce12c1 100644 --- a/drivers/staging/media/atomisp/include/linux/atomisp.h +++ b/drivers/staging/media/atomisp/include/linux/atomisp.h @@ -326,27 +326,12 @@ struct atomisp_resolution { u32 height; /** Height */ }; =20 -/* - * This specifies the coordinates (x,y) - */ -struct atomisp_zoom_point { - s32 x; /** x coordinate */ - s32 y; /** y coordinate */ -}; - -/* - * This specifies the region - */ -struct atomisp_zoom_region { - struct atomisp_zoom_point - origin; /* Starting point coordinates for the region */ - struct atomisp_resolution resolution; /* Region resolution */ -}; +#include =20 struct atomisp_dz_config { u32 dx; /** Horizontal zoom factor */ u32 dy; /** Vertical zoom factor */ - struct atomisp_zoom_region zoom_region; /** region for zoom */ + struct v4l2_rect zoom_region; /** region for zoom */ }; =20 struct atomisp_parm { diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/stag= ing/media/atomisp/pci/atomisp_cmd.c index 327836372..4ed6b8aea 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -1764,15 +1764,13 @@ int atomisp_calculate_real_zoom_region(struct atomi= sp_sub_device *asd, return -EINVAL; } =20 - if (dz_config->zoom_region.resolution.width - =3D=3D asd->sensor_array_res.width - || dz_config->zoom_region.resolution.height - =3D=3D asd->sensor_array_res.height) { + if (dz_config->zoom_region.width =3D=3D asd->sensor_array_res.width || + dz_config->zoom_region.height =3D=3D asd->sensor_array_res.height) { /*no need crop region*/ - dz_config->zoom_region.origin.x =3D 0; - dz_config->zoom_region.origin.y =3D 0; - dz_config->zoom_region.resolution.width =3D eff_res.width; - dz_config->zoom_region.resolution.height =3D eff_res.height; + dz_config->zoom_region.left =3D 0; + dz_config->zoom_region.top =3D 0; + dz_config->zoom_region.width =3D eff_res.width; + dz_config->zoom_region.height =3D eff_res.height; return 0; } =20 @@ -1783,18 +1781,18 @@ int atomisp_calculate_real_zoom_region(struct atomi= sp_sub_device *asd, */ =20 if (!IS_ISP2401) { - dz_config->zoom_region.origin.x =3D dz_config->zoom_region.origin.x - * eff_res.width - / asd->sensor_array_res.width; - dz_config->zoom_region.origin.y =3D dz_config->zoom_region.origin.y - * eff_res.height - / asd->sensor_array_res.height; - dz_config->zoom_region.resolution.width =3D dz_config->zoom_region.resol= ution.width - * eff_res.width - / asd->sensor_array_res.width; - dz_config->zoom_region.resolution.height =3D dz_config->zoom_region.reso= lution.height - * eff_res.height - / asd->sensor_array_res.height; + dz_config->zoom_region.left =3D + (s32)((long long)dz_config->zoom_region.left * + eff_res.width / asd->sensor_array_res.width); + dz_config->zoom_region.top =3D + (s32)((long long)dz_config->zoom_region.top * + eff_res.height / asd->sensor_array_res.height); + dz_config->zoom_region.width =3D + (u32)((long long)dz_config->zoom_region.width * + eff_res.width / asd->sensor_array_res.width); + dz_config->zoom_region.height =3D + (u32)((long long)dz_config->zoom_region.height * + eff_res.height / asd->sensor_array_res.height); /* * Set same ratio of crop region resolution and current pipe output * resolution @@ -1821,62 +1819,66 @@ int atomisp_calculate_real_zoom_region(struct atomi= sp_sub_device *asd, - asd->sensor_array_res.width * out_res.height / out_res.width; h_offset =3D h_offset / 2; - if (dz_config->zoom_region.origin.y < h_offset) - dz_config->zoom_region.origin.y =3D 0; + if (dz_config->zoom_region.top < h_offset) + dz_config->zoom_region.top =3D 0; else - dz_config->zoom_region.origin.y =3D dz_config->zoom_region.origin.y - = h_offset; + dz_config->zoom_region.top -=3D h_offset; w_offset =3D 0; } else { w_offset =3D asd->sensor_array_res.width - asd->sensor_array_res.height * out_res.width / out_res.height; w_offset =3D w_offset / 2; - if (dz_config->zoom_region.origin.x < w_offset) - dz_config->zoom_region.origin.x =3D 0; + if (dz_config->zoom_region.left < w_offset) + dz_config->zoom_region.left =3D 0; else - dz_config->zoom_region.origin.x =3D dz_config->zoom_region.origin.x - = w_offset; + dz_config->zoom_region.left -=3D w_offset; h_offset =3D 0; } - dz_config->zoom_region.origin.x =3D dz_config->zoom_region.origin.x - * eff_res.width - / (asd->sensor_array_res.width - 2 * w_offset); - dz_config->zoom_region.origin.y =3D dz_config->zoom_region.origin.y - * eff_res.height - / (asd->sensor_array_res.height - 2 * h_offset); - dz_config->zoom_region.resolution.width =3D dz_config->zoom_region.resol= ution.width - * eff_res.width - / (asd->sensor_array_res.width - 2 * w_offset); - dz_config->zoom_region.resolution.height =3D dz_config->zoom_region.reso= lution.height - * eff_res.height - / (asd->sensor_array_res.height - 2 * h_offset); - } - - if (out_res.width * dz_config->zoom_region.resolution.height - > dz_config->zoom_region.resolution.width * out_res.height) { - dz_config->zoom_region.resolution.height =3D - dz_config->zoom_region.resolution.width - * out_res.height / out_res.width; + dz_config->zoom_region.left =3D + (s32)((long long)dz_config->zoom_region.left * + eff_res.width / + (asd->sensor_array_res.width - 2 * w_offset)); + dz_config->zoom_region.top =3D + (s32)((long long)dz_config->zoom_region.top * + eff_res.height / + (asd->sensor_array_res.height - 2 * h_offset)); + dz_config->zoom_region.width =3D + (u32)((long long)dz_config->zoom_region.width * + eff_res.width / + (asd->sensor_array_res.width - 2 * w_offset)); + dz_config->zoom_region.height =3D + (u32)((long long)dz_config->zoom_region.height * + eff_res.height / + (asd->sensor_array_res.height - 2 * h_offset)); + } + + if ((long long)out_res.width * dz_config->zoom_region.height > + (long long)dz_config->zoom_region.width * out_res.height) { + dz_config->zoom_region.height =3D + (u32)((long long)dz_config->zoom_region.width * + out_res.height / out_res.width); } else { - dz_config->zoom_region.resolution.width =3D - dz_config->zoom_region.resolution.height - * out_res.width / out_res.height; + dz_config->zoom_region.width =3D + (u32)((long long)dz_config->zoom_region.height * + out_res.width / out_res.height); } dev_dbg(asd->isp->dev, "%s crop region:(%d,%d),(%d,%d) eff_res(%d, %d) array_size(%d,%d) out_re= s(%d, %d)\n", - __func__, dz_config->zoom_region.origin.x, - dz_config->zoom_region.origin.y, - dz_config->zoom_region.resolution.width, - dz_config->zoom_region.resolution.height, + __func__, dz_config->zoom_region.left, + dz_config->zoom_region.top, + dz_config->zoom_region.width, + dz_config->zoom_region.height, eff_res.width, eff_res.height, asd->sensor_array_res.width, asd->sensor_array_res.height, out_res.width, out_res.height); =20 - if ((dz_config->zoom_region.origin.x + - dz_config->zoom_region.resolution.width + if ((dz_config->zoom_region.left + + dz_config->zoom_region.width > eff_res.width) || - (dz_config->zoom_region.origin.y + - dz_config->zoom_region.resolution.height + (dz_config->zoom_region.top + + dz_config->zoom_region.height > eff_res.height)) return -EINVAL; =20 @@ -1901,10 +1903,10 @@ static bool atomisp_check_zoom_region( =20 config.width =3D asd->sensor_array_res.width; config.height =3D asd->sensor_array_res.height; - w =3D dz_config->zoom_region.origin.x + - dz_config->zoom_region.resolution.width; - h =3D dz_config->zoom_region.origin.y + - dz_config->zoom_region.resolution.height; + w =3D dz_config->zoom_region.left + + dz_config->zoom_region.width; + h =3D dz_config->zoom_region.top + + dz_config->zoom_region.height; =20 if ((w <=3D config.width) && (h <=3D config.height) && w > 0 && h > 0) flag =3D true; @@ -1912,10 +1914,10 @@ static bool atomisp_check_zoom_region( /* setting error zoom region */ dev_err(asd->isp->dev, "%s zoom region ERROR:dz_config:(%d,%d),(%d,%d)array_res(%d, %d)\n", - __func__, dz_config->zoom_region.origin.x, - dz_config->zoom_region.origin.y, - dz_config->zoom_region.resolution.width, - dz_config->zoom_region.resolution.height, + __func__, dz_config->zoom_region.left, + dz_config->zoom_region.top, + dz_config->zoom_region.width, + dz_config->zoom_region.height, config.width, config.height); =20 return flag; diff --git a/drivers/staging/media/atomisp/pci/ia_css_types.h b/drivers/sta= ging/media/atomisp/pci/ia_css_types.h index 676d7e20b..5c21a5415 100644 --- a/drivers/staging/media/atomisp/pci/ia_css_types.h +++ b/drivers/staging/media/atomisp/pci/ia_css_types.h @@ -431,8 +431,10 @@ struct ia_css_point { * This specifies the region */ struct ia_css_region { - struct ia_css_point origin; /** Starting point coordinates for the region= */ - struct ia_css_resolution resolution; /** Region resolution */ + s32 left; /** Starting point coordinates for the region */ + s32 top; + s32 width; /** Region resolution */ + s32 height; }; =20 /** diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/st= aging/media/atomisp/pci/sh_css_params.c index 11d62313c..0435f20a7 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_params.c +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c @@ -658,9 +658,7 @@ static const struct ia_css_dz_config default_dz_config = =3D { HRT_GDC_N, HRT_GDC_N, { - \ - {0, 0}, \ - {0, 0}, \ + 0, 0, 0, 0 } }; =20 @@ -1210,8 +1208,8 @@ ia_css_process_zoom_and_motion( } =20 assert(stage->stage_num < SH_CSS_MAX_STAGES); - if (params->dz_config.zoom_region.resolution.width =3D=3D 0 && - params->dz_config.zoom_region.resolution.height =3D=3D 0) { + if (params->dz_config.zoom_region.width =3D=3D 0 && + params->dz_config.zoom_region.height =3D=3D 0) { sh_css_update_uds_and_crop_info( &info->sp, &binary->in_frame_info, @@ -4096,10 +4094,10 @@ sh_css_update_uds_and_crop_info_based_on_zoom_regio= n( assert(motion_vector); assert(uds); assert(sp_out_crop_pos); - x0 =3D zoom->zoom_region.origin.x; - y0 =3D zoom->zoom_region.origin.y; - x1 =3D zoom->zoom_region.resolution.width + x0; - y1 =3D zoom->zoom_region.resolution.height + y0; + x0 =3D zoom->zoom_region.left; + y0 =3D zoom->zoom_region.top; + x1 =3D zoom->zoom_region.width + x0; + y1 =3D zoom->zoom_region.height + y0; =20 if ((x0 > x1) || (y0 > y1) || (x1 > pipe_in_res.width) || (y1 > pipe_in_r= es.height)) return -EINVAL; --=20 2.43.0