akaros/scripts/spatch/linux/funcs.cocci
<<
>>
Prefs
   1@@
   2expression T;
   3@@
   4-msleep(T);
   5+kthread_usleep(1000 * T);
   6
   7@@
   8expression TMIN;
   9expression TMAX;
  10@@
  11-usleep_range(TMIN, TMAX);
  12+kthread_usleep(TMIN);
  13
  14// barriers
  15@@
  16@@
  17-barrier();
  18+cmb();
  19
  20@@
  21@@
  22-smp_mb();
  23+mb();
  24
  25@@
  26@@
  27-smp_rmb();
  28+rmb();
  29
  30@@
  31@@
  32-smp_wmb();
  33+wmb();
  34
  35@@
  36expression A0;
  37expression A1;
  38@@
  39-min(A0, A1)
  40+MIN(A0, A1)
  41
  42@@
  43expression A0;
  44expression A1;
  45@@
  46-max(A0, A1)
  47+MAX(A0, A1)
  48
  49@@
  50expression LO;
  51expression HI;
  52expression V;
  53@@
  54-clamp(V, LO, HI)
  55+CLAMP(V, LO, HI)
  56
  57@@
  58expression A0;
  59expression A1;
  60type T;
  61@@
  62-min_t(T, A0, A1)
  63+MIN_T(T, A0, A1)
  64
  65@@
  66expression A0;
  67expression A1;
  68type T;
  69@@
  70-max_t(T, A0, A1)
  71+MAX_T(T, A0, A1)
  72
  73@@
  74expression LO;
  75expression HI;
  76expression V;
  77type T;
  78@@
  79-clamp_t(T, V, LO, HI)
  80+CLAMP_T(T, V, LO, HI)
  81
  82
  83// locking
  84// being conservative: they might not need irqsave
  85@@
  86expression E;
  87@@
  88-spin_lock_init(E)
  89+spinlock_init_irqsave(E)
  90
  91@@
  92expression E;
  93@@
  94-spin_lock_bh(E)
  95+spin_lock(E)
  96
  97@@
  98expression E;
  99@@
 100-spin_unlock_bh(E)
 101+spin_unlock(E)
 102@@
 103
 104expression E;
 105@@
 106-spin_lock_irq(E)
 107+spin_lock_irqsave(E)
 108
 109@@
 110expression E;
 111@@
 112-spin_unlock_irq(E)
 113+spin_unlock_irqsave(E)
 114
 115@@
 116expression lock, flags;
 117@@
 118-spin_lock_irqsave(lock, flags)
 119+spin_lock_irqsave(lock)
 120...
 121-spin_unlock_irqrestore(lock, flags)
 122+spin_unlock_irqsave(lock)
 123
 124@@
 125typedef raw_spinlock_t;
 126typedef spinlock_t;
 127@@
 128-raw_spinlock_t
 129+spinlock_t
 130
 131@@
 132expression E;
 133@@
 134-raw_spin_lock_init(E)
 135+spinlock_init_irqsave(E)
 136
 137@@
 138expression E;
 139@@
 140-raw_spin_lock(E)
 141+spin_lock_irqsave(E)
 142
 143@@
 144expression E;
 145@@
 146-raw_spin_unlock(E)
 147+spin_unlock_irqsave(E)
 148
 149@@
 150expression lock, flags;
 151@@
 152-raw_spin_lock_irqsave(lock, flags)
 153+spin_lock_irqsave(lock)
 154...
 155-raw_spin_unlock_irqrestore(lock, flags)
 156+spin_unlock_irqsave(lock)
 157
 158@@
 159expression E;
 160@@
 161-ilog2(E)
 162+LOG2_UP(E)
 163
 164@@
 165expression E;
 166@@
 167-roundup_pow_of_two(E)
 168+ROUNDUPPWR2(E)
 169
 170@@
 171expression E;
 172@@
 173-rounddown_pow_of_two(E)
 174+ROUNDDOWNPWR2(E)
 175
 176@@
 177expression E;
 178@@
 179-is_power_of_2(E)
 180+IS_PWR2(E)
 181
 182@@
 183expression DST;
 184expression SRC;
 185expression LEN;
 186@@
 187-copy_from_user(DST, SRC, LEN)
 188+memcpy_from_user(current, DST, SRC, LEN)
 189
 190@@
 191expression DST;
 192expression SRC;
 193expression LEN;
 194@@
 195-copy_to_user(DST, SRC, LEN)
 196+memcpy_to_user(current, DST, SRC, LEN)
 197
 198@@
 199@@
 200-ktime_get_real()
 201+epoch_nsec()
 202
 203@@
 204expression E;
 205@@
 206-ktime_to_ns(E)
 207+E
 208
 209@@
 210expression E;
 211@@
 212-htonl(E)
 213+cpu_to_be32(E)
 214
 215@@
 216expression E;
 217@@
 218-htons(E)
 219+cpu_to_be16(E)
 220
 221@@
 222expression E;
 223@@
 224-ntohl(E)
 225+be32_to_cpu(E)
 226
 227@@
 228expression E;
 229@@
 230-ntohs(E)
 231+be16_to_cpu(E)
 232
 233@@
 234@@
 235-smp_processor_id()
 236+core_id()
 237
 238// This is a little half-assed.  Any fix will need to be manually edited to
 239// provide a pointer to the pci device.  And you'll need to fix your handler to
 240// be the correct type.
 241@@
 242expression IRQ;
 243expression HANDLER;
 244expression FLAGS;
 245expression NAME;
 246expression ARG;
 247@@
 248-request_irq(IRQ, HANDLER, FLAGS, NAME, ARG)
 249+register_irq(IRQ, HANDLER, ARG, pci_to_tbdf(PCIDEV))
 250
 251// There are 3 return types for the irq handlers, IRQ_NONE, IRQ_HANDLED, and
 252// IRQ_WAKE_THREAD.  We can change the first two to just return.  The latter
 253// will need manual attention, since they want a thread to handle the rest.
 254@@
 255identifier HANDLER;
 256typedef irqreturn_t;
 257@@
 258irqreturn_t HANDLER(...) {
 259<...
 260-return IRQ_NONE;
 261+return;
 262...>
 263}
 264
 265// Need to comment out irqreturn_t, I guess because it's in a previous rule
 266@@
 267identifier HANDLER;
 268//typedef irqreturn_t;
 269@@
 270irqreturn_t HANDLER(...) {
 271<...
 272-return IRQ_HANDLED;
 273+return;
 274...>
 275}
 276
 277// There should be a way to catch both decl and def at once...
 278// Changes the definition
 279@@
 280identifier HANDLER;
 281//typedef irqreturn_t;
 282identifier IRQ;
 283identifier ARG;
 284@@
 285-irqreturn_t HANDLER(int IRQ, void *ARG
 286+void HANDLER(struct hw_trapframe *hw_tf, void *ARG
 287 ) { ... }
 288
 289// Changes the declaration
 290@@
 291identifier HANDLER;
 292//typedef irqreturn_t;
 293identifier IRQ;
 294identifier ARG;
 295@@
 296-irqreturn_t HANDLER(int IRQ, void *ARG
 297+void HANDLER(struct hw_trapframe *hw_tf, void *ARG
 298 );
 299
 300@@
 301expression VAL;
 302expression UP;
 303@@
 304-roundup(VAL, UP)
 305+ROUNDUP(VAL, UP)
 306
 307@@
 308expression VAL;
 309expression DOWN;
 310@@
 311-rounddown(VAL, DOWN)
 312+ROUNDDOWN(VAL, DOWN)
 313
 314@@
 315expression STMT;
 316@@
 317-BUG_ON(STMT)
 318+assert(!(STMT))
 319
 320@@
 321expression STMT;
 322@@
 323-BUILD_BUG_ON(STMT)
 324+static_assert(!(STMT))
 325
 326@@
 327@@
 328-BUG()
 329+panic("BUG")
 330
 331@@
 332@@
 333-WARN_ON
 334+warn_on
 335
 336@@
 337@@
 338-WARN_ON_ONCE
 339+warn_on_once
 340
 341@@
 342expression P;
 343@@
 344-pci_set_master(P)
 345+pci_set_bus_master(P)
 346
 347@@
 348expression P;
 349@@
 350-pci_clear_master(P)
 351+pci_clr_bus_master(P)
 352