From 060414704ba7bead00535aa2737fcf2953ca754d Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Mon, 5 Nov 2018 20:16:49 +0530 Subject: [PATCH] coccinelle: unsigned_shift.cocci: Update script * Use `expression` metavariable instead of `constant` to catch missing cases such as: diff -u -p a/subsys/net/ip/rpl.c b/subsys/net/ip/rpl.c --- a/subsys/net/ip/rpl.c +++ b/subsys/net/ip/rpl.c @@ -686,7 +686,7 @@ static void new_dio_interval(struct net_ { u32_t time; - time = 1 << instance->dio_interval_current; + time = BIT(instance->dio_interval_current); * Provide a single liner description at top using `///` comments. This one liner is displayed when using `--verbose` mode of coccicheck. * Specify Condidence level property adhering to coccinelle.rst section "Proposing new semantic patches". * Add virtual patch rule to handle the patch case when coccicheck is supplied with `--mode=patch` option. * Edit patch rule to remove redundant parentheses in the output. * Add `depends on !(file in "ext")` to ignore reports from `ext/` directory. Signed-off-by: Himanshu Jha --- scripts/coccinelle/unsigned_shift.cocci | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/coccinelle/unsigned_shift.cocci b/scripts/coccinelle/unsigned_shift.cocci index 07debb9d7b..159379ee8d 100644 --- a/scripts/coccinelle/unsigned_shift.cocci +++ b/scripts/coccinelle/unsigned_shift.cocci @@ -1,10 +1,15 @@ +/// Use BIT() helper macro instead of hardcoding using bitshifting +/// +// Confidence: High // Copyright (c) 2017 Intel Corporation // // SPDX-License-Identifier: Apache-2.0 -@@ -constant A; +virtual patch + +@depends on patch && !(file in "ext")@ +expression A; @@ -- 1 << A -+ BIT(A) \ No newline at end of file +- (1 << A) ++ BIT(A)