net/sfc/base: improve code style in sensors decoding
[dpdk.git] / drivers / net / sfc / base / mcdi_mon.c
index 0e86016..5ebf0cd 100644 (file)
@@ -63,33 +63,34 @@ mcdi_mon_decode_stats(
        for (sensor = 0; sensor < sensor_max; ++sensor) {
                efx_mon_stat_t id;
                efx_mon_stat_portmask_t stat_portmask = 0;
-               boolean_t decode_ok;
                efx_mon_stat_unit_t stat_unit;
 
                if ((sensor % (MC_CMD_SENSOR_PAGE0_NEXT + 1)) ==
                    MC_CMD_SENSOR_PAGE0_NEXT) {
+                       /* This sensor is one of the page boundary bits. */
                        page++;
                        continue;
-                       /* This sensor is one of the page boundary bits. */
                }
 
-               if (~(sensor_mask[page]) & (1U << sensor))
+               if (~(sensor_mask[page]) &
+                   (1U << (sensor % (sizeof (sensor_mask[page]) * 8)))) {
+                       /* This sensor is not supported. */
                        continue;
-               /* This sensor not in DMA buffer */
+               }
 
+               /* Supported sensor, so it is present in the DMA buffer. */
                idx++;
-               /*
-                * Valid stat in DMA buffer that we need to increment over, even
-                * if we couldn't look up the id
-                */
 
-               decode_ok = efx_mon_mcdi_to_efx_stat(sensor, &id);
-               decode_ok =
-                   decode_ok && efx_mon_get_stat_portmap(id, &stat_portmask);
+               if ((efx_mon_mcdi_to_efx_stat(sensor, &id) != B_TRUE) ||
+                   (efx_mon_get_stat_portmap(id, &stat_portmask) != B_TRUE)) {
+                       /* The sensor is not known to the driver. */
+                       continue;
+               }
 
-               if (!(decode_ok && (stat_portmask & port_mask)))
+               if ((stat_portmask & port_mask) == 0) {
+                       /* The sensor is not for this port. */
                        continue;
-               /* Either bad decode, or don't know what port stat is on */
+               }
 
                EFSYS_ASSERT(id < EFX_MON_NSTATS);
 
@@ -191,8 +192,8 @@ efx_mcdi_read_sensors(
        __in            uint32_t size)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_READ_SENSORS_EXT_IN_LEN,
-                           MC_CMD_READ_SENSORS_EXT_OUT_LEN)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_READ_SENSORS_EXT_IN_LEN,
+               MC_CMD_READ_SENSORS_EXT_OUT_LEN);
        uint32_t addr_lo, addr_hi;
        efx_rc_t rc;
 
@@ -230,8 +231,8 @@ efx_mcdi_sensor_info_npages(
        __out           uint32_t *npagesp)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
-                           MC_CMD_SENSOR_INFO_OUT_LENMAX)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SENSOR_INFO_EXT_IN_LEN,
+               MC_CMD_SENSOR_INFO_OUT_LENMAX);
        int page;
        efx_rc_t rc;
 
@@ -274,8 +275,8 @@ efx_mcdi_sensor_info(
        __in                    size_t npages)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
-                           MC_CMD_SENSOR_INFO_OUT_LENMAX)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SENSOR_INFO_EXT_IN_LEN,
+               MC_CMD_SENSOR_INFO_OUT_LENMAX);
        uint32_t page;
        efx_rc_t rc;
 
@@ -343,8 +344,8 @@ efx_mcdi_sensor_info_page(
                                efx_mon_stat_limits_t *limits)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
-               MC_CMD_SENSOR_INFO_OUT_LENMAX)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SENSOR_INFO_EXT_IN_LEN,
+               MC_CMD_SENSOR_INFO_OUT_LENMAX);
        efx_rc_t rc;
        uint32_t mask_copy;
        efx_dword_t *maskp;
@@ -356,7 +357,6 @@ efx_mcdi_sensor_info_page(
        memset(limits, 0,
            ((sizeof (*mask_part) * 8) - 1) * sizeof (efx_mon_stat_limits_t));
 
-       (void) memset(payload, 0, sizeof (payload));
        req.emr_cmd = MC_CMD_SENSOR_INFO;
        req.emr_in_buf = payload;
        req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN;