diff mbox

[v2,3/9] ipmi: replace *_MAXCMD defines

Message ID 1453396734-9363-4-git-send-email-clg@fr.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Cédric Le Goater Jan. 21, 2016, 5:18 p.m. UTC
ARRAY_SIZE() is simple to use and removes the need to pre-define
the size of the command arrays.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 hw/ipmi/ipmi_bmc_sim.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

Comments

Greg Kurz Jan. 22, 2016, 8:05 a.m. UTC | #1
On Thu, 21 Jan 2016 18:18:48 +0100
Cédric Le Goater <clg@fr.ibm.com> wrote:

> ARRAY_SIZE() is simple to use and removes the need to pre-define
> the size of the command arrays.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---

Much nicer !

Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>

>  hw/ipmi/ipmi_bmc_sim.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
> index e42c7e86c344..fc596a548df7 100644
> --- a/hw/ipmi/ipmi_bmc_sim.c
> +++ b/hw/ipmi/ipmi_bmc_sim.c
> @@ -30,14 +30,12 @@
>  #include "qemu/error-report.h"
> 
>  #define IPMI_NETFN_CHASSIS            0x00
> -#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
> 
>  #define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
>  #define IPMI_CMD_GET_CHASSIS_STATUS       0x01
>  #define IPMI_CMD_CHASSIS_CONTROL          0x02
> 
>  #define IPMI_NETFN_SENSOR_EVENT       0x04
> -#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
> 
>  #define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
>  #define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
> @@ -46,7 +44,6 @@
>  #define IPMI_CMD_GET_SENSOR_READING       0x2d
> 
>  /* #define IPMI_NETFN_APP             0x06 In ipmi.h */
> -#define IPMI_NETFN_APP_MAXCMD             0x36
> 
>  #define IPMI_CMD_GET_DEVICE_ID            0x01
>  #define IPMI_CMD_COLD_RESET               0x02
> @@ -63,7 +60,6 @@
>  #define IPMI_CMD_READ_EVT_MSG_BUF         0x35
> 
>  #define IPMI_NETFN_STORAGE            0x0a
> -#define IPMI_NETFN_STORAGE_MAXCMD         0x4a
> 
>  #define IPMI_CMD_GET_SDR_REP_INFO         0x20
>  #define IPMI_CMD_GET_SDR_REP_ALLOC_INFO   0x21
> @@ -1518,18 +1514,17 @@ static void get_sensor_reading(IPMIBmcSim *ibs,
>      }
>  }
> 
> -static const IPMICmdHandler chassis_cmds[IPMI_NETFN_CHASSIS_MAXCMD] = {
> +static const IPMICmdHandler chassis_cmds[] = {
>      [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities,
>      [IPMI_CMD_GET_CHASSIS_STATUS] = chassis_status,
>      [IPMI_CMD_CHASSIS_CONTROL] = chassis_control
>  };
>  static const IPMINetfn chassis_netfn = {
> -    .cmd_nums = IPMI_NETFN_CHASSIS_MAXCMD,
> +    .cmd_nums = ARRAY_SIZE(chassis_cmds),
>      .cmd_handlers = chassis_cmds
>  };
> 
> -static const IPMICmdHandler
> -sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
> +static const IPMICmdHandler sensor_event_cmds[] = {
>      [IPMI_CMD_SET_SENSOR_EVT_ENABLE] = set_sensor_evt_enable,
>      [IPMI_CMD_GET_SENSOR_EVT_ENABLE] = get_sensor_evt_enable,
>      [IPMI_CMD_REARM_SENSOR_EVTS] = rearm_sensor_evts,
> @@ -1537,11 +1532,11 @@ sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
>      [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading
>  };
>  static const IPMINetfn sensor_event_netfn = {
> -    .cmd_nums = IPMI_NETFN_SENSOR_EVENT_MAXCMD,
> +    .cmd_nums = ARRAY_SIZE(sensor_event_cmds),
>      .cmd_handlers = sensor_event_cmds
>  };
> 
> -static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
> +static const IPMICmdHandler app_cmds[] = {
>      [IPMI_CMD_GET_DEVICE_ID] = get_device_id,
>      [IPMI_CMD_COLD_RESET] = cold_reset,
>      [IPMI_CMD_WARM_RESET] = warm_reset,
> @@ -1557,11 +1552,11 @@ static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
>      [IPMI_CMD_GET_WATCHDOG_TIMER] = get_watchdog_timer,
>  };
>  static const IPMINetfn app_netfn = {
> -    .cmd_nums = IPMI_NETFN_APP_MAXCMD,
> +    .cmd_nums = ARRAY_SIZE(app_cmds),
>      .cmd_handlers = app_cmds
>  };
> 
> -static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
> +static const IPMICmdHandler storage_cmds[] = {
>      [IPMI_CMD_GET_SDR_REP_INFO] = get_sdr_rep_info,
>      [IPMI_CMD_RESERVE_SDR_REP] = reserve_sdr_rep,
>      [IPMI_CMD_GET_SDR] = get_sdr,
> @@ -1577,7 +1572,7 @@ static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
>  };
> 
>  static const IPMINetfn storage_netfn = {
> -    .cmd_nums = IPMI_NETFN_STORAGE_MAXCMD,
> +    .cmd_nums = ARRAY_SIZE(storage_cmds),
>      .cmd_handlers = storage_cmds
>  };
>
diff mbox

Patch

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index e42c7e86c344..fc596a548df7 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -30,14 +30,12 @@ 
 #include "qemu/error-report.h"
 
 #define IPMI_NETFN_CHASSIS            0x00
-#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
 
 #define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
 #define IPMI_CMD_GET_CHASSIS_STATUS       0x01
 #define IPMI_CMD_CHASSIS_CONTROL          0x02
 
 #define IPMI_NETFN_SENSOR_EVENT       0x04
-#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
 
 #define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
 #define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
@@ -46,7 +44,6 @@ 
 #define IPMI_CMD_GET_SENSOR_READING       0x2d
 
 /* #define IPMI_NETFN_APP             0x06 In ipmi.h */
-#define IPMI_NETFN_APP_MAXCMD             0x36
 
 #define IPMI_CMD_GET_DEVICE_ID            0x01
 #define IPMI_CMD_COLD_RESET               0x02
@@ -63,7 +60,6 @@ 
 #define IPMI_CMD_READ_EVT_MSG_BUF         0x35
 
 #define IPMI_NETFN_STORAGE            0x0a
-#define IPMI_NETFN_STORAGE_MAXCMD         0x4a
 
 #define IPMI_CMD_GET_SDR_REP_INFO         0x20
 #define IPMI_CMD_GET_SDR_REP_ALLOC_INFO   0x21
@@ -1518,18 +1514,17 @@  static void get_sensor_reading(IPMIBmcSim *ibs,
     }
 }
 
-static const IPMICmdHandler chassis_cmds[IPMI_NETFN_CHASSIS_MAXCMD] = {
+static const IPMICmdHandler chassis_cmds[] = {
     [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities,
     [IPMI_CMD_GET_CHASSIS_STATUS] = chassis_status,
     [IPMI_CMD_CHASSIS_CONTROL] = chassis_control
 };
 static const IPMINetfn chassis_netfn = {
-    .cmd_nums = IPMI_NETFN_CHASSIS_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(chassis_cmds),
     .cmd_handlers = chassis_cmds
 };
 
-static const IPMICmdHandler
-sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
+static const IPMICmdHandler sensor_event_cmds[] = {
     [IPMI_CMD_SET_SENSOR_EVT_ENABLE] = set_sensor_evt_enable,
     [IPMI_CMD_GET_SENSOR_EVT_ENABLE] = get_sensor_evt_enable,
     [IPMI_CMD_REARM_SENSOR_EVTS] = rearm_sensor_evts,
@@ -1537,11 +1532,11 @@  sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
     [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading
 };
 static const IPMINetfn sensor_event_netfn = {
-    .cmd_nums = IPMI_NETFN_SENSOR_EVENT_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(sensor_event_cmds),
     .cmd_handlers = sensor_event_cmds
 };
 
-static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
+static const IPMICmdHandler app_cmds[] = {
     [IPMI_CMD_GET_DEVICE_ID] = get_device_id,
     [IPMI_CMD_COLD_RESET] = cold_reset,
     [IPMI_CMD_WARM_RESET] = warm_reset,
@@ -1557,11 +1552,11 @@  static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
     [IPMI_CMD_GET_WATCHDOG_TIMER] = get_watchdog_timer,
 };
 static const IPMINetfn app_netfn = {
-    .cmd_nums = IPMI_NETFN_APP_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(app_cmds),
     .cmd_handlers = app_cmds
 };
 
-static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
+static const IPMICmdHandler storage_cmds[] = {
     [IPMI_CMD_GET_SDR_REP_INFO] = get_sdr_rep_info,
     [IPMI_CMD_RESERVE_SDR_REP] = reserve_sdr_rep,
     [IPMI_CMD_GET_SDR] = get_sdr,
@@ -1577,7 +1572,7 @@  static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
 };
 
 static const IPMINetfn storage_netfn = {
-    .cmd_nums = IPMI_NETFN_STORAGE_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(storage_cmds),
     .cmd_handlers = storage_cmds
 };