* [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers
@ 2022-12-26 6:17 Dong Chuanjian
2022-12-26 6:39 ` Chen-Yu Tsai
2023-01-09 21:22 ` Nicolas Dufresne
0 siblings, 2 replies; 3+ messages in thread
From: Dong Chuanjian @ 2022-12-26 6:17 UTC (permalink / raw)
To: mchehab, hverkuil-cisco, nicolas.dufresne, sebastian.fricke, ezequiel
Cc: linux-media, linux-kernel, Dong Chuanjian
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) {
+ 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers
2022-12-26 6:17 [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers Dong Chuanjian
@ 2022-12-26 6:39 ` Chen-Yu Tsai
2023-01-09 21:22 ` Nicolas Dufresne
1 sibling, 0 replies; 3+ messages in thread
From: Chen-Yu Tsai @ 2022-12-26 6:39 UTC (permalink / raw)
To: Dong Chuanjian
Cc: mchehab, hverkuil-cisco, nicolas.dufresne, sebastian.fricke,
ezequiel, linux-media, linux-kernel
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers
2022-12-26 6:17 [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers Dong Chuanjian
2022-12-26 6:39 ` Chen-Yu Tsai
@ 2023-01-09 21:22 ` Nicolas Dufresne
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Dufresne @ 2023-01-09 21:22 UTC (permalink / raw)
To: Dong Chuanjian, mchehab, hverkuil-cisco, sebastian.fricke, ezequiel
Cc: linux-media, linux-kernel
Hi,
Le lundi 26 décembre 2022 à 14:17 +0800, Dong Chuanjian a écrit :
> 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);
Can't this patch be reduced to this ?
+ if (!*out_str)
+ return NULL;
>
>
> -
> - 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) {
> + 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;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-09 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-26 6:17 [PATCH] drivers/media/v4l2-core/v4l2-h264.c : add detection of null pointers Dong Chuanjian
2022-12-26 6:39 ` Chen-Yu Tsai
2023-01-09 21:22 ` Nicolas Dufresne
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.