From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 15E66331A6A for ; Wed, 7 Jan 2026 13:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767793754; cv=none; b=ZBpazkptt9jxsSRBwC2ihnDC/r+n8/ERTM89HWpZVRhenczz5Q0mRGBuH9UMsg8timaF6+wGYcrd0xbdTDe+HxpMiOQupHqJLkGN2DCCzUMtPG1/NhP4H/kf7+DxmkNNrwL4y6iM1Y9ceS6+lofQI9Tvllwx8nqTpkYyjCJ0Q+M= 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=TgICsiMh; arc=none smtp.client-ip=209.85.210.177 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="TgICsiMh" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-803474aaa8bso501588b3a.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=lists.linux.dev; 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=TgICsiMhFiF0jbQsOCHUvE29QnG908Wr1bZNFJKa83Pb1vniZ8Ur+fwvEFlYFNv42d dSYD+Q3DxMTLgyFocEszoPfu8V20/d3Q/09SeqBD3iyyG38ICDztx7LIgohus/ILKR/v eFk5EoOyuCaPoebPHlj6E15VXhNCujOnvHIDagY7O/GkSwreIfKy+Oe32lCmnZfL9qsC O1JmfbtYncNUtObQaZLlp8O3VyfyzMYd3jMOLjE2zj4ZFQKaMYKCcfsvKrbGR1O69yqw vp5A4TrVhX+7I2TfvP0ouRdkQToSWXStXp75TMUC+NIWOmo+TWi2UUU5Qt6fmuC6bq6n 03rA== 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=FTLdtoRzFwMzOUSaFIg0x1UqLMv5CT6t0FVmAtlUsKutRzCCUh9Wmy0uZ44bD3T1HV EYDzs03Jd0KcXujQu+S1Gi0VDgqvS4U2Zb7/8WVS9Vrg+XHWt9j93zDqjEZu8wJpFgbJ DoFnBDUu80WJ2YdZd8wMszf1G5cBB07RhowPzreAIK9VR3kx9MRNFqGiZHP38tAoskIX 7mG+H6BmBKTLMcnGtxzOSxmD5nONX0ODejNQ3kpQKaXtDaOPPb8rEE1xLEey2ojzX3ks fpnkOkB+wkHCRIl4oJW/kpHd5vla/TzeMO3S4gI2ZMKxAypW/L4kFM306nneRioQJV7x gtuw== X-Forwarded-Encrypted: i=1; AJvYcCXJ1LZUZy381/4jb2q02Slx7JU54zZRWAJeinG7/EiG6+xgRxwGz+OTpiIKzl5wl8jRs1pQLYawO+mBIt1l@lists.linux.dev X-Gm-Message-State: AOJu0YzcRpUXLhUPmUOq+63E7lMzgFXOjbTFTajCorfP7UA4azLGpAfA fU/1+9f9yNh9k3PNY5g+EENPqF4xWKjTj6dnxI/2JP2GYWepCzV/IrCh X-Gm-Gg: AY/fxX6NJ7Hz7SEwJZvZWnAj7hX4TAbUgS9zCkDJDXMUFeBcjTm4WjfFwXzPk9UCL8i zjaSGiM2katr+UQylxo86pmccpaOVem0XveOI8EjK3tWrzjNuQwECdCHVgEs4tVCl68CxdKWTde 708GnMc11zk/sdIfoCdhtT7VxD94G2Atum0Ji7Xqn4TYcbzu6WWzd7mtChEuEpU/5nCQs9bAp/+ mTv7wYjahThNR5CwTz3ucxMcwrEgkzaUoilToHjHJuB84BlL9p/Gx5+CW18bTz59OpdpRrVj8Ib rCxuUR0FNbkZh4L15DdD3RK5ubkyhIKa71vT5SLscpjDVDOXXYelt4x2F1BI62iPosH7YmXsZlJ pjD/KReJeHKLo2KloLeWyzVzpcNq2arYZD/xajG802c5UhtTMBs7Lt8wtPjCrJwcTy2/BfR0TtL usnZ12cqsTpxEOHw7kuXALVg== 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-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/drivers/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 */ }; -/* - * 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 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 */ }; struct atomisp_parm { diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/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 atomisp_sub_device *asd, return -EINVAL; } - if (dz_config->zoom_region.resolution.width - == asd->sensor_array_res.width - || dz_config->zoom_region.resolution.height - == asd->sensor_array_res.height) { + if (dz_config->zoom_region.width == asd->sensor_array_res.width || + dz_config->zoom_region.height == asd->sensor_array_res.height) { /*no need crop region*/ - dz_config->zoom_region.origin.x = 0; - dz_config->zoom_region.origin.y = 0; - dz_config->zoom_region.resolution.width = eff_res.width; - dz_config->zoom_region.resolution.height = eff_res.height; + dz_config->zoom_region.left = 0; + dz_config->zoom_region.top = 0; + dz_config->zoom_region.width = eff_res.width; + dz_config->zoom_region.height = eff_res.height; return 0; } @@ -1783,18 +1781,18 @@ int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd, */ if (!IS_ISP2401) { - dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x - * eff_res.width - / asd->sensor_array_res.width; - dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y - * eff_res.height - / asd->sensor_array_res.height; - dz_config->zoom_region.resolution.width = dz_config->zoom_region.resolution.width - * eff_res.width - / asd->sensor_array_res.width; - dz_config->zoom_region.resolution.height = dz_config->zoom_region.resolution.height - * eff_res.height - / asd->sensor_array_res.height; + dz_config->zoom_region.left = + (s32)((long long)dz_config->zoom_region.left * + eff_res.width / asd->sensor_array_res.width); + dz_config->zoom_region.top = + (s32)((long long)dz_config->zoom_region.top * + eff_res.height / asd->sensor_array_res.height); + dz_config->zoom_region.width = + (u32)((long long)dz_config->zoom_region.width * + eff_res.width / asd->sensor_array_res.width); + dz_config->zoom_region.height = + (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 atomisp_sub_device *asd, - asd->sensor_array_res.width * out_res.height / out_res.width; h_offset = h_offset / 2; - if (dz_config->zoom_region.origin.y < h_offset) - dz_config->zoom_region.origin.y = 0; + if (dz_config->zoom_region.top < h_offset) + dz_config->zoom_region.top = 0; else - dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y - h_offset; + dz_config->zoom_region.top -= h_offset; w_offset = 0; } else { w_offset = asd->sensor_array_res.width - asd->sensor_array_res.height * out_res.width / out_res.height; w_offset = w_offset / 2; - if (dz_config->zoom_region.origin.x < w_offset) - dz_config->zoom_region.origin.x = 0; + if (dz_config->zoom_region.left < w_offset) + dz_config->zoom_region.left = 0; else - dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x - w_offset; + dz_config->zoom_region.left -= w_offset; h_offset = 0; } - dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x - * eff_res.width - / (asd->sensor_array_res.width - 2 * w_offset); - dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y - * eff_res.height - / (asd->sensor_array_res.height - 2 * h_offset); - dz_config->zoom_region.resolution.width = dz_config->zoom_region.resolution.width - * eff_res.width - / (asd->sensor_array_res.width - 2 * w_offset); - dz_config->zoom_region.resolution.height = dz_config->zoom_region.resolution.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 = - dz_config->zoom_region.resolution.width - * out_res.height / out_res.width; + dz_config->zoom_region.left = + (s32)((long long)dz_config->zoom_region.left * + eff_res.width / + (asd->sensor_array_res.width - 2 * w_offset)); + dz_config->zoom_region.top = + (s32)((long long)dz_config->zoom_region.top * + eff_res.height / + (asd->sensor_array_res.height - 2 * h_offset)); + dz_config->zoom_region.width = + (u32)((long long)dz_config->zoom_region.width * + eff_res.width / + (asd->sensor_array_res.width - 2 * w_offset)); + dz_config->zoom_region.height = + (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 = + (u32)((long long)dz_config->zoom_region.width * + out_res.height / out_res.width); } else { - dz_config->zoom_region.resolution.width = - dz_config->zoom_region.resolution.height - * out_res.width / out_res.height; + dz_config->zoom_region.width = + (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_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, eff_res.width, eff_res.height, asd->sensor_array_res.width, asd->sensor_array_res.height, out_res.width, out_res.height); - 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; @@ -1901,10 +1903,10 @@ static bool atomisp_check_zoom_region( config.width = asd->sensor_array_res.width; config.height = asd->sensor_array_res.height; - w = dz_config->zoom_region.origin.x + - dz_config->zoom_region.resolution.width; - h = dz_config->zoom_region.origin.y + - dz_config->zoom_region.resolution.height; + w = dz_config->zoom_region.left + + dz_config->zoom_region.width; + h = dz_config->zoom_region.top + + dz_config->zoom_region.height; if ((w <= config.width) && (h <= config.height) && w > 0 && h > 0) flag = 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); return flag; diff --git a/drivers/staging/media/atomisp/pci/ia_css_types.h b/drivers/staging/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; }; /** diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/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 = { HRT_GDC_N, HRT_GDC_N, { - \ - {0, 0}, \ - {0, 0}, \ + 0, 0, 0, 0 } }; @@ -1210,8 +1208,8 @@ ia_css_process_zoom_and_motion( } assert(stage->stage_num < SH_CSS_MAX_STAGES); - if (params->dz_config.zoom_region.resolution.width == 0 && - params->dz_config.zoom_region.resolution.height == 0) { + if (params->dz_config.zoom_region.width == 0 && + params->dz_config.zoom_region.height == 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_region( assert(motion_vector); assert(uds); assert(sp_out_crop_pos); - x0 = zoom->zoom_region.origin.x; - y0 = zoom->zoom_region.origin.y; - x1 = zoom->zoom_region.resolution.width + x0; - y1 = zoom->zoom_region.resolution.height + y0; + x0 = zoom->zoom_region.left; + y0 = zoom->zoom_region.top; + x1 = zoom->zoom_region.width + x0; + y1 = zoom->zoom_region.height + y0; if ((x0 > x1) || (y0 > y1) || (x1 > pipe_in_res.width) || (y1 > pipe_in_res.height)) return -EINVAL; -- 2.43.0