Skip to contentSkip to conversation

remove useless type cast

PATCH In review Yao Xingtao via 4 participants 8 messages Jul 22, 2024

lore
Share & tools
lore
#0 lore raw

cover remove useless type cast

Currently the pattern in scripts/coccinelle/typecast.cocci is used to remove the useless type cast.

Use the following command to find out the use cases and remove the useless type case:

$ spatch --macro-file scripts/cocci-macro-file.h \
         --sp-file ./scripts/coccinelle/typecast.cocci \
         --keep-comments --in-place --use-gitgrep --dir .

Yao Xingtao (2):
mips/loongson3_virt: remove useless type cast
nvme/ctrl: remove useless type cast

 hw/mips/loongson3_virt.c | 4 ++--
 hw/nvme/ctrl.c           | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/2 mips/loongson3_virt: remove useless type cast

The type of kernel_entry, kernel_low and kernel_high is uint64_t, cast the pointer of this type to uint64_t* is useless.

---
 hw/mips/loongson3_virt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +2 -2
index 4ad36f0c5b64..408e3d7054cd 100644
@@ -355,8 +355,8 @@ static uint64_t load_kernel(CPUMIPSState *env)
 
     kernel_size = load_elf(loaderparams.kernel_filename, NULL,
                            cpu_mips_kseg0_to_phys, NULL,
-                           (uint64_t *)&kernel_entry,
-                           (uint64_t *)&kernel_low, (uint64_t *)&kernel_high,
+                           &kernel_entry,
+                           &kernel_low, &kernel_high,
                            NULL, 0, EM_MIPS, 1, 0);
     if (kernel_size < 0) {
         error_report("could not load kernel '%s': %s",
Signature · 1 line
2.41.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mips/loongson3_virt: remove useless type cast

Quoted 15 lines · Yao Xingtao via

The type of kernel_entry, kernel_low and kernel_high is uint64_t, cast the pointer of this type to uint64_t* is useless.

---
 hw/mips/loongson3_virt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +0 -0
index 4ad36f0c5b64..408e3d7054cd 100644
@@ -355,8 +355,8 @@ static uint64_t load_kernel(CPUMIPSState *env)
 

hw/mips/loongson3_virt.c static uint64_t load_kernel(CPUMIPSState *env)

Quoted 10 lines
hw/mips/loongson3_virt.c +2 -3
     kernel_size = load_elf(loaderparams.kernel_filename, NULL,
                            cpu_mips_kseg0_to_phys, NULL,
-                           (uint64_t *)&kernel_entry,
-                           (uint64_t *)&kernel_low, (uint64_t *)&kernel_high,
+                           &kernel_entry,
+                           &kernel_low, &kernel_high,
                            NULL, 0, EM_MIPS, 1, 0);
     if (kernel_size < 0) {
         error_report("could not load kernel '%s': %s",
--

thanks
-- PMM

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] mips/loongson3_virt: remove useless type cast

In reply to Yao Xingtao via
Quoted 7 lines · Yao Xingtao

The type of kernel_entry, kernel_low and kernel_high is uint64_t, cast the pointer of this type to uint64_t* is useless.

---
  hw/mips/loongson3_virt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

and queued, thanks!

#5 lore raw

PATCH 2/2 nvme/ctrl: remove useless type cast

In reply to Yao Xingtao via

The type of req->cmd is NvmeCmd, cast the pointer of this type to NvmeCmd* is useless.

---
 hw/nvme/ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ctrl.c +1 -1
index 5b1b0cabcfc3..221818f551cd 100644
@@ -4167,7 +4167,7 @@ static bool nvme_zone_matches_filter(uint32_t zafs, NvmeZone *zl)
 
 static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req)
 {
-    NvmeCmd *cmd = (NvmeCmd *)&req->cmd;
+    NvmeCmd *cmd = &req->cmd;
     NvmeNamespace *ns = req->ns;
     /* cdw12 is zero-based number of dwords to return. Convert to bytes */
     uint32_t data_size = (le32_to_cpu(cmd->cdw12) + 1) << 2;
Signature · 1 line
2.41.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] nvme/ctrl: remove useless type cast

Quoted 23 lines · Yao Xingtao via

The type of req->cmd is NvmeCmd, cast the pointer of this type to NvmeCmd* is useless.

---
 hw/nvme/ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ctrl.c +1 -2
index 5b1b0cabcfc3..221818f551cd 100644
@@ -4167,7 +4167,7 @@ static bool nvme_zone_matches_filter(uint32_t zafs, NvmeZone *zl)
 
 static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req)
 {
-    NvmeCmd *cmd = (NvmeCmd *)&req->cmd;
+    NvmeCmd *cmd = &req->cmd;
     NvmeNamespace *ns = req->ns;
     /* cdw12 is zero-based number of dwords to return. Convert to bytes */
     uint32_t data_size = (le32_to_cpu(cmd->cdw12) + 1) << 2;
--
Quoted 1 line

2.41.0

thanks
-- PMM

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] nvme/ctrl: remove useless type cast

In reply to Yao Xingtao via
Quoted 24 lines · Yao Xingtao

The type of req->cmd is NvmeCmd, cast the pointer of this type to NvmeCmd* is useless.

---
 hw/nvme/ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ctrl.c +1 -1
index 5b1b0cabcfc3..221818f551cd 100644
@@ -4167,7 +4167,7 @@ static bool nvme_zone_matches_filter(uint32_t zafs, NvmeZone *zl)
 
 static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req)
 {
-    NvmeCmd *cmd = (NvmeCmd *)&req->cmd;
+    NvmeCmd *cmd = &req->cmd;
     NvmeNamespace *ns = req->ns;
     /* cdw12 is zero-based number of dwords to return. Convert to bytes */
     uint32_t data_size = (le32_to_cpu(cmd->cdw12) + 1) << 2;
Signature · 1 line
2.41.0

Thanks! Queued on nvme-next!