Skip to contentSkip to conversation

drivers: fsi: scom: Zero out user buffer first

PATCH In review Eddie James 4 participants 4 messages Feb 21, 2017 – Feb 22, 2017 FSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: fsi: scom: Zero out user buffer first

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

Scom data is just bit-wise OR'd with the user buffer, so it needs to be set to 0 first.

---
 drivers/fsi/fsi-scom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/fsi/fsi-scom.c +1 -0
index 51b3dc3..ed3b98e 100644
@@ -85,6 +85,7 @@ static int get_scom(struct scom_device *scom_dev, uint64_t *value,
 	uint32_t result, data;
 	int rc;
 
+	*value = 0ULL;
 	data = addr;
 	rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
 				sizeof(uint32_t));
Signature · 1 line
1.8.3.1
Acked-by Tested-by on v1 1/1
#1 lore raw
Quoted 23 lines · Eddie James

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

Scom data is just bit-wise OR'd with the user buffer, so it needs to be set to 0 first.

---
 drivers/fsi/fsi-scom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/fsi/fsi-scom.c +1 -1
index 51b3dc3..ed3b98e 100644
@@ -85,6 +85,7 @@ static int get_scom(struct scom_device *scom_dev, uint64_t *value,
        uint32_t result, data;
        int rc;
 
+       *value = 0ULL;
        data = addr;
        rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
                                sizeof(uint32_t));
--
Quoted 2 lines

1.8.3.1

Looks good!

#2 lore raw
Quoted 20 lines · Andrew Geissler
Quoted 18 lines · Eddie James

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

Scom data is just bit-wise OR'd with the user buffer, so it needs to be set to 0 first.

---
 drivers/fsi/fsi-scom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/fsi/fsi-scom.c +0 -0
index 51b3dc3..ed3b98e 100644
@@ -85,6 +85,7 @@ static int get_scom(struct scom_device *scom_dev, uint64_t *value,
        uint32_t result, data;
        int rc;
 
Quoted 4 lines

drivers/fsi/fsi-scom.c static int get_scom(struct scom_device *scom_dev, uint64_t *value, · line 91

Quoted 4 lines
drivers/fsi/fsi-scom.c +1 -0
+       *value = 0ULL;
        data = addr;
        rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
                                sizeof(uint32_t));

We could do something more sensible, like apply the low 32 bits to value and then OR in the top half:

        rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA1_REG, &result,
                                sizeof(uint32_t));
        if (rc)
                return rc;
       *value = result;

       rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA0_REG, &result,
                                sizeof(uint32_t));
        if (rc)
                return rc;

        *value |= (uint64_t) result << 32;

Or have result1 and result2, and then only save to value the once:

    *value = (result0 << 32) | result1;

And then there are questions of endianess that must be considered before upstreaming.

I have applied the fix as-is to dev-4.7. Please consider a cleaner fix when applying this patch to the series for upstream.

Thanks for the review everyone. Most reviewed one liner OpenBMC has ever seen :D

In all seriousness, keep it up, it's good to share the load.

Cheers,

Joel

Reviewed-by on v1 1/1
#3 lore raw
In reply to Eddie James
Quoted 15 lines · Eddie James

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

Scom data is just bit-wise OR'd with the user buffer, so it needs to be set to 0 first.

---
  drivers/fsi/fsi-scom.c | 1 +
  1 file changed, 1 insertion(+)
drivers/fsi/fsi-scom.c +0 -0
index 51b3dc3..ed3b98e 100644

drivers/fsi/fsi-scom.c static int get_scom(struct scom_device *scom_dev, uint64_t *value, · line 91

Quoted 7 lines
drivers/fsi/fsi-scom.c +1 -0
@@ -85,6 +85,7 @@ static int get_scom(struct scom_device *scom_dev, uint64_t *value,
  	uint32_t result, data;
  	int rc;
 
+	*value = 0ULL;
  	data = addr;
  	rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
  				sizeof(uint32_t));