From patchwork Thu Apr 17 06:53:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 882518 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 809AE2192F1 for ; Thu, 17 Apr 2025 06:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744872858; cv=none; b=SHkwoPKmqZ5LVGrSnIGAT1kE6Rzb6OnoDrPu3nKLCtbvlfhLv2QG6kaLlhNRz+rCtimsDzGNknK6lljeW4wcMwy+VIy9nUWknAbUDjvnJYv2Z6CiRzvPMTDs3u2n5wGh0SoTYGpHhD+yYde8TWC90tMY3JzhUqHsfhg9N5QoFy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744872858; c=relaxed/simple; bh=tJrfZIBfIIHeUGHAJVsvi4AvNbQNY7JCbUw5PkWBQkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ndz4TWNZLqfdtZTFC++mb95JwJNQy1hksX+VgEISc8n+svE5xX/1XQ4MqoVMkclDdZwSwrnpNhHvlxwnzCsdA0NkVwft9JulOgeubLVsNnGUVsPPUv5JwCHvOoQ85Sx2A3ccOeP/k+Xgvpio2+9rSLrTaErVDcHX6fgOM/w/oR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=m+B+tDwL; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="m+B+tDwL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744872856; x=1776408856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tJrfZIBfIIHeUGHAJVsvi4AvNbQNY7JCbUw5PkWBQkA=; b=m+B+tDwLVctAAP8XeQ6+QMbcmjz5vE55PbRut5kDJ3MDase09EwugHDW fxNiW3yShQSURr6E9YqH9N7WJ1si22+ZLPmOvUvzIc8VP77eryQccjydi o8WwQgASBc9D88resp6MRa/A+E+BGWCtxEN53i3QTPkCkbJzert08TiWU RFd4djtznpWRf3iiilKxwVkQiG4/Y/TmusaKr/o89mUZnWHiTZ6LRbpdn BGnX+ZSZkmqV71THkDv1fckjCdiNKlMfqmenOHZECA9/Go5nbnMsRdhQI 92EVpKC9EKThtWHqdLBa3onWFACdGUTEWVBnQ+bOsYoktRXxBB2zosA22 w==; X-CSE-ConnectionGUID: itgud0dJTm2zTJE4ddKPEQ== X-CSE-MsgGUID: Lvp4ryJrSTSXAsO6bi6dUA== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="71831290" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="71831290" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 23:54:12 -0700 X-CSE-ConnectionGUID: At2TKzNPQ3C6Lcnz2bwWwQ== X-CSE-MsgGUID: Sn0swTlwSa+St7KClJYxgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="131262202" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 23:54:11 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 2E19D120806; Thu, 17 Apr 2025 09:54:05 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.96) (envelope-from ) id 1u5J8P-001J5K-0Y; Thu, 17 Apr 2025 09:54:05 +0300 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, dongcheng.yan@intel.com Subject: [PATCH v2 09/11] media: ccs-pll: Better validate VT PLL branch Date: Thu, 17 Apr 2025 09:53:52 +0300 Message-Id: <20250417065354.311617-10-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250417065354.311617-1-sakari.ailus@linux.intel.com> References: <20250417065354.311617-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Check that the VT PLL dividers are actually found, don't trust they always are even though they should be. Signed-off-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ccs-pll.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ccs-pll.c b/drivers/media/i2c/ccs-pll.c index 3f8153fb4af0..fc6f8aff5fd8 100644 --- a/drivers/media/i2c/ccs-pll.c +++ b/drivers/media/i2c/ccs-pll.c @@ -449,7 +449,7 @@ static int ccs_pll_calculate_vt_tree(struct device *dev, return -EINVAL; } -static void +static int ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *pll_fr, @@ -572,6 +572,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, if (best_pix_div < SHRT_MAX >> 1) break; } + if (best_pix_div == SHRT_MAX >> 1) + return -EINVAL; pll->vt_bk.sys_clk_div = DIV_ROUND_UP(vt_div, best_pix_div); pll->vt_bk.pix_clk_div = best_pix_div; @@ -584,6 +586,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, out_calc_pixel_rate: pll->pixel_rate_pixel_array = pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes; + + return 0; } /* @@ -863,8 +867,10 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, if (pll->flags & CCS_PLL_FLAG_DUAL_PLL) break; - ccs_pll_calculate_vt(dev, lim, op_lim_bk, pll, op_pll_fr, - op_pll_bk, cphy, phy_const); + rval = ccs_pll_calculate_vt(dev, lim, op_lim_bk, pll, op_pll_fr, + op_pll_bk, cphy, phy_const); + if (rval) + continue; rval = check_bk_bounds(dev, lim, pll, PLL_VT); if (rval)