mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: keke.li@amlogic.com
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, kieran.bingham@ideasonboard.com,
	laurent.pinchart@ideasonboard.com, dan.scally@ideasonboard.com,
	jacopo.mondi@ideasonboard.com
Subject: Re: [PATCH v9 08/10] media: platform: Add C3 ISP driver
Date: Thu, 8 May 2025 15:44:47 +0000	[thread overview]
Message-ID: <aBzRb8ZKuGI3E_cu@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <20250427-c3isp-v9-8-e0fe09433d94@amlogic.com>

Hi Keke, Jacopo,

On Sun, Apr 27, 2025 at 02:27:16PM +0800, Keke Li via B4 Relay wrote:
> diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
> new file mode 100644
> index 000000000000..0e0b5d61654a
> --- /dev/null
> +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c

...

> +static int c3_isp_params_vb2_buf_prepare(struct vb2_buffer *vb)
> +{
> +	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> +	struct c3_isp_params_buffer *buf = to_c3_isp_params_buffer(vbuf);
> +	struct c3_isp_params *params = vb2_get_drv_priv(vb->vb2_queue);
> +	struct c3_isp_params_cfg *cfg = buf->cfg;
> +	struct c3_isp_params_cfg *usr_cfg = vb2_plane_vaddr(vb, 0);
> +	size_t payload_size = vb2_get_plane_payload(vb, 0);
> +	size_t header_size = offsetof(struct c3_isp_params_cfg, data);
> +	size_t block_offset = 0;
> +	size_t cfg_size;
> +
> +	/* Payload size can't be greater than the destination buffer size */
> +	if (payload_size > params->vfmt.fmt.meta.buffersize) {
> +		dev_dbg(params->isp->dev,
> +			"Payload size is too large: %zu\n", payload_size);
> +		return -EINVAL;
> +	}
> +
> +	/* Payload size can't be smaller than the header size */
> +	if (payload_size < header_size) {
> +		dev_dbg(params->isp->dev,
> +			"Payload size is too small: %zu\n", payload_size);
> +		return -EINVAL;
> +	}
> +
> +	/*
> +	 * Use the internal scratch buffer to avoid userspace modifying
> +	 * the buffer content while the driver is processing it.
> +	 */
> +	memcpy(cfg, usr_cfg, payload_size);
> +
> +	/* Only v0 is supported at the moment */
> +	if (cfg->version != C3_ISP_PARAMS_BUFFER_V0) {
> +		dev_dbg(params->isp->dev,
> +			"Invalid params buffer version: %u\n", cfg->version);
> +		return -EINVAL;
> +	}
> +
> +	/* Validate the size reported in the parameter buffer header */
> +	cfg_size = header_size + cfg->data_size;
> +	if (cfg_size != payload_size) {
> +		dev_dbg(params->isp->dev,
> +			"Data size %zu and payload size %zu are different\n",
> +			cfg_size, payload_size);
> +		return -EINVAL;
> +	}
> +
> +	/* Walk the list of parameter blocks and validate them */
> +	cfg_size = cfg->data_size;
> +	while (cfg_size >= sizeof(struct c3_isp_params_block_header)) {
> +		const struct c3_isp_params_block_header *block;
> +		const struct c3_isp_params_handler *handler;
> +
> +		block = (struct c3_isp_params_block_header *)
> +			&cfg->data[block_offset];
> +
> +		if (block->type >= ARRAY_SIZE(c3_isp_params_handlers)) {
> +			dev_dbg(params->isp->dev,
> +				"Invalid params block type\n");
> +			return -EINVAL;
> +		}
> +
> +		if (block->size > cfg_size) {
> +			dev_dbg(params->isp->dev,
> +				"Block size is greater than cfg size\n");
> +			return -EINVAL;
> +		}
> +
> +		if ((block->flags & (C3_ISP_PARAMS_BLOCK_FL_ENABLE |
> +				     C3_ISP_PARAMS_BLOCK_FL_DISABLE)) ==
> +		    (C3_ISP_PARAMS_BLOCK_FL_ENABLE |
> +		     C3_ISP_PARAMS_BLOCK_FL_DISABLE)) {
> +			dev_dbg(params->isp->dev,
> +				"Invalid parameters block flags\n");
> +			return -EINVAL;
> +		}
> +
> +		handler = &c3_isp_params_handlers[block->type];
> +		if (block->size != handler->size) {
> +			dev_dbg(params->isp->dev,
> +				"Invalid params block size\n");
> +			return -EINVAL;
> +		}
> +
> +		block_offset += block->size;
> +		cfg_size -= block->size;
> +	}
> +
> +	if (cfg_size) {
> +		dev_dbg(params->isp->dev,
> +			"Unexpected data after the params buffer end\n");
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}

The above looks very much like rkisp1_params_prepare_ext_params() in the
Rockchip ISP driver. Instead of copying all this non-trivial code in
verbatim here, could you instead refactor this so both the drivers could
use the same implementation?

The types are different so macros will be likely needed.

-- 
Regards,

Sakari Ailus

  reply	other threads:[~2025-05-08 15:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-27  6:27 [PATCH v9 00/10] Amlogic C3 ISP support Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 01/10] dt-bindings: media: Add amlogic,c3-mipi-csi2.yaml Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 02/10] media: platform: Add C3 MIPI CSI-2 driver Keke Li via B4 Relay
2025-05-08 15:28   ` Sakari Ailus
2025-04-27  6:27 ` [PATCH v9 03/10] dt-bindings: media: Add amlogic,c3-mipi-adapter.yaml Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 04/10] media: platform: Add C3 MIPI adapter driver Keke Li via B4 Relay
2025-05-08 15:33   ` Sakari Ailus
2025-04-27  6:27 ` [PATCH v9 05/10] dt-bindings: media: Add amlogic,c3-isp.yaml Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 06/10] media: Add C3ISP_PARAMS and C3ISP_STATS meta formats Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 07/10] media: uapi: Add stats info and parameters buffer for C3 ISP Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 08/10] media: platform: Add C3 ISP driver Keke Li via B4 Relay
2025-05-08 15:44   ` Sakari Ailus [this message]
2025-05-08 16:28     ` Jacopo Mondi
2025-05-08 21:00       ` Sakari Ailus
2025-05-09  8:00         ` Jacopo Mondi
2025-05-09  8:04           ` Sakari Ailus
2025-04-27  6:27 ` [PATCH v9 09/10] Documentation: media: add documentation file metafmt-c3-isp.rst Keke Li via B4 Relay
2025-04-27  6:27 ` [PATCH v9 10/10] Documentation: media: add documentation file c3-isp.rst Keke Li via B4 Relay
2025-05-08 13:18   ` Jacopo Mondi
2025-05-08 16:09 ` [PATCH v9 00/10] Amlogic C3 ISP support Sakari Ailus
2025-05-09  5:48   ` Keke Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aBzRb8ZKuGI3E_cu@valkosipuli.retiisi.eu \
    --to=sakari.ailus@iki.fi \
    --cc=conor+dt@kernel.org \
    --cc=dan.scally@ideasonboard.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=keke.li@amlogic.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=krzk+dt@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®