Skip to contentSkip to conversation

net: ipa: a few bug fixes

PATCH Applied Alex Elder 3 participants 11 messages Feb 1, 2021 – Feb 2, 2021

Subsystems (3)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

cover net: ipa: a few bug fixes

This series fixes four minor bugs. The first two are things that sparse points out. All four are very simple and each patch should explain itself pretty well.

-Alex

Alex Elder (4):
net: ipa: add a missing __iomem attribute
net: ipa: be explicit about endianness
net: ipa: use the right accessor in ipa_endpoint_status_skip()
net: ipa: fix two format specifier errors

 drivers/net/ipa/gsi.c          | 2 +-
 drivers/net/ipa/ipa_endpoint.c | 6 +++---
 drivers/net/ipa/ipa_mem.c      | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/4 net: ipa: add a missing __iomem attribute

The virt local variable in gsi_channel_state() does not have an __iomem attribute but should. Fix this.

---
 drivers/net/ipa/gsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ipa/gsi.c +1 -1
index 14d9a791924bf..e2e77f09077a9 100644
@@ -440,7 +440,7 @@ static void gsi_evt_ring_de_alloc_command(struct gsi *gsi, u32 evt_ring_id)
 static enum gsi_channel_state gsi_channel_state(struct gsi_channel *channel)
 {
 	u32 channel_id = gsi_channel_id(channel);
-	void *virt = channel->gsi->virt;
+	void __iomem *virt = channel->gsi->virt;
 	u32 val;
 
 	val = ioread32(virt + GSI_CH_C_CNTXT_0_OFFSET(channel_id));
Signature · 1 line
2.27.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH net 1/4] net: ipa: add a missing __iomem attribute

Quoted 23 lines · Alex Elder

The virt local variable in gsi_channel_state() does not have an __iomem attribute but should. Fix this.

---
 drivers/net/ipa/gsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ipa/gsi.c +1 -2
index 14d9a791924bf..e2e77f09077a9 100644
@@ -440,7 +440,7 @@ static void gsi_evt_ring_de_alloc_command(struct gsi *gsi, u32 evt_ring_id)
 static enum gsi_channel_state gsi_channel_state(struct gsi_channel *channel)
 {
        u32 channel_id = gsi_channel_id(channel);
-       void *virt = channel->gsi->virt;
+       void __iomem *virt = channel->gsi->virt;
        u32 val;
 
        val = ioread32(virt + GSI_CH_C_CNTXT_0_OFFSET(channel_id));
--
Quoted 2 lines

2.27.0

Seems pretty straightforward to me, ioread32 expects an __iomem-annotated pointer.

author
#3 lore raw

PATCH 2/4 net: ipa: be explicit about endianness

In reply to Alex Elder

Sparse warns that the assignment of the metadata mask for a QMAP endpoint in ipa_endpoint_init_hdr_metadata_mask() is a bad assignment. We know we want the mask value to be big endian, even though the value we write is in host byte order. Use a __force tag to indicate we really mean it.

---
 drivers/net/ipa/ipa_endpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ipa/ipa_endpoint.c +1 -1
index 9f4be9812a1f3..448d89da1e456 100644
@@ -588,7 +588,7 @@ static void ipa_endpoint_init_hdr_metadata_mask(struct ipa_endpoint *endpoint)
 
 	/* Note that HDR_ENDIANNESS indicates big endian header fields */
 	if (endpoint->data->qmap)
-		val = cpu_to_be32(IPA_ENDPOINT_QMAP_METADATA_MASK);
+		val = (__force u32)cpu_to_be32(IPA_ENDPOINT_QMAP_METADATA_MASK);
 
 	iowrite32(val, endpoint->ipa->reg_virt + offset);
 }
Signature · 1 line
2.27.0
author
#4 lore raw

PATCH 3/4 net: ipa: use the right accessor in ipa_endpoint_status_skip()

In reply to Alex Elder

When extracting the destination endpoint ID from the status in ipa_endpoint_status_skip(), u32_get_bits() is used. This happens to work, but it's wrong: the structure field is only 8 bits wide instead of 32.

Fix this by using u8_get_bits() to get the destination endpoint ID.

---
 drivers/net/ipa/ipa_endpoint.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_endpoint.c +2 -2
index 448d89da1e456..612afece303f3 100644
@@ -1164,8 +1164,8 @@ static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint,
 		return true;
 	if (!status->pkt_len)
 		return true;
-	endpoint_id = u32_get_bits(status->endp_dst_idx,
-				   IPA_STATUS_DST_IDX_FMASK);
+	endpoint_id = u8_get_bits(status->endp_dst_idx,
+				  IPA_STATUS_DST_IDX_FMASK);
 	if (endpoint_id != endpoint->endpoint_id)
 		return true;
 
Signature · 1 line
2.27.0
#5 lore raw

Re: [PATCH net 3/4] net: ipa: use the right accessor in ipa_endpoint_status_skip()

Quoted 7 lines · Alex Elder

