]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
Tegra: bpmp_ipc: improve cyclomatic complexity
authorVarun Wadekar <vwadekar@nvidia.com>
Wed, 20 Jun 2018 23:12:50 +0000 (16:12 -0700)
committerVarun Wadekar <vwadekar@nvidia.com>
Thu, 20 Feb 2020 17:25:45 +0000 (09:25 -0800)
Code complexity is a good indication of maintainability versus
testability of a piece of software.

ISO26262 introduces the following thresholds:

    complexity < 10 is accepted
    10 <= complexity < 20 has to be justified
    complexity >= 20 cannot be accepted

Rationale is that number of test cases to fully test a piece of
software can (depending on the coverage metrics) grow exponentially
with the number of branches in the software.

This patch removes redundant conditionals from 'ipc_send_req_atomic'
handler to reduce the McCabe Cyclomatic Complexity for this function

Change-Id: I20fef79a771301e1c824aea72a45ff83f97591d5
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
plat/nvidia/tegra/common/drivers/bpmp_ipc/intf.c

index eaf96751ceb851601eae0620d1259ec32179ed82..2e90d25474b50ce7d39c91b32bd811f47041f37c 100644 (file)
@@ -175,44 +175,39 @@ static int32_t tegra_bpmp_ipc_send_req_atomic(uint32_t mrq, void *p_out,
        if ((p_out == NULL) || (size_out > IVC_DATA_SZ_BYTES) ||
            (frame == NULL)) {
                ERROR("%s: invalid parameters, exiting\n", __func__);
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
-       if (ret == 0) {
-
-               /* prepare the command frame */
-               frame->mrq = mrq;
-               frame->flags = FLAG_DO_ACK;
-               p_fdata = frame->data;
-               (void)memcpy(p_fdata, p_out, (size_t)size_out);
+       /* prepare the command frame */
+       frame->mrq = mrq;
+       frame->flags = FLAG_DO_ACK;
+       p_fdata = frame->data;
+       (void)memcpy(p_fdata, p_out, (size_t)size_out);
 
-               /* signal the slave */
-               tegra_bpmp_signal_slave();
+       /* signal the slave */
+       tegra_bpmp_signal_slave();
 
-               /* wait for slave to ack */
-               ret = tegra_bpmp_wait_for_slave_ack();
-               if (ret != 0) {
-                       ERROR("failed waiting for the slave to ack\n");
-               }
+       /* wait for slave to ack */
+       ret = tegra_bpmp_wait_for_slave_ack();
+       if (ret < 0) {
+               ERROR("%s: wait for slave failed (%d)\n", __func__, ret);
+               return ret;
+       }
 
-               /* retrieve the response frame */
-               if ((size_in <= IVC_DATA_SZ_BYTES) && (p_in != NULL) &&
-                   (ret == 0)) {
+       /* retrieve the response frame */
+       if ((size_in <= IVC_DATA_SZ_BYTES) && (p_in != NULL)) {
 
-                       f_in = tegra_bpmp_get_cur_in_frame();
-                       if (f_in != NULL) {
-                               ERROR("Failed to get next input frame!\n");
-                       } else {
-                               (void)memcpy(p_in, p_fdata, (size_t)size_in);
-                       }
+               f_in = tegra_bpmp_get_cur_in_frame();
+               if (f_in != NULL) {
+                       ERROR("Failed to get next input frame!\n");
+               } else {
+                       (void)memcpy(p_in, p_fdata, (size_t)size_in);
                }
+       }
 
-               if (ret == 0) {
-                       ret = tegra_bpmp_free_master();
-                       if (ret != 0) {
-                               ERROR("Failed to free master\n");
-                       }
-               }
+       ret = tegra_bpmp_free_master();
+       if (ret < 0) {
+               ERROR("%s: free master failed (%d)\n", __func__, ret);
        }
 
        return ret;