Skip to contentSkip to conversation

Update memdup_user.cocci

PATCH In review Markus Elfring 2 participants 3 messages Jul 26, 2020 – Aug 10, 2020

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

…

Quoted 3 lines
Quoted 3 lines

Changes in v3:
- add missing '-' for patch rule in kmalloc/kzalloc call args
- selfcheck rule dropped from patchset

…

Quoted 1 line

All three applied. …

Will the software development discussion be continued by patches according to previously mentioned ideas and remaining open issues?

Regards,
Markus

#1 lore raw

PATCH 1/1 Coccinelle: Reduce duplicate code for patch rules of memdup_user.cocci

From: Markus Elfring <[email protected]>
Date: Sun, 9 Aug 2020 11:11:20 +0200

Another patch rule was added. A bit of code was copied from a previous SmPL rule for this change specification.

* Thus reduce duplicate code by using another SmPL disjunction.

* Increase the precision a bit for desired source code adjustments.

Fixes 9c568dbd677bcfc975220d3157c89c48669a23e3 ("coccinelle: api: extend memdup_user rule with vmemdup_user()")
---
 scripts/coccinelle/api/memdup_user.cocci | 44 +++++++++---------------
 1 file changed, 16 insertions(+), 28 deletions(-)
scripts/coccinelle/api/memdup_user.cocci +16 -28
index e01e95108405..7cf698b4e925 100644
@@ -27,34 +27,22 @@ expression from,to,size;
 identifier l1,l2;
 position p : script:python() { relevant(p) };
 @@
-
--  to = \(kmalloc@p\|kzalloc@p\)
--		(size,\(GFP_KERNEL\|GFP_USER\|
--		      \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN\));
-+  to = memdup_user(from,size);
-   if (
--      to==NULL
-+      IS_ERR(to)
-                 || ...) {
-   <+... when != goto l1;
--  -ENOMEM
-+  PTR_ERR(to)
-   ...+>
-   }
--  if (copy_from_user(to, from, size) != 0) {
--    <+... when != goto l2;
--    -EFAULT
--    ...+>
--  }
-
-@depends on patch@
-expression from,to,size;
-identifier l1,l2;
-position p : script:python() { relevant(p) };
-@@
-
--  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
-+  to = vmemdup_user(from,size);
+ to =
+(
+-     \(kmalloc@p\|kzalloc@p\)
++     memdup_user
+      (
+-      size, \( \(GFP_KERNEL\|GFP_USER\) \| \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN \)
++      from, size
+      )
+|
+-     \(kvmalloc@p\|kvzalloc@p\)
++     vmemdup_user
+      (
+-      size, \(GFP_KERNEL\|GFP_USER\)
++      from, size
+      )
+);
    if (
 -      to==NULL
 +      IS_ERR(to)

--
2.28.0

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

maintainer
#2 lore raw

Re: [PATCH] Coccinelle: Reduce duplicate code for patch rules of memdup_user.cocci

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 9 Aug 2020 11:11:20 +0200

Another patch rule was added. A bit of code was copied from a previous SmPL rule for this change specification.

* Thus reduce duplicate code by using another SmPL disjunction.

I don't care about this issue.

Quoted 2 lines

* Increase the precision a bit for desired source code adjustments.

This gives no information. If you explain the improvement in an understandable way, I will consider whether it is useful to take the patch.

julia

Quoted 64 lines
Fixes 9c568dbd677bcfc975220d3157c89c48669a23e3 ("coccinelle: api: extend memdup_user rule with vmemdup_user()")
---
 scripts/coccinelle/api/memdup_user.cocci | 44 +++++++++---------------
 1 file changed, 16 insertions(+), 28 deletions(-)
scripts/coccinelle/api/memdup_user.cocci +15 -29
index e01e95108405..7cf698b4e925 100644
@@ -27,34 +27,22 @@ expression from,to,size;
 identifier l1,l2;
 position p : script:python() { relevant(p) };
 @@
-
--  to = \(kmalloc@p\|kzalloc@p\)
--		(size,\(GFP_KERNEL\|GFP_USER\|
--		      \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN\));
-+  to = memdup_user(from,size);
-   if (
--      to=NULL
-+      IS_ERR(to)
-                 || ...) {
-   <+... when != goto l1;
--  -ENOMEM
-+  PTR_ERR(to)
-   ...+>
-   }
--  if (copy_from_user(to, from, size) != 0) {
--    <+... when != goto l2;
--    -EFAULT
--    ...+>
--  }
-
-@depends on patch@
-expression from,to,size;
-identifier l1,l2;
-position p : script:python() { relevant(p) };
-@@
-
--  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
-+  to = vmemdup_user(from,size);
+ to > +(
+-     \(kmalloc@p\|kzalloc@p\)
++     memdup_user
+      (
+-      size, \( \(GFP_KERNEL\|GFP_USER\) \| \(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN \)
++      from, size
+      )
+|
+-     \(kvmalloc@p\|kvzalloc@p\)
++     vmemdup_user
+      (
+-      size, \(GFP_KERNEL\|GFP_USER\)
++      from, size
+      )
+);
    if (
 -      to=NULL
 +      IS_ERR(to)
--

2.28.0