When extracting the destination endpoint ID from the status in ipa_endpoint_status_skip(), u32_get_bits() is used. This happens to work, but it's wrong: the structure field is only 8 bits wide instead of 32.

Fix this by using u8_get_bits() to get the destination endpoint ID.

Isn't

drivers/net/ipa/ipa_endpoint.c static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint, · line 1164

Quoted 12 lines
---
 drivers/net/ipa/ipa_endpoint.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_endpoint.c +0 -0
index 448d89da1e456..612afece303f3 100644
@@ -1164,8 +1164,8 @@ static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint,
                return true;

A few lines above this, endpoint_id is initialized as u32. If we're going for "correctness", endpoint_id should be a u8. But of course, this would contrast with ipa_endpoint having it as a u32.

Quoted 10 lines
drivers/net/ipa/ipa_endpoint.c +2 -3
        if (!status->pkt_len)
                return true;
-       endpoint_id = u32_get_bits(status->endp_dst_idx,
-                                  IPA_STATUS_DST_IDX_FMASK);
+       endpoint_id = u8_get_bits(status->endp_dst_idx,
+                                 IPA_STATUS_DST_IDX_FMASK);
        if (endpoint_id != endpoint->endpoint_id)
                return true;
 
--
Quoted 2 lines

2.27.0

As far as I see it, using u32_get_bits instead of u8_get_bits simply eliminates confusion about the type of endpoint_id. Perhaps instead of this patch, send a patch with a comment that while u32_get_bits is used, the field is only 8 bits?

Best regards,
Amy Parker
(she/her/hers)

#6 lore raw

Re: [PATCH net 3/4] net: ipa: use the right accessor in ipa_endpoint_status_skip()

Quoted 4 lines · Amy Parker
Quoted 1 line

Fix this by using u8_get_bits() to get the destination endpoint ID.

Isn't

Apologies about this - premature email sending. This was simply going to be "Isn't endpoint_id u32?", which was addressed later anyways.

Best regards,
Amy Parker
(she/her/hers)

author
#7 lore raw

Re: [PATCH net 3/4] net: ipa: use the right accessor in ipa_endpoint_status_skip()

In reply to Amy Parker
Quoted 10 lines · Amy Parker
Quoted 7 lines · Alex Elder

When extracting the destination endpoint ID from the status in ipa_endpoint_status_skip(), u32_get_bits() is used. This happens to work, but it's wrong: the structure field is only 8 bits wide instead of 32.

Fix this by using u8_get_bits() to get the destination endpoint ID.

Isn't

(I saw your second message.)

Quoted 5 lines
Quoted 5 lines
---
  drivers/net/ipa/ipa_endpoint.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 10 lines

drivers/net/ipa/ipa_endpoint.c static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint, · line 1164

Quoted 6 lines
drivers/net/ipa/ipa_endpoint.c +0 -0
index 448d89da1e456..612afece303f3 100644
@@ -1164,8 +1164,8 @@ static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint,
                 return true;

A few lines above this, endpoint_id is initialized as u32. If we're going for "correctness", endpoint_id should be a u8. But of course, this would contrast with ipa_endpoint having it as a u32.

You are correct, endpoint_id is *defined* as type u32.

But the issue here is that the field status->endp_dst_idx has type u8. u32_get_bits() assumes the field it is passed has type u32; while u8_get_bits() takes a u8.

The return value of u8_get_bits() is u8, as you might suspect. The C standard guarantees that the u8 value will be promoted to the u32 target type here.

Quoted 9 lines
Quoted 9 lines
drivers/net/ipa/ipa_endpoint.c +2 -2
         if (!status->pkt_len)
                 return true;
-       endpoint_id = u32_get_bits(status->endp_dst_idx,
-                                  IPA_STATUS_DST_IDX_FMASK);
+       endpoint_id = u8_get_bits(status->endp_dst_idx,
+                                 IPA_STATUS_DST_IDX_FMASK);
         if (endpoint_id != endpoint->endpoint_id)
                 return true;
 
Quoted 8 lines
Quoted 3 lines

--
2.27.0

As far as I see it, using u32_get_bits instead of u8_get_bits simply eliminates confusion about the type of endpoint_id. Perhaps instead of this patch, send a patch with a comment that while u32_get_bits is used, the field is only 8 bits?

No. We really want to extract a sub-field from the u8 value passed to u8_get_bits() (not u32_get_bits()).

Does that make sense?

-Alex

Quoted 4 lines

Best regards,
Amy Parker
(she/her/hers)

#8 lore raw

Re: [PATCH net 3/4] net: ipa: use the right accessor in ipa_endpoint_status_skip()

Quoted 31 lines · Alex Elder
Quoted 10 lines · Amy Parker
Quoted 7 lines · Alex Elder

When extracting the destination endpoint ID from the status in ipa_endpoint_status_skip(), u32_get_bits() is used. This happens to work, but it's wrong: the structure field is only 8 bits wide instead of 32.

