From: josh@joshtriplett.org (Josh Triplett)
To: cocci@systeme.lip6.fr
Subject: [Cocci] if (...) {} semantic patch
Date: Sat, 2 Nov 2013 08:01:55 -0700 [thread overview]
Message-ID: <20131102150155.GU15704@leaf> (raw)
In-Reply-To: <alpine.DEB.2.02.1311021541590.2261@hadrien>
On Sat, Nov 02, 2013 at 03:46:52PM +0100, Julia Lawall wrote:
> I think that there are more side-effecting expressions that you should
> consider, eg E += E2, etc.
>
> The following lines from the SmPL lexer shows the operators that are
> supported:
>
> | "-=" { start_line true; mkassign Ast.Minus lexbuf }
> | "+=" { start_line true; mkassign Ast.Plus lexbuf }
> | "*=" { start_line true; mkassign Ast.Mul lexbuf }
> | "/=" { start_line true; mkassign Ast.Div lexbuf }
> | "%=" { start_line true; mkassign Ast.Mod lexbuf }
> | "&=" { start_line true; mkassign Ast.And lexbuf }
> | "|=" { start_line true; mkassign Ast.Or lexbuf }
> | "^=" { start_line true; mkassign Ast.Xor lexbuf }
> | ">?=" { start_line true; mkassign Ast.Max lexbuf }
> | "<?=" { start_line true; mkassign Ast.Min lexbuf }
> | "<<=" { start_line true; mkassign Ast.DecLeft lexbuf }
> | ">>=" { start_line true; mkassign Ast.DecRight lexbuf }
Interesting. I went by the example in
http://coccinelle.lip6.fr/rules/bugon.html , which doesn't include
those. I had assumed that the compound assignment operators were
subject to some kind of isomorphism that made matching them unnecessary.
You might consider providing some shortcut for matching code that has
side effects.
> Also, if the output from -D patch is sometimes undesirable, it would be
> useful to mention that in the initial comments about the semantic patch,
> so that the user knows that there is something to look for. The
> convention seems to be to put such comments after //#
Fair enough.
A couple of examples of the type of suboptimal output I meant in the
commit message:
--- a/arch/arm/mach-ux500/cpu-db8500.c
+++ b/arch/arm/mach-ux500/cpu-db8500.c
@@ -296,7 +296,8 @@ static void __init u8500_init_machine(vo
snowball_pinmaps_init();
} else if (of_machine_is_compatible("st-ericsson,hrefv60+"))
hrefv60_pinmaps_init();
- else if (of_machine_is_compatible("st-ericsson,ccu9540")) {}
+ else {of_machine_is_compatible("st-ericsson,ccu9540");
+}
/* TODO: Add pinmaps for ccu9540 board. */
/* automatically probe child nodes of dbx5x0 devices */
Leaving aside the issue that of_machine_is_compatible has no side
effects, the formatting is clearly wrong there.
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -3232,9 +3232,7 @@ void pm8001_bytes_dmaed(struct pm8001_hb
id->dev_type = phy->identify.device_type;
id->initiator_bits = SAS_PROTOCOL_ALL;
id->target_bits = phy->identify.target_port_protocols;
- } else if (phy->phy_type & PORT_TYPE_SATA) {
- /*Nothing*/
- }
+ } else {}
PM8001_MSG_DBG(pm8001_ha, pm8001_printk("phy %d byte dmaded.\n", i));
sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
This one should have the else dropped entirely.
--- a/arch/mn10300/kernel/signal.c
+++ b/arch/mn10300/kernel/signal.c
@@ -413,8 +413,7 @@ static void do_signal(struct pt_regs *re
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
if (signr > 0) {
- if (handle_signal(signr, &info, &ka, regs) == 0) {
- }
+ handle_signal(signr, &info, &ka, regs) == 0;
return;
}
Here, the " == 0" is unnecessary.
- Josh Triplett
next prev parent reply other threads:[~2013-11-02 15:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-02 13:36 [Cocci] Matching an absence of statements before the closing brace of a function? Josh Triplett
2013-11-02 14:27 ` Julia Lawall
2013-11-02 14:54 ` Josh Triplett
2013-11-02 15:02 ` Julia Lawall
2013-11-02 15:52 ` Josh Triplett
2013-11-02 16:02 ` Julia Lawall
2013-11-02 16:28 ` Josh Triplett
2013-11-02 16:34 ` Julia Lawall
2013-11-02 16:27 ` Julia Lawall
2013-11-02 21:01 ` Julia Lawall
2013-11-02 14:46 ` [Cocci] if (...) {} semantic patch Julia Lawall
2013-11-02 15:01 ` Josh Triplett [this message]
2013-11-02 15:08 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131102150155.GU15704@leaf \
--to=josh@joshtriplett.org \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.