Skip to contentSkip to conversation

staging: media: atomisp: Remove useless cast.

PATCH In review Varsha Rao 2 participants 7 messages Mar 8, 2017 – Mar 9, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Varsha Rao

author
#1 lore raw

PATCH 1/2 staging: media: atomisp: Remove useless cast.

In reply to a message not in the archive

Explicit type casting of variable, with same type as that of variable, is not required. The following coccinelle script is used to remove it.

@@
type T;
T *ptr,p;
@@
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p)
+ p
)

---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c    | 2 +-
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_sp.c | 2 +-
 drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +1 -1
index f39d6f5..0bb6fa0 100644
@@ -1335,7 +1335,7 @@ static int pc_monitoring(void *data)
 {
 	int i = 0;
 
-	(void)data;
+	data;
 	while (true) {
 		if (sh_binary_running) {
 			sh_css_metrics_sample_pcs();
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_sp.c +1 -1
index 00b2d16..e274950 100644
@@ -1155,7 +1155,7 @@ sp_init_stage(struct ia_css_pipeline_stage *stage,
 	}
 
 	err = sh_css_sp_init_stage(binary,
-			     (const char *)binary_name,
+			     binary_name,
 			     blob_info,
 			     args,
 			     pipe_num,
drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c +1 -1
index 358d340..a32c981 100644
@@ -553,7 +553,7 @@ int hmm_set(ia_css_ptr virt, int c, unsigned int bytes)
 		vptr = hmm_bo_vmap(bo, true);
 		if (vptr) {
 			vptr = vptr + (virt - bo->start);
-			memset((void *)vptr, c, bytes);
+			memset(vptr, c, bytes);
 			clflush_cache_range(vptr, bytes);
 			hmm_bo_vunmap(bo);
 			return 0;
Signature · 1 line
2.9.3
author
#7 lore raw

PATCH 2/2 staging: media: atomisp: Remove unnecessary identifier.

In reply to a message not in the archive

This patch removes indentifier data, which is not required.

---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +0 -1
index 0bb6fa0..b575365 100644
@@ -1335,7 +1335,6 @@ static int pc_monitoring(void *data)
 {
 	int i = 0;
 
-	data;
 	while (true) {
 		if (sh_binary_running) {
 			sh_css_metrics_sample_pcs();
Signature · 1 line
2.9.3
#2 lore raw
In reply to Varsha Rao

y

Quoted 33 lines · Varsha Rao

Explicit type casting of variable, with same type as that of variable, is not required. The following coccinelle script is used to remove it.

@@
type T;
T *ptr,p;
@@
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p)
+ p
)

---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c    | 2 +-
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_sp.c | 2 +-
 drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +0 -0
index f39d6f5..0bb6fa0 100644

drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c static int pc_monitoring(void *data) · line 1338

Quoted 5 lines
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +1 -1
@@ -1335,7 +1335,7 @@ static int pc_monitoring(void *data)
 {
 	int i = 0;
 
-	(void)data;
+	data;

Did Coccinelle really find this case for you? Because void and void * are not the same.

julia

Quoted 39 lines
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +0 -0
 	while (true) {
 		if (sh_binary_running) {
 			sh_css_metrics_sample_pcs();
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_sp.c +1 -1
index 00b2d16..e274950 100644
@@ -1155,7 +1155,7 @@ sp_init_stage(struct ia_css_pipeline_stage *stage,
 	}
 
 	err = sh_css_sp_init_stage(binary,
-			     (const char *)binary_name,
+			     binary_name,
 			     blob_info,
 			     args,
 			     pipe_num,
drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c +1 -2
index 358d340..a32c981 100644
@@ -553,7 +553,7 @@ int hmm_set(ia_css_ptr virt, int c, unsigned int bytes)
 		vptr = hmm_bo_vmap(bo, true);
 		if (vptr) {
 			vptr = vptr + (virt - bo->start);
-			memset((void *)vptr, c, bytes);
+			memset(vptr, c, bytes);
 			clflush_cache_range(vptr, bytes);
 			hmm_bo_vunmap(bo);
 			return 0;
--

2.9.3

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/58bf8051.081a620a.e7433.8064%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

author
#3 lore raw

Hello,

Did Coccinelle really find this case for you? Because void and void * are

Quoted 3 lines

not the same.

Yes, it was found using Coccinelle. I got the output as following.

diff -u -p a/media/atomisp/pci/atomisp2/css2400/sh_css.c
b/media/atomisp/pci/atomisp2/css2400/sh_css.c

media/atomisp/pci/atomisp2/css2400/sh_css.c +1 -1
@@ -1335,7 +1335,7 @@ static int pc_monitoring(void *data)
 {
        int i = 0;
 
-       (void)data;
+       data;
        while (true) {
                if (sh_binary_running) {
                        sh_css_metrics_sample_pcs();

@@
type T; //Here if we assume T to be type void
T *ptr,p; //ptr is pointer to void and p is of type void. @@

As you said void and void * are different.
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p) It is taking this case.
+ p
)

But p and ptr are also different, then why is it considering p? Is it giving false positive?
To check this, I just changed the declaration.

@@
type T;
T *ptr;
T p;
@@
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p)
+ p
)

However, here it does not match void and void * . Also gives no output for this particular file.
Why is it not recognizing the difference between ptr and p ? (with the earlier coccinelle script)

Thanks,
Varsha

#4 lore raw
Quoted 63 lines · Varsha Rao

Hello,

Did Coccinelle really find this case for you?  Because void and void * are not the same.

   Yes, it was found using Coccinelle. I got the output as following.

   diff -u -p a/media/atomisp/pci/atomisp2/css2400/sh_css.c b/media/atomisp/pci/atomisp2/css2400/sh_css.c

media/atomisp/pci/atomisp2/css2400/sh_css.c +1 -1
@@ -1335,7 +1335,7 @@ static int pc_monitoring(void *data)
  {
         int i = 0;
 
-       (void)data;
+       data;
         while (true) {
                 if (sh_binary_running) {
                         sh_css_metrics_sample_pcs();


 @@
type T;    //Here if we assume T to be type void T *ptr,p;  //ptr is pointer to void and p is of type void. @@

As you said void and void * are different.
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p)   It is taking this case.
+ p
)

But p and ptr are also different, then why is it considering p? Is it giving false positive? To  check this, I just changed the declaration.

@@
type T;
T *ptr;
T p;
@@
(
- (T *)(&p)
+ &p
|
- (T *)ptr
+ ptr
|
- (T *)(ptr)
+ ptr
|
- (T)(p)
+ p
)

Quoted 2 lines

However, here it does not match void and void * . Also gives no output for this particular file. Why is it not recognizing the difference between ptr and p ? (with the earlier coccinelle script)

Because there is a bug in the parsing of metavariable identifiers. I knew this, but haven't thought about it recently... I think that once it sees a *, it applies the * to everything that comes after. Or more likely, it is probably parsing the metavariables as T * being the type, and the list of names coming after.

I'll make a note to fix it.

thanks,
julia

Quoted 12 lines

Thanks,
Varsha

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/53167cf4-2fc5-4178-b963-c616822ae3b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

author
#5 lore raw

Hello,

Quoted 5 lines

However, here it does not match void and void * . Also gives no output for this particular file.

Quoted 1 line

Why is it not recognizing the difference between ptr and p ? (with the

earlier coccinelle script)

Quoted 9 lines

Because there is a bug in the parsing of metavariable identifiers. I knew this, but haven't thought about it recently... I think that once it sees a *, it applies the * to everything that comes after. Or more likely, it is probably parsing the metavariables as T * being the type, and the list of names coming after.

I'll make a note to fix it.

Yes, it is indeed a bug and thanks for considering it. I hope the
following observation would be of help.

There was one more case, which I ignored as it gave false result. (using
the first script)
Such as it could not recognize difference between declaration unsigned
int __user *user_chanlist and cast (unsigned int __force *)user_chanlist .
Removed the later casting. The file is comedi/comedi_fops.c

- cmd.chanlist = (unsigned int __force *)user_chanlist;
+ cmd.chanlist = user_chanlist;

Thanks,
Varsha

#6 lore raw
Quoted 24 lines · Varsha Rao

Hello,

> However, here it does not match void and void * . Also gives no output for this particular file.
> Why is it not recognizing the difference between ptr and p ? (with the earlier coccinelle script)

Because there is a bug in the parsing of metavariable identifiers.  I knew
this, but haven't thought about it recently...  I think that once it sees
a *, it applies the * to everything that comes after.  Or more likely, it
is probably parsing the metavariables as T * being the type, and the list
of names coming after.

I'll make a note to fix it.

  Yes, it is indeed a bug and thanks for considering it. I hope the following observation would be of help.

Quoted 8 lines

  There was one more case, which I ignored as it gave false result. (using the first script)
  Such as it could not recognize difference between declaration unsigned int __user *user_chanlist and cast (unsigned int __force *)user_chanlist . Removed the later casting. The file is comedi/comedi_fops.c

  -               cmd.chanlist = (unsigned int __force *)user_chanlist; +               cmd.chanlist = user_chanlist;

Yeah, Coccinelle is also not good at annotations at the moment - work in progress... It was good thinking to ignore this case.

julia

Quoted 15 lines

   Thanks,
   Varsha

--
You received this message because you are subscribed to the Google Groups
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/c301a39d-7f44-4c3e-8f6c- 2350b5938d1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.