i40e: don't overload fields
authorMitch Williams <mitch.a.williams@intel.com>
Tue, 11 Nov 2014 20:02:19 +0000 (20:02 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 20 Nov 2014 22:56:42 +0000 (14:56 -0800)
Overloading the msg_size field in the arq_event_info struct is just a
bad idea. It leads to repeated bugs when the structure is used in a
loop, since the input value (buffer size) is overwritten by the output
value (actual message length).

Fix this by splitting the field into two and renaming to indicate the
actual function of each field.

Since the arq_event struct has now changed, we need to change the drivers
to support this. Note that we no longer need to initialize the buffer size
each time we go through a loop as this value is no longer destroyed by
arq processing.

In the process, we also fix a bug in i40evf_verify_api_ver where the
buffer size was not correctly reinitialized each time through the loop.

Change-ID: Ic7f9633cdd6f871f93e698dfb095e29c696f5581
Signed-off-by: Mitch Williams <mitch.a.williams@intel.com>
Acked-by: Shannon Nelson <shannon.nelson@intel.com>
Acked-by: Ashish Shah <ashish.n.shah@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_adminq.c
drivers/net/ethernet/intel/i40e/i40e_adminq.h
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/i40evf/i40e_adminq.c
drivers/net/ethernet/intel/i40evf/i40e_adminq.h
drivers/net/ethernet/intel/i40evf/i40evf_main.c
drivers/net/ethernet/intel/i40evf/i40evf_virtchnl.c

index f7f6206368dfeef5d88d60f6580190eaa4194c36..5bb4914bda56bbb77082db8a256db6e2febe7a06 100644 (file)
@@ -980,10 +980,10 @@ i40e_status i40e_clean_arq_element(struct i40e_hw *hw,
 
        e->desc = *desc;
        datalen = le16_to_cpu(desc->datalen);
-       e->msg_size = min(datalen, e->msg_size);
-       if (e->msg_buf != NULL && (e->msg_size != 0))
+       e->msg_len = min(datalen, e->buf_len);
+       if (e->msg_buf != NULL && (e->msg_len != 0))
                memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va,
-                      e->msg_size);
+                      e->msg_len);
 
        i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: desc and buffer:\n");
        i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
index df0bd09ed5d82f4cfc4a3454c2639fd2aa1f959c..003a227b8515a610bbcd7aa761074d5693d774a9 100644 (file)
@@ -76,7 +76,8 @@ struct i40e_asq_cmd_details {
 /* ARQ event information */
 struct i40e_arq_event_info {
        struct i40e_aq_desc desc;
-       u16 msg_size;
+       u16 msg_len;
+       u16 buf_len;
        u8 *msg_buf;
 };
 
index c998d82da0fc0986a01635332ffa2d5561dce7b4..3ebab039fbb3c4842a8998c0fc987fb6a7d0f3a1 100644 (file)
@@ -5750,13 +5750,12 @@ static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
        if (oldval != val)
                wr32(&pf->hw, pf->hw.aq.asq.len, val);
 
-       event.msg_size = I40E_MAX_AQ_BUF_SIZE;
-       event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
+       event.buf_len = I40E_MAX_AQ_BUF_SIZE;
+       event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
        if (!event.msg_buf)
                return;
 
        do {
-               event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
                ret = i40e_clean_arq_element(hw, &event, &pending);
                if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
                        break;
@@ -5777,7 +5776,7 @@ static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
                                        le32_to_cpu(event.desc.cookie_high),
                                        le32_to_cpu(event.desc.cookie_low),
                                        event.msg_buf,
-                                       event.msg_size);
+                                       event.msg_len);
                        break;
                case i40e_aqc_opc_lldp_update_mib:
                        dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
index 500ca21627087962dd3270ced4c27e567b4a4bc7..d7e446f3e7a4d9f360c068430565ce9c436b4011 100644 (file)
@@ -929,10 +929,10 @@ i40e_status i40evf_clean_arq_element(struct i40e_hw *hw,
 
        e->desc = *desc;
        datalen = le16_to_cpu(desc->datalen);
-       e->msg_size = min(datalen, e->msg_size);
-       if (e->msg_buf != NULL && (e->msg_size != 0))
+       e->msg_len = min(datalen, e->buf_len);
+       if (e->msg_buf != NULL && (e->msg_len != 0))
                memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va,
-                      e->msg_size);
+                      e->msg_len);
 
        if (i40e_is_nvm_update_op(&e->desc))
                hw->aq.nvm_busy = false;
index f40cfac4b022fbfcdc4d317a47759de1c7baf3f9..0d58378be7406bcadfade1e30d628be3409421e6 100644 (file)
@@ -76,7 +76,8 @@ struct i40e_asq_cmd_details {
 /* ARQ event information */
 struct i40e_arq_event_info {
        struct i40e_aq_desc desc;
-       u16 msg_size;
+       u16 msg_len;
+       u16 buf_len;
        u8 *msg_buf;
 };
 
index 489227891ffb167fb58b9d5013148b5a5a9b6bdf..d378e130d421caa01a8968f4095d09f287a56e5e 100644 (file)
@@ -1632,8 +1632,8 @@ static void i40evf_adminq_task(struct work_struct *work)
        if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
                return;
 
-       event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
-       event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
+       event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
+       event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
        if (!event.msg_buf)
                return;
 
@@ -1645,10 +1645,9 @@ static void i40evf_adminq_task(struct work_struct *work)
 
                i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
                                           v_msg->v_retval, event.msg_buf,
-                                          event.msg_size);
+                                          event.msg_len);
                if (pending != 0) {
                        memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
-                       event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
                }
        } while (pending);
 
index 49bfdb5421c8f8c031337944a87a8c74667c8c91..422dd2d6551b6fd3de2a1122491588814c89df8b 100644 (file)
@@ -92,8 +92,8 @@ int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
        enum i40e_virtchnl_ops op;
        i40e_status err;
 
-       event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
-       event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
+       event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
+       event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
        if (!event.msg_buf) {
                err = -ENOMEM;
                goto out;
@@ -169,15 +169,14 @@ int i40evf_get_vf_config(struct i40evf_adapter *adapter)
 
        len =  sizeof(struct i40e_virtchnl_vf_resource) +
                I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
-       event.msg_size = len;
-       event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
+       event.buf_len = len;
+       event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
        if (!event.msg_buf) {
                err = -ENOMEM;
                goto out;
        }
 
        while (1) {
-               event.msg_size = len;
                /* When the AQ is empty, i40evf_clean_arq_element will return
                 * nonzero and this loop will terminate.
                 */
@@ -191,7 +190,7 @@ int i40evf_get_vf_config(struct i40evf_adapter *adapter)
        }
 
        err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
-       memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len));
+       memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
 
        i40e_vf_parse_hw_config(hw, adapter->vf_res);
 out_alloc: