Convert Macro into static inline function
v2 cover Convert Macro into static inline function
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
This check is done via following coccinelle script.
Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []
@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_inc(es,e,...);
@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)
@finalize:python@
@@
possible = True
for t in list:
if t != list[0]:
possible = False
if possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'
Somya Anand (2):
Staging: lustre: Convert macro class_export_rpc_inc into static inline
function
Staging: lustre: Convert macro class_export_rpc_dec into static inline
function
drivers/staging/lustre/lustre/include/obd_class.h | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/2 Staging: lustre: Convert macro class_export_rpc_inc into static inline function
This patch converts the macro class_export_rpc_inc into static inline function. This is possible because the types of arguments at all the call sites are same. So, the type of parameter is compatible with the types of the arguments at all of the call sites.
---
Changes since v1:
* Reword the commit message.
drivers/staging/lustre/lustre/include/obd_class.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +6 -6
@@ -222,12 +222,12 @@ extern void (*class_export_dump_hook)(struct obd_export *);#endif -#define class_export_rpc_inc (exp) \ -({ \ - atomic_inc(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_inc (struct obd_export *exp) +{ +atomic_inc (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC GETting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_rpc_dec (exp) \ ({ \
Signature · 1 line
1.9.1
PATCH v2 2/2 Staging: lustre: Convert macro class_export_rpc_dec into static inline function
In reply to Somya AnandThis patch converts the macro class_export_rpc_dec into static inline function. This is possible because the types of arguments at all the call sites are same. So, the type of parameter is compatible with the types of the arguments at all of the call sites.
---
Changes since v1:
* Reword the commit message.
drivers/staging/lustre/lustre/include/obd_class.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +7 -7
@@ -229,13 +229,13 @@ static inline void class_export_rpc_inc(struct obd_export *exp) (exp), atomic_read(&(exp)->exp_rpc_count)); } -#define class_export_rpc_dec (exp) \ -({ \ - LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \ - atomic_dec(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_dec (struct obd_export *exp) +{ +LASSERT_ATOMIC_POS (&exp->exp_rpc_count); +atomic_dec (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC PUTting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_lock_get (exp, lock) \ ({ \
Signature · 1 line
1.9.1
Looks better. Thanks.
julia
Quoted 61 lines · Somya Anand
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
This check is done via following coccinelle script.
Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_inc(es,e,...);@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)@finalize:python@
@@
possible = True
for t in list:
if t != list[0]:
possible = Falseif possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'Somya Anand (2):
Staging: lustre: Convert macroclass_export_rpc_incinto static inline
function
Staging: lustre: Convert macroclass_export_rpc_decinto static inline
functiondrivers/staging/lustre/lustre/include/obd_class.h | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-)Signature · 8 lines
1.9.1 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1426942225-7634-1-git-send-email-somyaanand214%40gmail.com. For more options, visit https://groups.google.com/d/optout.