Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Checking pretty-printing around a transformation for array_size()
@ 2019-10-15 12:40 Markus Elfring
  2019-10-26  9:46 ` [Cocci] Checking placement of spaces for code changes with SmPL Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2019-10-15 12:40 UTC (permalink / raw)
  To: Coccinelle

Hello,

I have tried another source code transformation approach out with
the software combination “Coccinelle 1.0.8-00004-g842075f7”.

@replacement@
expression count, item, source, target;
type t1, t2;
@@
 target = kmemdup(source,
+                 array_size(
(
                  sizeof(
-                        t1
+                        *source
                        )
|
                  count
)
-                 *
+                 ,
(
                  sizeof(
-                        t2
+                        *source
                        )
|
                  item
)
+                 )
                  , ...);


This small SmPL script can produce some “usable” results.
But I find the source code formatting occasionally questionable
according to the Linux coding style.

Example:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/mach-omap2/omap_device.c?id=5bc52f64e8841c4526d74f1073bfa95d4f6224d4#n348
https://elixir.bootlin.com/linux/v5.4-rc2/source/arch/arm/mach-omap2/omap_device.c#L348

elfring@Sonne:~/Projekte/Linux/next-patched> spatch arch/arm/mach-omap2/omap_device.c ~/Projekte/Coccinelle/janitor/use_array_size_for_kmemdup2.cocci
…
@@ -345,7 +345,7 @@ struct omap_device *omap_device_alloc(st
 	}
 	od->hwmods_cnt = oh_cnt;

-	hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
+	hwmods = kmemdup(ohs,array_size( sizeof(*ohs), oh_cnt), GFP_KERNEL);
 	if (!hwmods)
 		goto oda_exit2;
…


Would you like to clarify pretty-printing concerns?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Checking placement of spaces for code changes with SmPL
  2019-10-15 12:40 [Cocci] Checking pretty-printing around a transformation for array_size() Markus Elfring
@ 2019-10-26  9:46 ` Markus Elfring
  2019-10-26 12:45   ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2019-10-26  9:46 UTC (permalink / raw)
  To: Coccinelle

> But I find the source code formatting occasionally questionable
> according to the Linux coding style.

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch ../janitor/use_array_size_for_kmemdup2.cocci task_test6.c
…
@@ -1,6 +1,6 @@
 void* my_task(void)
 {
 void* copy;
-copy = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
+copy = kmemdup(ohs,array_size( sizeof(*ohs), oh_cnt), GFP_KERNEL);
 return copy;
 }


How would you like to clarify pretty-printing concerns?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Checking placement of spaces for code changes with SmPL
  2019-10-26  9:46 ` [Cocci] Checking placement of spaces for code changes with SmPL Markus Elfring
@ 2019-10-26 12:45   ` Julia Lawall
  2019-10-26 13:18     ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2019-10-26 12:45 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]



On Sat, 26 Oct 2019, Markus Elfring wrote:

> > But I find the source code formatting occasionally questionable
> > according to the Linux coding style.
>
> elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch ../janitor/use_array_size_for_kmemdup2.cocci task_test6.c
> …
> @@ -1,6 +1,6 @@
>  void* my_task(void)
>  {
>  void* copy;
> -copy = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
> +copy = kmemdup(ohs,array_size( sizeof(*ohs), oh_cnt), GFP_KERNEL);
>  return copy;
>  }
>
>
> How would you like to clarify pretty-printing concerns?

I would need the semantic patch to understand the problem.

julia


>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Checking placement of spaces for code changes with SmPL
  2019-10-26 12:45   ` Julia Lawall
@ 2019-10-26 13:18     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-10-26 13:18 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> I would need the semantic patch to understand the problem.

Please take another look at the corresponding clarification request
with the topic “Checking pretty-printing around a transformation for array_size()”.
https://lore.kernel.org/cocci/384c6657-5ddc-ff47-14e2-2ffad31295d2@web.de/
https://systeme.lip6.fr/pipermail/cocci/2019-October/006441.html

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 12:40 [Cocci] Checking pretty-printing around a transformation for array_size() Markus Elfring
2019-10-26  9:46 ` [Cocci] Checking placement of spaces for code changes with SmPL Markus Elfring
2019-10-26 12:45   ` Julia Lawall
2019-10-26 13:18     ` Markus Elfring

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git