staging: ccree: remove BUG macro usage
authorGilad Ben-Yossef <gilad@benyossef.com>
Thu, 7 Sep 2017 09:00:16 +0000 (12:00 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 17 Sep 2017 14:35:26 +0000 (16:35 +0200)
Replace BUG() macro usage that crash the kernel with alternatives
that signal error and/or try to recover.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ccree/ssi_buffer_mgr.c
drivers/staging/ccree/ssi_cipher.c
drivers/staging/ccree/ssi_pm.c
drivers/staging/ccree/ssi_request_mgr.c

index 63936091d524e50d01fbcbf0f4798913f7642ef3..67c3296e0fd259909f12c4227d2f35427f8b43fb 100644 (file)
@@ -81,11 +81,6 @@ static unsigned int ssi_buffer_mgr_get_sgl_nents(
        unsigned int nents = 0;
 
        while (nbytes != 0) {
-               if (sg_is_chain(sg_list)) {
-                       SSI_LOG_ERR("Unexpected chained entry "
-                                  "in sg (entry =0x%X)\n", nents);
-                       BUG();
-               }
                if (sg_list->length != 0) {
                        nents++;
                        /* get the number of bytes in the last entry */
@@ -854,7 +849,7 @@ static inline int ssi_buffer_mgr_aead_chain_assoc(
                        //if have reached the end of the sgl, then this is unexpected
                        if (!current_sg) {
                                SSI_LOG_ERR("reached end of sg list. unexpected\n");
-                               BUG();
+                               return -EINVAL;
                        }
                        sg_index += current_sg->length;
                        mapped_nents++;
@@ -1134,10 +1129,9 @@ static inline int ssi_buffer_mgr_aead_chain_data(
 
        offset = size_to_skip;
 
-       if (!sg_data) {
-               rc = -EINVAL;
-               goto chain_data_exit;
-       }
+       if (!sg_data)
+               return -EINVAL;
+
        areq_ctx->src_sgl = req->src;
        areq_ctx->dst_sgl = req->dst;
 
@@ -1154,7 +1148,7 @@ static inline int ssi_buffer_mgr_aead_chain_data(
                //if have reached the end of the sgl, then this is unexpected
                if (!areq_ctx->src_sgl) {
                        SSI_LOG_ERR("reached end of sg list. unexpected\n");
-                       BUG();
+                       return -EINVAL;
                }
                sg_index += areq_ctx->src_sgl->length;
                src_mapped_nents--;
@@ -1198,7 +1192,7 @@ static inline int ssi_buffer_mgr_aead_chain_data(
                //if have reached the end of the sgl, then this is unexpected
                if (!areq_ctx->dst_sgl) {
                        SSI_LOG_ERR("reached end of sg list. unexpected\n");
-                       BUG();
+                       return -EINVAL;
                }
                sg_index += areq_ctx->dst_sgl->length;
                dst_mapped_nents--;
index ab0349f7a678a7babc86f88f4394384cff1b1785..a462075c9b12a077970db3af6870f26114d5803c 100644 (file)
@@ -541,7 +541,6 @@ ssi_blkcipher_create_setup_desc(
                break;
        default:
                SSI_LOG_ERR("Unsupported cipher mode (%d)\n", cipher_mode);
-               BUG();
        }
 }
 
index 31325e6cd4b4ace3c7d153158a30b0de7a8017be..a50671ae261fda7b43c1f177ea6601b9e1c54473 100644 (file)
@@ -109,7 +109,8 @@ int ssi_power_mgr_runtime_put_suspend(struct device *dev)
                rc = pm_runtime_put_autosuspend(dev);
        } else {
                /* Something wrong happens*/
-               BUG();
+               SSI_LOG_ERR("request to suspend already suspended queue");
+               rc = -EBUSY;
        }
        return rc;
 }
index e5c2f92857f6add54dfa0d9b8aea94783a1f5f1e..97c235973b1525564ad214ffe7269d9090113029 100644 (file)
@@ -369,11 +369,16 @@ int send_request(
        enqueue_seq(cc_base, &req_mgr_h->compl_desc, (is_dout ? 0 : 1));
 
        if (unlikely(req_mgr_h->q_free_slots < total_seq_len)) {
-               /*This means that there was a problem with the resume*/
-               BUG();
+               /* This situation should never occur. Maybe indicating problem
+                * with resuming power. Set the free slot count to 0 and hope
+                * for the best.
+                */
+               SSI_LOG_ERR("HW free slot count mismatch.");
+               req_mgr_h->q_free_slots = 0;
+       } else {
+               /* Update the free slots in HW queue */
+               req_mgr_h->q_free_slots -= total_seq_len;
        }
-       /* Update the free slots in HW queue */
-       req_mgr_h->q_free_slots -= total_seq_len;
 
        spin_unlock_bh(&req_mgr_h->hw_lock);
 
@@ -460,8 +465,13 @@ static void proc_completions(struct ssi_drvdata *drvdata)
 
                /* Dequeue request */
                if (unlikely(request_mgr_handle->req_queue_head == request_mgr_handle->req_queue_tail)) {
-                       SSI_LOG_ERR("Request queue is empty req_queue_head==req_queue_tail==%u\n", request_mgr_handle->req_queue_head);
-                       BUG();
+                       /* We are supposed to handle a completion but our
+                        * queue is empty. This is not normal. Return and
+                        * hope for the best.
+                        */
+                       SSI_LOG_ERR("Request queue is empty head == tail %u\n",
+                                   request_mgr_handle->req_queue_head);
+                       break;
                }
 
                ssi_req = &request_mgr_handle->req_queue[request_mgr_handle->req_queue_tail];