devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Ming Qian <ming.qian@nxp.com>
Cc: mchehab@kernel.org, shawnguo@kernel.org, robh+dt@kernel.org,
	s.hauer@pengutronix.de, hverkuil-cisco@xs4all.nl,
	kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com,
	aisheng.dong@nxp.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v18 10/15] media: amphion: implement malone decoder rpc interface
Date: Wed, 9 Mar 2022 14:44:54 +0300	[thread overview]
Message-ID: <20220309114454.GB2592@kili> (raw)
In-Reply-To: <d0ab41721f15544646fac01c1902331476bddfbe.1645670589.git.ming.qian@nxp.com>

On Thu, Feb 24, 2022 at 11:10:08AM +0800, Ming Qian wrote:
> +static int vpu_malone_add_padding_scode(struct vpu_buffer *stream_buffer,
> +					struct vpu_malone_str_buffer __iomem *str_buf,
> +					u32 pixelformat, u32 scode_type)
> +{
> +	u32 wptr;
> +	u32 size;
> +	u32 total_size = 0;
> +	const struct malone_padding_scode *ps;
> +	const u32 padding_size = 4096;
> +	int ret;
> +
> +	ps = get_padding_scode(scode_type, pixelformat);
> +	if (!ps)
> +		return -EINVAL;
> +
> +	wptr = readl(&str_buf->wptr);
> +	size = ALIGN(wptr, 4) - wptr;

The ALIGN() macro can wrap to zero if wptr is > UINT_MAX - 4.  This
would make size into a very high unsigned value.

> +	if (size)
> +		vpu_helper_memset_stream_buffer(stream_buffer, &wptr, 0, size);
> +	total_size += size;
> +
> +	size = sizeof(ps->data);
> +	ret = vpu_helper_copy_to_stream_buffer(stream_buffer, &wptr, size, (void *)ps->data);
> +	if (ret < size)

The problem here is that size is a u32 so ret is type promoted to a u32
and (u32)-EINVAL > size so the condition is impossible.

> +		return -EINVAL;
> +	total_size += size;
> +
> +	size = padding_size - sizeof(ps->data);
> +	vpu_helper_memset_stream_buffer(stream_buffer, &wptr, 0, size);
> +	total_size += size;
> +
> +	vpu_malone_update_wptr(str_buf, wptr);
> +	return total_size;

What was the point of making total_size a u32 if the function itself is
and int?

> +}

[ snip ]

> +static int vpu_malone_input_frame_data(struct vpu_malone_str_buffer __iomem *str_buf,
> +				       struct vpu_inst *inst, struct vb2_buffer *vb,
> +				       u32 disp_imm)
> +{
> +	struct malone_scode_t scode;
> +	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> +	u32 wptr = readl(&str_buf->wptr);
> +	int size = 0;
> +	int ret = 0;
> +
> +	/*add scode: SCODE_SEQUENCE, SCODE_PICTURE, SCODE_SLICE*/
> +	scode.inst = inst;
> +	scode.vb = vb;
> +	scode.wptr = wptr;
> +	scode.need_data = 1;
> +	if (vbuf->sequence == 0 || vpu_vb_is_codecconfig(vbuf))
> +		ret = vpu_malone_insert_scode(&scode, SCODE_SEQUENCE);
> +
> +	if (ret < 0)
> +		return -ENOMEM;
> +	size += ret;
> +	wptr = scode.wptr;
> +	if (!scode.need_data) {
> +		vpu_malone_update_wptr(str_buf, wptr);
> +		return size;
> +	}
> +
> +	ret = vpu_malone_insert_scode(&scode, SCODE_PICTURE);
> +	if (ret < 0)
> +		return -ENOMEM;
> +	size += ret;
> +	wptr = scode.wptr;
> +
> +	ret = vpu_helper_copy_to_stream_buffer(&inst->stream_buffer,
> +					       &wptr,
> +					       vb2_get_plane_payload(vb, 0),
> +					       vb2_plane_vaddr(vb, 0));
> +	if (ret < vb2_get_plane_payload(vb, 0))

Here again, negative values of "ret" are type promoted to high unsigned
values so the condition is impossible.

> +		return -ENOMEM;
> +	size += ret;
> +
> +	vpu_malone_update_wptr(str_buf, wptr);
> +
> +	if (disp_imm && !vpu_vb_is_codecconfig(vbuf)) {
> +		ret = vpu_malone_add_scode(inst->core->iface,
> +					   inst->id,
> +					   &inst->stream_buffer,
> +					   inst->out_format.pixfmt,
> +					   SCODE_PADDING_BUFFLUSH);
> +		if (ret < 0)
> +			return ret;
> +		size += ret;
> +	}
> +
> +	return size;
> +}
> +
> +static int vpu_malone_input_stream_data(struct vpu_malone_str_buffer __iomem *str_buf,
> +					struct vpu_inst *inst, struct vb2_buffer *vb)
> +{
> +	u32 wptr = readl(&str_buf->wptr);
> +	int ret = 0;
> +
> +	ret = vpu_helper_copy_to_stream_buffer(&inst->stream_buffer,
> +					       &wptr,
> +					       vb2_get_plane_payload(vb, 0),
> +					       vb2_plane_vaddr(vb, 0));
> +	if (ret < vb2_get_plane_payload(vb, 0))

Same thing.  This condition is impossible.

> +		return -ENOMEM;
> +
> +	vpu_malone_update_wptr(str_buf, wptr);
> +
> +	return ret;
> +}

