public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sylwester Nawrocki <snawrocki@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	kernel-janitors@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH] [media] s3c-camif: array underflow in __camif_subdev_try_format()
Date: Mon, 22 Jan 2018 21:50:04 +0100	[thread overview]
Message-ID: <5b3b7195-930c-58c3-d52f-b2738c3fde1e@kernel.org> (raw)
In-Reply-To: <20180122103714.GA25044@mwanda>

On 01/22/2018 11:37 AM, Dan Carpenter wrote:
> The while loop is a post op, "while (i-- >= 0)" so the last iteration
> will read camif_mbus_formats[-1] and then the loop will exit with "i"
> set to -2 and so we do: "mf->code = camif_mbus_formats[-2];".
> 
> I've changed it to a pre-op, I've added a check to ensure we found the
> right format and I've removed the "mf->code = camif_mbus_formats[i];"
> because that is a no-op anyway.
> 
> Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
> index 437395a61065..012f4b389c55 100644
> --- a/drivers/media/platform/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/s3c-camif/camif-capture.c
> @@ -1261,11 +1261,11 @@ static void __camif_subdev_try_format(struct camif_dev *camif,
>   	/* FIXME: constraints against codec or preview path ? */
>   	pix_lim = &variant->vp_pix_limits[VP_CODEC];
>   
> -	while (i-- >= 0)
> +	while (--i >= 0)
>   		if (camif_mbus_formats[i] == mf->code)
>   			break;
> -
> -	mf->code = camif_mbus_formats[i];
> +	if (i < 0)
> +		return;

Thanks for the patch Dan. mf->width needs to be aligned by this try_format
function so we shouldn't return here. Also it needs to be ensured mf->code 
is set to one of the supported values when this function returns. Sorry,
the current code really doesn't give a clue what was intended.

There is already queued a patch from Arnd [1] addressing the issues you 
have found.
 
>   	if (pad == CAMIF_SD_PAD_SINK) {
>   		v4l_bound_align_image(&mf->width, 8, CAMIF_MAX_PIX_WIDTH,
> 

[1] https://patchwork.linuxtv.org/patch/46508

--
Regards,
Sylwester

  reply	other threads:[~2018-01-22 20:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 10:37 [PATCH] [media] s3c-camif: array underflow in __camif_subdev_try_format() Dan Carpenter
2018-01-22 20:50 ` Sylwester Nawrocki [this message]
2018-01-24  8:13   ` Dan Carpenter
2018-01-24  8:43     ` Arnd Bergmann

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=5b3b7195-930c-58c3-d52f-b2738c3fde1e@kernel.org \
    --to=snawrocki@kernel.org \
    --cc=arnd@arndb.de \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=mchehab@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