mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wenst@chromium.org>
To: Dong Chuanjian <chuanjian@nfschina.com>
Cc: mchehab@kernel.org, hverkuil-cisco@xs4all.nl,
	nicolas.dufresne@collabora.com, sebastian.fricke@collabora.com,
	ezequiel@vanguardiasur.com.ar, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers
Date: Mon, 26 Dec 2022 14:39:45 +0800	[thread overview]
Message-ID: <CAGXv+5HT4CD5eRYCuAdwrdAPRbNcd9SPEdDCnPfLpAAQbooBYQ@mail.gmail.com> (raw)
In-Reply-To: <20221226061711.3988-1-chuanjian@nfschina.com>

On Mon, Dec 26, 2022 at 2:17 PM Dong Chuanjian <chuanjian@nfschina.com> wrote:
>
> Continue the program when the pointer assignment is successful.
>
> Signed-off-by: Dong Chuanjian <chuanjian@nfschina.com>
>
> diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
> index 72bd64f65198..1163cd48ff33 100644
> --- a/drivers/media/v4l2-core/v4l2-h264.c
> +++ b/drivers/media/v4l2-core/v4l2-h264.c
> @@ -343,18 +343,19 @@ static const char *format_ref_list_b(const struct v4l2_h264_reflist_builder *bui
>         int n = 0, i;
>
>         *out_str = kmalloc(tmp_str_size, GFP_KERNEL);
> -
> -       n += snprintf(*out_str + n, tmp_str_size - n, "|");
> -
> -       for (i = 0; i < builder->num_valid; i++) {
> -               int frame_num = builder->refs[reflist[i].index].frame_num;
> -               u32 poc = v4l2_h264_get_poc(builder, reflist + i);
> -               bool longterm = builder->refs[reflist[i].index].longterm;
> -
> -               n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|",
> -                              longterm ? frame_num : poc,
> -                              longterm ? 'l' : 's',
> -                              ref_type_to_char(reflist[i].fields));
> +       if (*out_str != NULL) {

I would suggest returning early if it's NULL. The change would be cleaner
as you wouldn't need to reindent the whole code block.

ChenYu

> +               n += snprintf(*out_str + n, tmp_str_size - n, "|");
> +
> +               for (i = 0; i < builder->num_valid; i++) {
> +                       int frame_num = builder->refs[reflist[i].index].frame_num;
> +                       u32 poc = v4l2_h264_get_poc(builder, reflist + i);
> +                       bool longterm = builder->refs[reflist[i].index].longterm;
> +
> +                       n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|",
> +                                      longterm ? frame_num : poc,
> +                                      longterm ? 'l' : 's',
> +                                      ref_type_to_char(reflist[i].fields));
> +               }
>         }
>
>         return *out_str;
> --
> 2.18.2
>

  reply	other threads:[~2022-12-26  6:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-26  6:17 Dong Chuanjian
2022-12-26  6:39 ` Chen-Yu Tsai [this message]
2023-01-09 21:22 ` Nicolas Dufresne

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=CAGXv+5HT4CD5eRYCuAdwrdAPRbNcd9SPEdDCnPfLpAAQbooBYQ@mail.gmail.com \
    --to=wenst@chromium.org \
    --cc=chuanjian@nfschina.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=sebastian.fricke@collabora.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®