>   Does coccinelle need driver to be compiled as a module? As hdm_dim2 driver
> is not but sm750fb driver is compiled as a module. Does coccinelle require
> executable file to work?

No, it just looks at the source code.  It doesn't care about modules, etc.
   
    Then it is strange, as I tried again with different drivers, few of them work and few others don't.
   
    Drivers compiled as module and got output : iio and sm750fb
    Drivers not compiled as module but still got output: lustre and greybus
    Drivers not compiled as module and no output: most (all drivers) and netlogic


Could you try the original experiment again?  Maybe the problem is somehow
resolved.

    Same output.
   
   spatch --sp-file ret.cocci --no-includes  ~/git/kernels/staging/drivers/staging/most/hdm-dim2/dim2_sysfs.c  > ret.out
   init_defs_builtins: /usr/lib64/coccinelle/standard.h
   HANDLING:
   /home/varsha/git/kernels/staging/drivers/staging/most/hdm-dim2/dim2_sysfs.c

   Thanks,
   Varsha