regards,
dan carpenter


  reply	other threads:[~2022-03-09 11:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24  3:09 [PATCH v18 00/15] amphion video decoder/encoder driver Ming Qian
2022-02-24  3:09 ` [PATCH v18 01/15] dt-bindings: media: amphion: add amphion video codec bindings Ming Qian
2022-02-24  3:10 ` [PATCH v18 02/15] media: add nv12m_8l128 and nv12m_10be_8l128 video format Ming Qian
2022-02-24  3:10 ` [PATCH v18 03/15] media: amphion: add amphion vpu device driver Ming Qian
2022-02-24  3:10 ` [PATCH v18 04/15] media: amphion: add vpu core driver Ming Qian
2022-03-09 12:06   ` Dan Carpenter
2022-02-24  3:10 ` [PATCH v18 05/15] media: amphion: implement vpu core communication based on mailbox Ming Qian
2022-03-09 12:23   ` Dan Carpenter
2022-02-24  3:10 ` [PATCH v18 06/15] media: amphion: add vpu v4l2 m2m support Ming Qian
2022-03-09 11:34   ` Dan Carpenter
2022-03-10  1:55     ` [EXT] " Ming Qian
2022-02-24  3:10 ` [PATCH v18 07/15] media: amphion: add v4l2 m2m vpu encoder stateful driver Ming Qian
2022-02-24  3:10 ` [PATCH v18 08/15] media: amphion: add v4l2 m2m vpu decoder " Ming Qian
2022-02-24  3:10 ` [PATCH v18 09/15] media: amphion: implement windsor encoder rpc interface Ming Qian
2022-02-24  3:10 ` [PATCH v18 10/15] media: amphion: implement malone decoder " Ming Qian
2022-03-09 11:44   ` Dan Carpenter [this message]
2022-02-24  3:10 ` [PATCH v18 11/15] arm64: dts: freescale: imx8q: add imx vpu codec entries Ming Qian
2022-02-24  3:10 ` [PATCH v18 12/15] firmware: imx: scu-pd: imx8q: add vpu mu resources Ming Qian
2022-02-24  3:10 ` [PATCH v18 13/15] MAINTAINERS: add AMPHION VPU CODEC V4L2 driver entry Ming Qian
2022-02-24  3:10 ` [PATCH v18 14/15] arm64: defconfig: amphion: enable vpu driver Ming Qian
2022-02-24  3:10 ` [PATCH v18 15/15] media: amphion: add amphion vpu entry in Kconfig and Makefile Ming Qian

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=20220309114454.GB2592@kili \
    --to=dan.carpenter@oracle.com \
    --cc=aisheng.dong@nxp.com \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ming.qian@nxp.com \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@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;
as well as URLs for NNTP newsgroup(s).