Skip to contentSkip to conversation

drivers: fsi: Copy all data out

PATCH In review Eddie James 2 participants 2 messages Feb 20, 2017 – Feb 21, 2017 FSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers: fsi: Copy all data out

From: "Edward A. James" <[email protected]>

Driver was only copying 32 bits out to the user-provided data pointer.

since v1:
* don't do a for loop... thanks Milton.

---
 drivers/fsi/fsi-master-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fsi/fsi-master-gpio.c +1 -1
index 3ed82ea..8c8a8f4 100644
@@ -274,7 +274,7 @@ static int poll_for_response(struct fsi_master_gpio *master, uint8_t expected,
 			resp <<= bits_remaining;
 			resp |= response.msg;
 			bits_received += bits_remaining;
-			*((uint32_t *)data) = response.msg;
+			memcpy(data, &response.msg, size);
 		}
 
 		crc_in = fsi_crc4(0, resp | (0x1ULL << bits_received),
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Eddie James

From: "Edward A. James" <[email protected]>

Driver was only copying 32 bits out to the user-provided data pointer.

since v1:
* don't do a for loop... thanks Milton.

Thanks for adding the changelog. Convention is to put it blow the "--", which means it's not included in the commit log.

Quoted 11 lines
---
 drivers/fsi/fsi-master-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fsi/fsi-master-gpio.c +0 -0
index 3ed82ea..8c8a8f4 100644

drivers/fsi/fsi-master-gpio.c static int poll_for_response(struct fsi_master_gpio *master, uint8_t expected, · line 277

Quoted 5 lines
drivers/fsi/fsi-master-gpio.c +1 -1
@@ -274,7 +274,7 @@ static int poll_for_response(struct fsi_master_gpio *master, uint8_t expected,
                        resp <<= bits_remaining;
                        resp |= response.msg;
                        bits_received += bits_remaining;
-                       *((uint32_t *)data) = response.msg;
+                       memcpy(data, &response.msg, size);

This change looks good. I will apply it as-is. However, we have another issue:

When reviewing I took a look at some of the call sites. The driver does this:

        rc = poll_for_response(master, FSI_GPIO_RESP_ACK, size, NULL);

So we have:

static int poll_for_response(struct fsi_master_gpio *master, uint8_t expected,
uint8_t size, void *data)
{
...

        struct fsi_gpio_msg response, cmd;
        int bits_remaining = 0, bit_count, response_id, id;

...

                serial_in(master, &response, bit_count);
                response_id = response.msg & 0x3;
...
                switch (response_id) {
                case FSI_GPIO_RESP_ACK:
                        if (expected == FSI_GPIO_RESP_ACKD)
                                bits_remaining = 8 * size;
                        break;
...
                /* Read in the data field if applicable */
                if (bits_remaining) {
                        serial_in(master, &response, bits_remaining);
                        resp <<= bits_remaining;
                        resp |= response.msg;
                        bits_received += bits_remaining;
                        *((uint32_t *)data) = response.msg;
                }

Data is still null, so we now have a null pointer dereference.

Can you or Chris please take a look at this?

Cheers,

Joel

Quoted 6 lines
                }

                crc_in = fsi_crc4(0, resp | (0x1ULL << bits_received),

--
1.8.3.1