mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: xkernel.wang@foxmail.com
Cc: sakari.ailus@iki.fi, mchehab@kernel.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: omap3isp: check the return of __ccp2_get_format()
Date: Fri, 4 Mar 2022 14:09:36 +0200	[thread overview]
Message-ID: <YiIBgDA7PQHYS59h@pendragon.ideasonboard.com> (raw)
In-Reply-To: <tencent_E6A97F6B1009E6F65C230E070A9770612507@qq.com>

Hello Xiaoke,

Thank you for the patch.

On Fri, Mar 04, 2022 at 07:48:18PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> __ccp2_get_format() returns format structure or NULL on error.
> So it is better to check the return value of it to prevent potential
> wrong memory access.

The function can actually never return NULL if it's called with a valid
pad number, which should always be the case as far as I can tell (since
commit a8fa55078a778). This patch is thus not needed.

> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
>  drivers/media/platform/omap3isp/ispccp2.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
> index acb58b6..81881b1 100644
> --- a/drivers/media/platform/omap3isp/ispccp2.c
> +++ b/drivers/media/platform/omap3isp/ispccp2.c
> @@ -675,8 +675,10 @@ static void ccp2_try_format(struct isp_ccp2_device *ccp2,
>  		 */
>  		format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SINK,
>  					   which);
> -		memcpy(fmt, format, sizeof(*fmt));
> -		fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
> +		if (format != NULL) {
> +			memcpy(fmt, format, sizeof(*fmt));
> +			fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
> +		}
>  		break;
>  	}
>  
> @@ -709,6 +711,9 @@ static int ccp2_enum_mbus_code(struct v4l2_subdev *sd,
>  
>  		format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SINK,
>  					   code->which);
> +		if (format == NULL)
> +			return -EINVAL;
> +
>  		code->code = format->code;
>  	}
>  
> @@ -792,6 +797,9 @@ static int ccp2_set_format(struct v4l2_subdev *sd,
>  	if (fmt->pad == CCP2_PAD_SINK) {
>  		format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SOURCE,
>  					   fmt->which);
> +		if (format == NULL)
> +			return -EINVAL;
> +
>  		*format = fmt->format;
>  		ccp2_try_format(ccp2, sd_state, CCP2_PAD_SOURCE, format,
>  				fmt->which);

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2022-03-04 12:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 11:48 xkernel.wang
2022-03-04 12:09 ` Laurent Pinchart [this message]

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=YiIBgDA7PQHYS59h@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=xkernel.wang@foxmail.com \
    /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®