v4l2-core: v4l2-h264: check after increasing memory allocation

Message ID 20221219033712.3270-1-zeming@nfschina.com
State New
Headers
Series v4l2-core: v4l2-h264: check after increasing memory allocation |

Commit Message

Li zeming Dec. 19, 2022, 3:37 a.m. UTC
  The pointer *out_str adds judgment and should help with program robustness.

Signed-off-by: Li zeming <zeming@nfschina.com>
---
 drivers/media/v4l2-core/v4l2-h264.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Bagas Sanjaya Dec. 19, 2022, 7:41 a.m. UTC | #1
On Mon, Dec 19, 2022 at 11:37:12AM +0800, Li zeming wrote:
> The pointer *out_str adds judgment and should help with program robustness.
> 

Terminology: if[-else] blocks are conditionals, not judgements.

> diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
> index 72bd64f65198..934aba539332 100644
> --- a/drivers/media/v4l2-core/v4l2-h264.c
> +++ b/drivers/media/v4l2-core/v4l2-h264.c
> @@ -305,6 +305,8 @@ static const char *format_ref_list_p(const struct v4l2_h264_reflist_builder *bui
>  	int n = 0, i;
>  
>  	*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
> +	if (!*out_str)
> +		return NULL;

Why did you add the check beside robustness?

Thanks.
  

Patch

diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
index 72bd64f65198..934aba539332 100644
--- a/drivers/media/v4l2-core/v4l2-h264.c
+++ b/drivers/media/v4l2-core/v4l2-h264.c
@@ -305,6 +305,8 @@  static const char *format_ref_list_p(const struct v4l2_h264_reflist_builder *bui
 	int n = 0, i;
 
 	*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
+	if (!*out_str)
+		return NULL;
 
 	n += snprintf(*out_str + n, tmp_str_size - n, "|");