Fix this by using u8_get_bits() to get the destination endpoint ID.

Isn't

(I saw your second message.)

Quoted 5 lines
Quoted 5 lines
---
  drivers/net/ipa/ipa_endpoint.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 10 lines

drivers/net/ipa/ipa_endpoint.c static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint, · line 1164

Quoted 6 lines
drivers/net/ipa/ipa_endpoint.c +0 -0
index 448d89da1e456..612afece303f3 100644
@@ -1164,8 +1164,8 @@ static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint,
                 return true;

A few lines above this, endpoint_id is initialized as u32. If we're going for "correctness", endpoint_id should be a u8. But of course, this would contrast with ipa_endpoint having it as a u32.

Quoted 5 lines

You are correct, endpoint_id is *defined* as type u32.

But the issue here is that the field status->endp_dst_idx has type u8. u32_get_bits() assumes the field it is passed has type u32; while u8_get_bits() takes a u8.

Ah, missed that bit. Thanks for clarifying.

Quoted 4 lines

The return value of u8_get_bits() is u8, as you might suspect. The C standard guarantees that the u8 value will be promoted to the u32 target type here.

Yes, it does, and so it wouldn't be a theoretical issue - just an issue of developer confusion at first when working with it. But the above outlined point of the types taken is more important.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ipa/ipa_endpoint.c +2 -2
         if (!status->pkt_len)
                 return true;
-       endpoint_id = u32_get_bits(status->endp_dst_idx,
-                                  IPA_STATUS_DST_IDX_FMASK);
+       endpoint_id = u8_get_bits(status->endp_dst_idx,
+                                 IPA_STATUS_DST_IDX_FMASK);
         if (endpoint_id != endpoint->endpoint_id)
                 return true;
 
Quoted 8 lines
Quoted 3 lines

--
2.27.0

As far as I see it, using u32_get_bits instead of u8_get_bits simply eliminates confusion about the type of endpoint_id. Perhaps instead of this patch, send a patch with a comment that while u32_get_bits is used, the field is only 8 bits?

Quoted 6 lines

No. We really want to extract a sub-field from the u8 value passed to u8_get_bits() (not u32_get_bits()).

Does that make sense?

-Alex

Yes, it does. Thank you.

Best regards,
Amy Parker
(she/her/hers)

author
#9 lore raw

PATCH 4/4 net: ipa: fix two format specifier errors

In reply to Alex Elder

Fix two format specifiers that used %lu for a size_t in "ipa_mem.c".

---
 drivers/net/ipa/ipa_mem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ipa/ipa_mem.c +2 -2
index 0cc3a3374caa2..f25029b9ec857 100644
@@ -336,7 +336,7 @@ static void ipa_imem_exit(struct ipa *ipa)
 
 		size = iommu_unmap(domain, ipa->imem_iova, ipa->imem_size);
 		if (size != ipa->imem_size)
-			dev_warn(dev, "unmapped %zu IMEM bytes, expected %lu\n",
+			dev_warn(dev, "unmapped %zu IMEM bytes, expected %zu\n",
 				 size, ipa->imem_size);
 	} else {
 		dev_err(dev, "couldn't get IPA IOMMU domain for IMEM\n");
@@ -440,7 +440,7 @@ static void ipa_smem_exit(struct ipa *ipa)
 
 		size = iommu_unmap(domain, ipa->smem_iova, ipa->smem_size);
 		if (size != ipa->smem_size)
-			dev_warn(dev, "unmapped %zu SMEM bytes, expected %lu\n",
+			dev_warn(dev, "unmapped %zu SMEM bytes, expected %zu\n",
 				 size, ipa->smem_size);
 
 	} else {
Signature · 1 line
2.27.0
#10 lore raw
In reply to Alex Elder
This series was applied to netdev/net.git (refs/heads/master):

Hello:

This series was applied to netdev/net.git (refs/heads/master):

Quoted 6 lines · On Mon, 1 Feb 2021 17:26:05 -0600 you wrote:

This series fixes four minor bugs. The first two are things that sparse points out. All four are very simple and each patch should explain itself pretty well.

-Alex

Quoted 7 lines

Alex Elder (4):
net: ipa: add a missing __iomem attribute
net: ipa: be explicit about endianness
net: ipa: use the right accessor in ipa_endpoint_status_skip()
net: ipa: fix two format specifier errors

[...]

Here is the summary with links:
- [net,1/4] net: ipa: add a missing __iomem attribute

    https://git.kernel.org/netdev/net/c/e6cdd6d80bae
  - [net,2/4] net: ipa: be explicit about endianness
    https://git.kernel.org/netdev/net/c/088f8a2396d8
  - [net,3/4] net: ipa: use the right accessor in ipa_endpoint_status_skip()
    https://git.kernel.org/netdev/net/c/c13899f18728
  - [net,4/4] net: ipa: fix two format specifier errors
    https://git.kernel.org/netdev/net/c/113b6ea09ccd

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html