staging: media: atomisp: Refactor ia_css_stream_load()
Subsystems (4)
PATCH v2 5/8 staging: media: atomisp: Refactor ia_css_stream_load()
Move the support check to the beginning of the function. Change the logic to avoid multiple nesting blocks. Move variable assignment outside of the if statement. Remove an unnecessary check.
--- drivers/staging/media/atomisp/pci/sh_css.c | 72 +++++++++++----------- 1 file changed, 35 insertions(+), 37 deletions(-)
drivers/staging/media/atomisp/pci/sh_css.c +35 -37
@@ -9615,48 +9615,46 @@ ia_css_stream_get_info(const struct ia_css_stream *stream,int ia_css_stream_load (struct ia_css_stream *stream) { -if (!IS_ISP2401 ) { -int i; -int err; +int i, j, err; -assert (stream); -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); -for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { -if (my_css_save.stream_seeds[i].stream == stream) { -int j; - -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { -if ((err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], - &my_css_save.stream_seeds[i].pipes[j])) !=0 ) { -if (j) { -int k; - -for (k =0 ; k < j; k++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); - } -return err; - } - } - err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, - my_css_save.stream_seeds[i].num_pipes, - my_css_save.stream_seeds[i].pipes, - &my_css_save.stream_seeds[i].stream); -if (err) { -ia_css_stream_destroy (stream); -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); -return err; - } -break ; - } - } -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); -return 0 ; - }else { +if (IS_ISP2401 ) {/* TODO remove function - DEPRECATED */ (void )stream;return -ENOTSUPP ; } + +assert (stream); +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); +for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { +if (my_css_save.stream_seeds[i].stream != stream) +continue ; + +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { +int k; + + err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], + &my_css_save.stream_seeds[i].pipes[j]); +if (!err) +continue ; + +for (k =0 ; k < j; k++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); +return err; + } + err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, + my_css_save.stream_seeds[i].num_pipes, + my_css_save.stream_seeds[i].pipes, + &my_css_save.stream_seeds[i].stream); +if (err) { +ia_css_stream_destroy (stream); +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); +return err; + } + } + +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); +return 0 ; }int
Signature · 1 line
2.31.1
Quoted 81 lines · Martiros Shakhzadyan
Move the support check to the beginning of the function. Change the logic to avoid multiple nesting blocks. Move variable assignment outside of the if statement. Remove an unnecessary check.
Signed-off-by Martiros Shakhzadyan <[email protected]>--- drivers/staging/media/atomisp/pci/sh_css.c | 72 +++++++++++----------- 1 file changed, 35 insertions(+), 37 deletions(-)drivers/staging/media/atomisp/pci/sh_css.c +21
-37@@ -9615,48 +9615,46 @@ ia_css_stream_get_info(const struct ia_css_stream *stream,int ia_css_stream_load (struct ia_css_stream *stream) { -if (!IS_ISP2401 ) { -int i; -int err; +int i, j, err; -assert (stream); -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); -for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { -if (my_css_save.stream_seeds[i].stream == stream) { -int j; - -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { -if ((err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], - &my_css_save.stream_seeds[i].pipes[j])) !=0 ) { -if (j) { -int k; - -for (k =0 ; k < j; k++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); - } -return err; - } - } - err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, - my_css_save.stream_seeds[i].num_pipes, - my_css_save.stream_seeds[i].pipes, - &my_css_save.stream_seeds[i].stream); -if (err) { -ia_css_stream_destroy (stream); -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); -return err; - } -break ; - } - } -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); -return 0 ; - }else { +if (IS_ISP2401 ) {/* TODO remove function - DEPRECATED */ (void )stream;return -ENOTSUPP ; } + +assert (stream); +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); +for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { +if (my_css_save.stream_seeds[i].stream != stream) +continue ; + +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { +int k; + + err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], + &my_css_save.stream_seeds[i].pipes[j]); +if (!err) +continue ; + +for (k =0 ; k < j; k++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); +return err; + }
drivers/staging/media/atomisp/pci/sh_css.c ia_css_stream_get_info(const struct ia_css_stream *stream, · line 9653
Quoted 10 lines
drivers/staging/media/atomisp/pci/sh_css.c +10
-0+ err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, + my_css_save.stream_seeds[i].num_pipes, + my_css_save.stream_seeds[i].pipes, + &my_css_save.stream_seeds[i].stream); +if (err) { +ia_css_stream_destroy (stream); +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); +return err; + }
You dropped a 'break' here!
Regards,
Hans
Quoted 8 lines
drivers/staging/media/atomisp/pci/sh_css.c +4
-0+ } + +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); +return 0 ; }int
Quoted 3 lines · Martiros Shakhzadyan
Move the support check to the beginning of the function. Change the logic to avoid multiple nesting blocks. Move variable assignment outside of the if statement.
Which variable? Mention it explicitly: 'Move 'err' variable assignment...'
Quoted 1 line
Remove an unnecessary check.
Which check?
Regards,
Hans
Quoted 95 lines
Signed-off-by Martiros Shakhzadyan <[email protected]>--- drivers/staging/media/atomisp/pci/sh_css.c | 72 +++++++++++----------- 1 file changed, 35 insertions(+), 37 deletions(-)drivers/staging/media/atomisp/pci/sh_css.c +35
-37@@ -9615,48 +9615,46 @@ ia_css_stream_get_info(const struct ia_css_stream *stream,int ia_css_stream_load (struct ia_css_stream *stream) { -if (!IS_ISP2401 ) { -int i; -int err; +int i, j, err; -assert (stream); -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); -for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { -if (my_css_save.stream_seeds[i].stream == stream) { -int j; - -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { -if ((err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], - &my_css_save.stream_seeds[i].pipes[j])) !=0 ) { -if (j) { -int k; - -for (k =0 ; k < j; k++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); - } -return err; - } - } - err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, - my_css_save.stream_seeds[i].num_pipes, - my_css_save.stream_seeds[i].pipes, - &my_css_save.stream_seeds[i].stream); -if (err) { -ia_css_stream_destroy (stream); -for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) -ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); -return err; - } -break ; - } - } -ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); -return 0 ; - }else { +if (IS_ISP2401 ) {/* TODO remove function - DEPRECATED */ (void )stream;return -ENOTSUPP ; } + +assert (stream); +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() enter,\n" ); +for (i =0 ; i <MAX_ACTIVE_STREAMS ; i++) { +if (my_css_save.stream_seeds[i].stream != stream) +continue ; + +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) { +int k; + + err =ia_css_pipe_create (&my_css_save.stream_seeds[i].pipe_config[j], + &my_css_save.stream_seeds[i].pipes[j]); +if (!err) +continue ; + +for (k =0 ; k < j; k++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[k]); +return err; + } + err =ia_css_stream_create (&my_css_save.stream_seeds[i].stream_config, + my_css_save.stream_seeds[i].num_pipes, + my_css_save.stream_seeds[i].pipes, + &my_css_save.stream_seeds[i].stream); +if (err) { +ia_css_stream_destroy (stream); +for (j =0 ; j < my_css_save.stream_seeds[i].num_pipes; j++) +ia_css_pipe_destroy (my_css_save.stream_seeds[i].pipes[j]); +return err; + } + } + +ia_css_debug_dtrace (IA_CSS_DEBUG_TRACE ,"ia_css_stream_load() exit,\n" ); +return 0 ; }int