ipmi: Make ipmi_demangle_device_id more generic
authorJeremy Kerr <jk@ozlabs.org>
Fri, 25 Aug 2017 07:47:23 +0000 (15:47 +0800)
committerCorey Minyard <cminyard@mvista.com>
Wed, 27 Sep 2017 21:03:45 +0000 (16:03 -0500)
Currently, ipmi_demagle_device_id requires a full response buffer in its
data argument. This means we can't use it to parse a response in a
struct ipmi_recv_msg, which has the netfn and cmd as separate bytes.

This change alters the definition and users of ipmi_demangle_device_id
to use a split netfn, cmd and data buffer, so it can be used with
non-sequential responses.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Fixed the ipmi_ssif.c and ipmi_si_intf.c changes to use data from the
response, not the data from the message, when passing info to the
ipmi_demangle_device_id() function.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
drivers/char/ipmi/ipmi_si_intf.c
drivers/char/ipmi/ipmi_ssif.c
include/linux/ipmi_smi.h

index f8e28bad6d56b5fa140c06aff7b8774ea77f8680..bc99369fca4975bb36fa05c577333d51c33e20f0 100644 (file)
@@ -2926,7 +2926,8 @@ static int try_get_dev_id(struct smi_info *smi_info)
                                                  resp, IPMI_MAX_MSG_LENGTH);
 
        /* Check and record info from the get device id, in case we need it. */
-       rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id);
+       rv = ipmi_demangle_device_id(resp[0] >> 2, resp[1],
+                       resp + 2, resp_len - 2, &smi_info->device_id);
 
 out:
        kfree(resp);
index 0aea3bcb615848f65d9eef06806cbacf2ae92ed3..20ab098cd661563c37abb1b6e65a99d56c0e141b 100644 (file)
@@ -1491,7 +1491,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
        if (rv)
                goto out;
 
-       rv = ipmi_demangle_device_id(resp, len, &ssif_info->device_id);
+       rv = ipmi_demangle_device_id(resp[0] >> 2, resp[1],
+                       resp + 2, len - 2, &ssif_info->device_id);
        if (rv)
                goto out;
 
index f8cea14485ddde6f5d73bea2817b9bfa8913dc10..75542c837c07c16b63e9814e53f695bd36507276 100644 (file)
@@ -162,27 +162,27 @@ struct ipmi_device_id {
 #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
 #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
 
-/* Take a pointer to a raw data buffer and a length and extract device
-   id information from it.  The first byte of data must point to the
-   netfn << 2, the data should be of the format:
-      netfn << 2, cmd, completion code, data
-   as normally comes from a device interface. */
-static inline int ipmi_demangle_device_id(const unsigned char *data,
+/* Take a pointer to an IPMI response and extract device id information from
+ * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
+ * a SI response.
+ */
+static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
+                                         const unsigned char *data,
                                          unsigned int data_len,
                                          struct ipmi_device_id *id)
 {
-       if (data_len < 9)
+       if (data_len < 7)
                return -EINVAL;
-       if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 ||
-           data[1] != IPMI_GET_DEVICE_ID_CMD)
+       if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
                /* Strange, didn't get the response we expected. */
                return -EINVAL;
-       if (data[2] != 0)
+       if (data[0] != 0)
                /* That's odd, it shouldn't be able to fail. */
                return -EINVAL;
 
-       data += 3;
-       data_len -= 3;
+       data++;
+       data_len--;
+
        id->device_id = data[0];
        id->device_revision = data[1];
        id->firmware_revision_1 = data[2];