* [PATCH 0/2] Staging: android: Redefine macros as static inline functions
@ 2016-03-11 14:03 Bhumika Goyal
2016-03-11 14:03 ` [PATCH 1/2] Staging: android: ashmem.c: " Bhumika Goyal
2016-03-11 14:03 ` [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function Bhumika Goyal
0 siblings, 2 replies; 4+ messages in thread
From: Bhumika Goyal @ 2016-03-11 14:03 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal
Convert macros page_in_range, range_before_page,
page_range_{subsumes/subsumed_by/in}_rang into static inline functions
as static inline functions are preferred over macros. The
change can be done as the arguments at all call sites have the same type.
Bhumika Goyal (2):
Staging: android: ashmem.c: Redefine macros as static inline functions
Staging: android: ashmem.c: Convert macros
page_range_{subsumes/subsumed_by/in}_range to static inline
function
drivers/staging/android/ashmem.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] Staging: android: ashmem.c: Redefine macros as static inline functions 2016-03-11 14:03 [PATCH 0/2] Staging: android: Redefine macros as static inline functions Bhumika Goyal @ 2016-03-11 14:03 ` Bhumika Goyal 2016-03-11 14:03 ` [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function Bhumika Goyal 1 sibling, 0 replies; 4+ messages in thread From: Bhumika Goyal @ 2016-03-11 14:03 UTC (permalink / raw) To: outreachy-kernel; +Cc: Bhumika Goyal Convert macros page_in_range and range_before_page into static inline functions as static inline functions are preferred over macros. The change can be done as the arguments at all call sites have the same type. Also, both the macros have same type of arguments and return values. Done using coccinelle: @r@ identifier f; expression e; @@ #define f(...) e @r1@ identifier r.f; identifier range,page; expression r.e; @@ - #define f(range,page) e + static inline int f(struct ashmem_range *range, size_t page) + { + return e; + } Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> --- drivers/staging/android/ashmem.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 8ae1308..d3e884e 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -112,15 +112,19 @@ static struct kmem_cache *ashmem_range_cachep __read_mostly; #define page_range_subsumed_by_range(range, start, end) \ (((range)->pgstart <= (start)) && ((range)->pgend >= (end))) -#define page_in_range(range, page) \ - (((range)->pgstart <= (page)) && ((range)->pgend >= (page))) +static inline int page_in_range(struct ashmem_range *range, size_t page) +{ + return (((range)->pgstart <= (page)) && ((range)->pgend >= (page))); +} #define page_range_in_range(range, start, end) \ (page_in_range(range, start) || page_in_range(range, end) || \ page_range_subsumes_range(range, start, end)) -#define range_before_page(range, page) \ - ((range)->pgend < (page)) +static inline int range_before_page(struct ashmem_range *range, size_t page) +{ + return ((range)->pgend < (page)); +} #define PROT_MASK (PROT_EXEC | PROT_READ | PROT_WRITE) -- 1.9.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function 2016-03-11 14:03 [PATCH 0/2] Staging: android: Redefine macros as static inline functions Bhumika Goyal 2016-03-11 14:03 ` [PATCH 1/2] Staging: android: ashmem.c: " Bhumika Goyal @ 2016-03-11 14:03 ` Bhumika Goyal 2016-03-12 12:55 ` [Outreachy kernel] " Julia Lawall 1 sibling, 1 reply; 4+ messages in thread From: Bhumika Goyal @ 2016-03-11 14:03 UTC (permalink / raw) To: outreachy-kernel; +Cc: Bhumika Goyal Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function as static inline functions are preferred over macros. The change can be done as the arguments at all call sites have the same type. Also, all three macro have same type of arguments and return values so they can converted using a common semantic patch. @r@ identifier f; expression e; @@ #define f(...) e @r2@ identifier r.f; identifier range,start,end; expression r.e; @@ - #define f(range,start,end) e + static inline int f(struct ashmem_range *range, size_t start, size_t end) +{ + return e; +} Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> --- drivers/staging/android/ashmem.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index d3e884e..0a592d0 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -106,20 +106,29 @@ static struct kmem_cache *ashmem_range_cachep __read_mostly; #define range_on_lru(range) \ ((range)->purged == ASHMEM_NOT_PURGED) -#define page_range_subsumes_range(range, start, end) \ - (((range)->pgstart >= (start)) && ((range)->pgend <= (end))) +static inline int page_range_subsumes_range(struct ashmem_range *range, + size_t start, size_t end) +{ + return (((range)->pgstart >= (start)) && ((range)->pgend <= (end))); +} -#define page_range_subsumed_by_range(range, start, end) \ - (((range)->pgstart <= (start)) && ((range)->pgend >= (end))) +static inline int page_range_subsumed_by_range(struct ashmem_range *range, + size_t start, size_t end) +{ + return (((range)->pgstart <= (start)) && ((range)->pgend >= (end))); +} static inline int page_in_range(struct ashmem_range *range, size_t page) { return (((range)->pgstart <= (page)) && ((range)->pgend >= (page))); } -#define page_range_in_range(range, start, end) \ - (page_in_range(range, start) || page_in_range(range, end) || \ - page_range_subsumes_range(range, start, end)) +static inline int page_range_in_range(struct ashmem_range *range, + size_t start, size_t end) +{ + return (page_in_range(range, start) || page_in_range(range, end) || + page_range_subsumes_range(range, start, end)); +} static inline int range_before_page(struct ashmem_range *range, size_t page) { -- 1.9.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Outreachy kernel] [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function 2016-03-11 14:03 ` [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function Bhumika Goyal @ 2016-03-12 12:55 ` Julia Lawall 0 siblings, 0 replies; 4+ messages in thread From: Julia Lawall @ 2016-03-12 12:55 UTC (permalink / raw) To: Bhumika Goyal; +Cc: outreachy-kernel On Fri, 11 Mar 2016, Bhumika Goyal wrote: > Convert macros page_range_{subsumes/subsumed_by/in}_range to static > inline function as static inline functions are preferred over macros. > The change can be done as the arguments at all call sites have the same > type. Also, all three macro have same type of arguments and return > values so they can converted using a common semantic patch. > > @r@ > identifier f; > expression e; > @@ > #define f(...) e I don't see the point of this rule. The described strategy in the challenge problem was to have Coccinelle check the type properties of the actual arguments to the macro, but you have done that part by hand. julia > > @r2@ > identifier r.f; > identifier range,start,end; > expression r.e; > @@ > - #define f(range,start,end) e > + static inline int f(struct ashmem_range *range, size_t start, size_t end) > +{ > + return e; > +} > > Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> > --- > drivers/staging/android/ashmem.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c > index d3e884e..0a592d0 100644 > --- a/drivers/staging/android/ashmem.c > +++ b/drivers/staging/android/ashmem.c > @@ -106,20 +106,29 @@ static struct kmem_cache *ashmem_range_cachep __read_mostly; > #define range_on_lru(range) \ > ((range)->purged == ASHMEM_NOT_PURGED) > > -#define page_range_subsumes_range(range, start, end) \ > - (((range)->pgstart >= (start)) && ((range)->pgend <= (end))) > +static inline int page_range_subsumes_range(struct ashmem_range *range, > + size_t start, size_t end) > +{ > + return (((range)->pgstart >= (start)) && ((range)->pgend <= (end))); > +} > > -#define page_range_subsumed_by_range(range, start, end) \ > - (((range)->pgstart <= (start)) && ((range)->pgend >= (end))) > +static inline int page_range_subsumed_by_range(struct ashmem_range *range, > + size_t start, size_t end) > +{ > + return (((range)->pgstart <= (start)) && ((range)->pgend >= (end))); > +} > > static inline int page_in_range(struct ashmem_range *range, size_t page) > { > return (((range)->pgstart <= (page)) && ((range)->pgend >= (page))); > } > > -#define page_range_in_range(range, start, end) \ > - (page_in_range(range, start) || page_in_range(range, end) || \ > - page_range_subsumes_range(range, start, end)) > +static inline int page_range_in_range(struct ashmem_range *range, > + size_t start, size_t end) > +{ > + return (page_in_range(range, start) || page_in_range(range, end) || > + page_range_subsumes_range(range, start, end)); > +} > > static inline int range_before_page(struct ashmem_range *range, size_t page) > { > -- > 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 outreachy-kernel+unsubscribe@googlegroups.com. > To post to this group, send email to outreachy-kernel@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/8743d5b317759576c30c8ea05a04c537aec7234b.1457703530.git.bhumirks%40gmail.com. > For more options, visit https://groups.google.com/d/optout. > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-12 12:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-11 14:03 [PATCH 0/2] Staging: android: Redefine macros as static inline functions Bhumika Goyal
2016-03-11 14:03 ` [PATCH 1/2] Staging: android: ashmem.c: " Bhumika Goyal
2016-03-11 14:03 ` [PATCH 2/2] Staging: android: ashmem.c: Convert macros page_range_{subsumes/subsumed_by/in}_range to static inline function Bhumika Goyal
2016-03-12 12:55 ` [Outreachy kernel] " Julia Lawall
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.