Skip to contentSkip to conversation

pds_fwctl: fix type and endian complaints

PATCH Applied Shannon Nelson 4 participants 6 messages Apr 2, 2025 – Apr 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pds_fwctl: fix type and endian complaints

Fix a number of type and endian complaints from the sparse checker.

---
 drivers/fwctl/pds/main.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/fwctl/pds/main.c +20 -13
index 284c4165fdd4..9b9d1f6b5556 100644
@@ -105,12 +105,14 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)
 static void pdsfc_free_endpoints(struct pdsfc_dev *pdsfc)
 {
 	struct device *dev = &pdsfc->fwctl.dev;
+	u32 num_endpoints;
 	int i;
 
 	if (!pdsfc->endpoints)
 		return;
 
-	for (i = 0; pdsfc->endpoint_info && i < pdsfc->endpoints->num_entries; i++)
+	num_endpoints = le32_to_cpu(pdsfc->endpoints->num_entries);
+	for (i = 0; pdsfc->endpoint_info && i < num_endpoints; i++)
 		mutex_destroy(&pdsfc->endpoint_info[i].lock);
 	vfree(pdsfc->endpoint_info);
 	pdsfc->endpoint_info = NULL;
@@ -199,7 +201,7 @@ static int pdsfc_init_endpoints(struct pdsfc_dev *pdsfc)
 	ep_entry = (struct pds_fwctl_query_data_endpoint *)pdsfc->endpoints->entries;
 	for (i = 0; i < num_endpoints; i++) {
 		mutex_init(&pdsfc->endpoint_info[i].lock);
-		pdsfc->endpoint_info[i].endpoint = ep_entry[i].id;
+		pdsfc->endpoint_info[i].endpoint = le32_to_cpu(ep_entry[i].id);
 	}
 
 	return 0;
@@ -214,6 +216,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 	struct pds_fwctl_query_data *data;
 	union pds_core_adminq_cmd cmd;
 	dma_addr_t data_pa;
+	u32 num_entries;
 	int err;
 	int i;
 
@@ -246,8 +249,9 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 	*pa = data_pa;
 
 	entries = (struct pds_fwctl_query_data_operation *)data->entries;
-	dev_dbg(dev, "num_entries %d\n", data->num_entries);
-	for (i = 0; i < data->num_entries; i++) {
+	num_entries = le32_to_cpu(data->num_entries);
+	dev_dbg(dev, "num_entries %d\n", num_entries);
+	for (i = 0; i < num_entries; i++) {
 
 		/* Translate FW command attribute to fwctl scope */
 		switch (entries[i].scope) {
@@ -267,7 +271,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 			break;
 		}
 		dev_dbg(dev, "endpoint %d operation: id %x scope %d\n",
-			ep, entries[i].id, entries[i].scope);
+			ep, le32_to_cpu(entries[i].id), entries[i].scope);
 	}
 
 	return data;
@@ -280,24 +284,26 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 	struct pds_fwctl_query_data_operation *op_entry;
 	struct pdsfc_rpc_endpoint_info *ep_info = NULL;
 	struct device *dev = &pdsfc->fwctl.dev;
+	u32 num_entries;
 	int i;
 
 	/* validate rpc in_len & out_len based
 	 * on ident.max_req_sz & max_resp_sz
 	 */
-	if (rpc->in.len > pdsfc->ident.max_req_sz) {
+	if (rpc->in.len > le32_to_cpu(pdsfc->ident.max_req_sz)) {
 		dev_dbg(dev, "Invalid request size %u, max %u\n",
-			rpc->in.len, pdsfc->ident.max_req_sz);
+			rpc->in.len, le32_to_cpu(pdsfc->ident.max_req_sz));
 		return -EINVAL;
 	}
 
-	if (rpc->out.len > pdsfc->ident.max_resp_sz) {
+	if (rpc->out.len > le32_to_cpu(pdsfc->ident.max_resp_sz)) {
 		dev_dbg(dev, "Invalid response size %u, max %u\n",
-			rpc->out.len, pdsfc->ident.max_resp_sz);
+			rpc->out.len, le32_to_cpu(pdsfc->ident.max_resp_sz));
 		return -EINVAL;
 	}
 
-	for (i = 0; i < pdsfc->endpoints->num_entries; i++) {
+	num_entries = le32_to_cpu(pdsfc->endpoints->num_entries);
+	for (i = 0; i < num_entries; i++) {
 		if (pdsfc->endpoint_info[i].endpoint == rpc->in.ep) {
 			ep_info = &pdsfc->endpoint_info[i];
 			break;
@@ -326,8 +332,9 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 
 	/* reject unsupported and/or out of scope commands */
 	op_entry = (struct pds_fwctl_query_data_operation *)ep_info->operations->entries;
-	for (i = 0; i < ep_info->operations->num_entries; i++) {
-		if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, op_entry[i].id)) {
+	num_entries = le32_to_cpu(ep_info->operations->num_entries);
+	for (i = 0; i < num_entries; i++) {
+		if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, le32_to_cpu(op_entry[i].id))) {
 			if (scope < op_entry[i].scope)
 				return -EPERM;
 			return 0;
@@ -402,7 +409,7 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
 	cmd = (union pds_core_adminq_cmd) {
 		.fwctl_rpc = {
 			.opcode = PDS_FWCTL_CMD_RPC,
-			.flags = PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP,
+			.flags = cpu_to_le16(PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP),
 			.ep = cpu_to_le32(rpc->in.ep),
 			.op = cpu_to_le32(rpc->in.op),
 			.req_pa = cpu_to_le64(in_payload_dma_addr),
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 72 lines · Shannon Nelson

Fix a number of type and endian complaints from the sparse checker.

---
 drivers/fwctl/pds/main.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/fwctl/pds/main.c +10 -5
index 284c4165fdd4..9b9d1f6b5556 100644
@@ -105,12 +105,14 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)
 static void pdsfc_free_endpoints(struct pdsfc_dev *pdsfc)
 {
 	struct device *dev = &pdsfc->fwctl.dev;
+	u32 num_endpoints;
 	int i;
 
 	if (!pdsfc->endpoints)
 		return;
 
-	for (i = 0; pdsfc->endpoint_info && i < pdsfc->endpoints->num_entries; i++)
+	num_endpoints = le32_to_cpu(pdsfc->endpoints->num_entries);
+	for (i = 0; pdsfc->endpoint_info && i < num_endpoints; i++)
 		mutex_destroy(&pdsfc->endpoint_info[i].lock);
 	vfree(pdsfc->endpoint_info);
 	pdsfc->endpoint_info = NULL;
@@ -199,7 +201,7 @@ static int pdsfc_init_endpoints(struct pdsfc_dev *pdsfc)
 	ep_entry = (struct pds_fwctl_query_data_endpoint *)pdsfc->endpoints->entries;
 	for (i = 0; i < num_endpoints; i++) {
 		mutex_init(&pdsfc->endpoint_info[i].lock);
-		pdsfc->endpoint_info[i].endpoint = ep_entry[i].id;
+		pdsfc->endpoint_info[i].endpoint = le32_to_cpu(ep_entry[i].id);
 	}
 
 	return 0;
@@ -214,6 +216,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 	struct pds_fwctl_query_data *data;
 	union pds_core_adminq_cmd cmd;
 	dma_addr_t data_pa;
+	u32 num_entries;
 	int err;
 	int i;
 
@@ -246,8 +249,9 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 	*pa = data_pa;
 
 	entries = (struct pds_fwctl_query_data_operation *)data->entries;
-	dev_dbg(dev, "num_entries %d\n", data->num_entries);
-	for (i = 0; i < data->num_entries; i++) {
+	num_entries = le32_to_cpu(data->num_entries);
+	dev_dbg(dev, "num_entries %d\n", num_entries);
+	for (i = 0; i < num_entries; i++) {
 
 		/* Translate FW command attribute to fwctl scope */
 		switch (entries[i].scope) {
@@ -267,7 +271,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
 			break;
 		}
 		dev_dbg(dev, "endpoint %d operation: id %x scope %d\n",
-			ep, entries[i].id, entries[i].scope);
+			ep, le32_to_cpu(entries[i].id), entries[i].scope);
 	}
 
 	return data;
@@ -280,24 +284,26 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 	struct pds_fwctl_query_data_operation *op_entry;
 	struct pdsfc_rpc_endpoint_info *ep_info = NULL;
 	struct device *dev = &pdsfc->fwctl.dev;
+	u32 num_entries;

drivers/fwctl/pds/main.c static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc, · line 295

Quoted 10 lines
drivers/fwctl/pds/main.c +2 -2
 	int i;
 
 	/* validate rpc in_len & out_len based
 	 * on ident.max_req_sz & max_resp_sz
 	 */
-	if (rpc->in.len > pdsfc->ident.max_req_sz) {
+	if (rpc->in.len > le32_to_cpu(pdsfc->ident.max_req_sz)) {
 		dev_dbg(dev, "Invalid request size %u, max %u\n",
-			rpc->in.len, pdsfc->ident.max_req_sz);
+			rpc->in.len, le32_to_cpu(pdsfc->ident.max_req_sz));

Maybe use a local var for max_req_sz. I'm seeing that getting converted more than once in the same function.

drivers/fwctl/pds/main.c static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc, · line 301

Quoted 8 lines
drivers/fwctl/pds/main.c +2 -2
 		return -EINVAL;
 	}
 
-	if (rpc->out.len > pdsfc->ident.max_resp_sz) {
+	if (rpc->out.len > le32_to_cpu(pdsfc->ident.max_resp_sz)) {
 		dev_dbg(dev, "Invalid response size %u, max %u\n",
-			rpc->out.len, pdsfc->ident.max_resp_sz);
+			rpc->out.len, le32_to_cpu(pdsfc->ident.max_resp_sz));

Same for max_res_sz.

DJ

Quoted 30 lines
drivers/fwctl/pds/main.c +6 -4
 		return -EINVAL;
 	}
 
-	for (i = 0; i < pdsfc->endpoints->num_entries; i++) {
+	num_entries = le32_to_cpu(pdsfc->endpoints->num_entries);
+	for (i = 0; i < num_entries; i++) {
 		if (pdsfc->endpoint_info[i].endpoint == rpc->in.ep) {
 			ep_info = &pdsfc->endpoint_info[i];
 			break;
@@ -326,8 +332,9 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 
 	/* reject unsupported and/or out of scope commands */
 	op_entry = (struct pds_fwctl_query_data_operation *)ep_info->operations->entries;
-	for (i = 0; i < ep_info->operations->num_entries; i++) {
-		if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, op_entry[i].id)) {
+	num_entries = le32_to_cpu(ep_info->operations->num_entries);
+	for (i = 0; i < num_entries; i++) {
+		if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, le32_to_cpu(op_entry[i].id))) {
 			if (scope < op_entry[i].scope)
 				return -EPERM;
 			return 0;
@@ -402,7 +409,7 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
 	cmd = (union pds_core_adminq_cmd) {
 		.fwctl_rpc = {
 			.opcode = PDS_FWCTL_CMD_RPC,
-			.flags = PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP,
+			.flags = cpu_to_le16(PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP),
 			.ep = cpu_to_le32(rpc->in.ep),
 			.op = cpu_to_le32(rpc->in.op),
 			.req_pa = cpu_to_le64(in_payload_dma_addr),
#2 lore raw
Quoted 89 lines · Dave Jiang
Quoted 72 lines · Shannon Nelson

Fix a number of type and endian complaints from the sparse checker.

---
  drivers/fwctl/pds/main.c | 33 ++++++++++++++++++++-------------
  1 file changed, 20 insertions(+), 13 deletions(-)
drivers/fwctl/pds/main.c +10 -5
index 284c4165fdd4..9b9d1f6b5556 100644
@@ -105,12 +105,14 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)
  static void pdsfc_free_endpoints(struct pdsfc_dev *pdsfc)
  {
       struct device *dev = &pdsfc->fwctl.dev;
+     u32 num_endpoints;
       int i;
 
       if (!pdsfc->endpoints)
               return;
 
-     for (i = 0; pdsfc->endpoint_info && i < pdsfc->endpoints->num_entries; i++)
+     num_endpoints = le32_to_cpu(pdsfc->endpoints->num_entries);
+     for (i = 0; pdsfc->endpoint_info && i < num_endpoints; i++)
               mutex_destroy(&pdsfc->endpoint_info[i].lock);
       vfree(pdsfc->endpoint_info);
       pdsfc->endpoint_info = NULL;
@@ -199,7 +201,7 @@ static int pdsfc_init_endpoints(struct pdsfc_dev *pdsfc)
       ep_entry = (struct pds_fwctl_query_data_endpoint *)pdsfc->endpoints->entries;
       for (i = 0; i < num_endpoints; i++) {
               mutex_init(&pdsfc->endpoint_info[i].lock);
-             pdsfc->endpoint_info[i].endpoint = ep_entry[i].id;
+             pdsfc->endpoint_info[i].endpoint = le32_to_cpu(ep_entry[i].id);
       }
 
       return 0;
@@ -214,6 +216,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
       struct pds_fwctl_query_data *data;
       union pds_core_adminq_cmd cmd;
       dma_addr_t data_pa;
+     u32 num_entries;
       int err;
       int i;
 
@@ -246,8 +249,9 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
       *pa = data_pa;
 
       entries = (struct pds_fwctl_query_data_operation *)data->entries;
-     dev_dbg(dev, "num_entries %d\n", data->num_entries);
-     for (i = 0; i < data->num_entries; i++) {
+     num_entries = le32_to_cpu(data->num_entries);
+     dev_dbg(dev, "num_entries %d\n", num_entries);
+     for (i = 0; i < num_entries; i++) {
 
               /* Translate FW command attribute to fwctl scope */
               switch (entries[i].scope) {
@@ -267,7 +271,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
                       break;
               }
               dev_dbg(dev, "endpoint %d operation: id %x scope %d\n",
-                     ep, entries[i].id, entries[i].scope);
+                     ep, le32_to_cpu(entries[i].id), entries[i].scope);
       }
 
       return data;
@@ -280,24 +284,26 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
       struct pds_fwctl_query_data_operation *op_entry;
       struct pdsfc_rpc_endpoint_info *ep_info = NULL;
       struct device *dev = &pdsfc->fwctl.dev;
+     u32 num_entries;

drivers/fwctl/pds/main.c static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc, · line 295

Quoted 10 lines
drivers/fwctl/pds/main.c +2 -2
       int i;
 
       /* validate rpc in_len & out_len based
        * on ident.max_req_sz & max_resp_sz
        */
-     if (rpc->in.len > pdsfc->ident.max_req_sz) {
+     if (rpc->in.len > le32_to_cpu(pdsfc->ident.max_req_sz)) {
               dev_dbg(dev, "Invalid request size %u, max %u\n",
-                     rpc->in.len, pdsfc->ident.max_req_sz);
+                     rpc->in.len, le32_to_cpu(pdsfc->ident.max_req_sz));

Maybe use a local var for max_req_sz. I'm seeing that getting converted more than once in the same function.

Quoted 3 lines
drivers/fwctl/pds/main.c +0 -0
               return -EINVAL;
       }
 
Quoted 7 lines

drivers/fwctl/pds/main.c static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc, · line 301

Quoted 5 lines
drivers/fwctl/pds/main.c +2 -2
-     if (rpc->out.len > pdsfc->ident.max_resp_sz) {
+     if (rpc->out.len > le32_to_cpu(pdsfc->ident.max_resp_sz)) {
               dev_dbg(dev, "Invalid response size %u, max %u\n",
-                     rpc->out.len, pdsfc->ident.max_resp_sz);
+                     rpc->out.len, le32_to_cpu(pdsfc->ident.max_resp_sz));

Same for max_res_sz.

I went back and forth on that, then left them this way in anticipation of possibly removing the dev_dbg() uses. I could go either way on this.

sln

Quoted 34 lines

DJ

Quoted 30 lines
drivers/fwctl/pds/main.c +6 -4
               return -EINVAL;
       }
 
-     for (i = 0; i < pdsfc->endpoints->num_entries; i++) {
+     num_entries = le32_to_cpu(pdsfc->endpoints->num_entries);
+     for (i = 0; i < num_entries; i++) {
               if (pdsfc->endpoint_info[i].endpoint == rpc->in.ep) {
                       ep_info = &pdsfc->endpoint_info[i];
                       break;
@@ -326,8 +332,9 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 
       /* reject unsupported and/or out of scope commands */
       op_entry = (struct pds_fwctl_query_data_operation *)ep_info->operations->entries;
-     for (i = 0; i < ep_info->operations->num_entries; i++) {
-             if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, op_entry[i].id)) {
+     num_entries = le32_to_cpu(ep_info->operations->num_entries);
+     for (i = 0; i < num_entries; i++) {
+             if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, le32_to_cpu(op_entry[i].id))) {
                       if (scope < op_entry[i].scope)
                               return -EPERM;
                       return 0;
@@ -402,7 +409,7 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
       cmd = (union pds_core_adminq_cmd) {
               .fwctl_rpc = {
                       .opcode = PDS_FWCTL_CMD_RPC,
-                     .flags = PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP,
+                     .flags = cpu_to_le16(PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP),
                       .ep = cpu_to_le32(rpc->in.ep),
                       .op = cpu_to_le32(rpc->in.op),
                       .req_pa = cpu_to_le64(in_payload_dma_addr),
maintainer Reviewed-by
#3 lore raw
Quoted 96 lines · Shannon
Quoted 95 lines · Dave Jiang
Quoted 72 lines · Shannon Nelson

Fix a number of type and endian complaints from the sparse checker.

---
  drivers/fwctl/pds/main.c | 33 ++++++++++++++++++++-------------

  1 file changed, 20 insertions(+), 13 deletions(-)
drivers/fwctl/pds/main.c +10 -5
index 284c4165fdd4..9b9d1f6b5556 100644
@@ -105,12 +105,14 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)
   static void pdsfc_free_endpoints(struct pdsfc_dev *pdsfc)
   {
        struct device *dev = &pdsfc->fwctl.dev;
+     u32 num_endpoints;
        int i;
 
        if (!pdsfc->endpoints)
                return;
 
-     for (i = 0; pdsfc->endpoint_info && i < pdsfc->endpoints->num_entries; i++)
+     num_endpoints = le32_to_cpu(pdsfc->endpoints->num_entries);
+     for (i = 0; pdsfc->endpoint_info && i < num_endpoints; i++)
                mutex_destroy(&pdsfc->endpoint_info[i].lock);
        vfree(pdsfc->endpoint_info);
        pdsfc->endpoint_info = NULL;
@@ -199,7 +201,7 @@ static int pdsfc_init_endpoints(struct pdsfc_dev *pdsfc)
        ep_entry = (struct pds_fwctl_query_data_endpoint *)pdsfc->endpoints->entries;
        for (i = 0; i < num_endpoints; i++) {
                mutex_init(&pdsfc->endpoint_info[i].lock);
-             pdsfc->endpoint_info[i].endpoint = ep_entry[i].id;
+             pdsfc->endpoint_info[i].endpoint = le32_to_cpu(ep_entry[i].id);
        }
 
        return 0;
@@ -214,6 +216,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
        struct pds_fwctl_query_data *data;
        union pds_core_adminq_cmd cmd;
        dma_addr_t data_pa;
+     u32 num_entries;
        int err;
        int i;
 
@@ -246,8 +249,9 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
        *pa = data_pa;
 
        entries = (struct pds_fwctl_query_data_operation *)data->entries;
-     dev_dbg(dev, "num_entries %d\n", data->num_entries);
-     for (i = 0; i < data->num_entries; i++) {
+     num_entries = le32_to_cpu(data->num_entries);
+     dev_dbg(dev, "num_entries %d\n", num_entries);
+     for (i = 0; i < num_entries; i++) {
 
                /* Translate FW command attribute to fwctl scope */
                switch (entries[i].scope) {
@@ -267,7 +271,7 @@ static struct pds_fwctl_query_data *pdsfc_get_operations(struct pdsfc_dev *pdsfc
                        break;
                }
                dev_dbg(dev, "endpoint %d operation: id %x scope %d\n",
-                     ep, entries[i].id, entries[i].scope);
+                     ep, le32_to_cpu(entries[i].id), entries[i].scope);
        }
 
        return data;
@@ -280,24 +284,26 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
        struct pds_fwctl_query_data_operation *op_entry;
        struct pdsfc_rpc_endpoint_info *ep_info = NULL;
        struct device *dev = &pdsfc->fwctl.dev;
+     u32 num_entries;

drivers/fwctl/pds/main.c static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc, · line 295

Quoted 10 lines
drivers/fwctl/pds/main.c +2 -2
        int i;
 
        /* validate rpc in_len & out_len based
         * on ident.max_req_sz & max_resp_sz
         */
-     if (rpc->in.len > pdsfc->ident.max_req_sz) {
+     if (rpc->in.len > le32_to_cpu(pdsfc->ident.max_req_sz)) {
                dev_dbg(dev, "Invalid request size %u, max %u\n",
-                     rpc->in.len, pdsfc->ident.max_req_sz);
+                     rpc->in.len, le32_to_cpu(pdsfc->ident.max_req_sz));

Maybe use a local var for max_req_sz. I'm seeing that getting converted more than once in the same function.

Quoted 8 lines
drivers/fwctl/pds/main.c +2 -2
                return -EINVAL;
        }
 
-     if (rpc->out.len > pdsfc->ident.max_resp_sz) {
+     if (rpc->out.len > le32_to_cpu(pdsfc->ident.max_resp_sz)) {
                dev_dbg(dev, "Invalid response size %u, max %u\n",
-                     rpc->out.len, pdsfc->ident.max_resp_sz);
+                     rpc->out.len, le32_to_cpu(pdsfc->ident.max_resp_sz));
Quoted 3 lines
Quoted 1 line

Same for max_res_sz.

I went back and forth on that, then left them this way in anticipation of possibly removing the dev_dbg() uses.  I could go either way on this.

Up to you.

Quoted 38 lines

sln

Quoted 34 lines

DJ

Quoted 30 lines
drivers/fwctl/pds/main.c +6 -4
                return -EINVAL;
        }
 
-     for (i = 0; i < pdsfc->endpoints->num_entries; i++) {
+     num_entries = le32_to_cpu(pdsfc->endpoints->num_entries);
+     for (i = 0; i < num_entries; i++) {
                if (pdsfc->endpoint_info[i].endpoint == rpc->in.ep) {
                        ep_info = &pdsfc->endpoint_info[i];
                        break;
@@ -326,8 +332,9 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 
        /* reject unsupported and/or out of scope commands */
        op_entry = (struct pds_fwctl_query_data_operation *)ep_info->operations->entries;
-     for (i = 0; i < ep_info->operations->num_entries; i++) {
-             if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, op_entry[i].id)) {
+     num_entries = le32_to_cpu(ep_info->operations->num_entries);
+     for (i = 0; i < num_entries; i++) {
+             if (PDS_FWCTL_RPC_OPCODE_CMP(rpc->in.op, le32_to_cpu(op_entry[i].id))) {
                        if (scope < op_entry[i].scope)
                                return -EPERM;
                        return 0;
@@ -402,7 +409,7 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
        cmd = (union pds_core_adminq_cmd) {
                .fwctl_rpc = {
                        .opcode = PDS_FWCTL_CMD_RPC,
-                     .flags = PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP,
+                     .flags = cpu_to_le16(PDS_FWCTL_RPC_IND_REQ | PDS_FWCTL_RPC_IND_RESP),
                        .ep = cpu_to_le32(rpc->in.ep),
                        .op = cpu_to_le32(rpc->in.op),
                        .req_pa = cpu_to_le64(in_payload_dma_addr),
maintainer Applied
#5 lore raw
In reply to Shannon Nelson
Quoted 8 lines · Shannon Nelson

Fix a number of type and endian complaints from the sparse checker.

---
 drivers/fwctl/pds/main.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

Applied, thanks

Jason