Skip to content

Commit

Permalink
highmem: mark k[un]map_atomic() with two arguments as deprecated
Browse files Browse the repository at this point in the history
For backward compatibility, we still keep the deprecated form,
and will warn the users if they still use the deprecated one, like this:

drivers/block/drbd/drbd_bitmap.c: In function ‘bm_page_io_async’:
drivers/block/drbd/drbd_bitmap.c:973:3: warning: ‘kmap_atomic_deprecated’ is deprecated (declared at /home/wangcong/linux-2.6/include/linux/highmem.h:124)
drivers/block/drbd/drbd_bitmap.c:977:3: warning: ‘kunmap_atomic_deprecated’ is deprecated (declared at /home/wangcong/linux-2.6/include/linux/highmem.h:144)

Thanks to Nick Bowler for the cpp trick!

Cc: Cesar Eduardo Barros <cesarb@cesarb.net>
Cc: Nick Bowler <nbowler@elliptictech.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Cong Wang <amwang@redhat.com>
  • Loading branch information
Cong Wang authored and Cong Wang committed Mar 20, 2012
1 parent c16fa4f commit 980c19e
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions include/linux/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,60 @@ static inline void kmap_atomic_idx_pop(void)
#endif

/*
* Make both: kmap_atomic(page, idx) and kmap_atomic(page) work.
* NOTE:
* kmap_atomic() and kunmap_atomic() with two arguments are deprecated.
* We only keep them for backward compatibility, any usage of them
* are now warned.
*/
#define kmap_atomic(page, args...) __kmap_atomic(page)

#define PASTE(a, b) a ## b
#define PASTE2(a, b) PASTE(a, b)

#define NARG_(_2, _1, n, ...) n
#define NARG(...) NARG_(__VA_ARGS__, 2, 1, :)

static inline void *kmap_atomic(struct page *page)
{
return __kmap_atomic(page);
}

static inline void __deprecated *kmap_atomic_deprecated(struct page *page,
enum km_type km)
{
return __kmap_atomic(page);
}

#define kmap_atomic1(...) kmap_atomic(__VA_ARGS__)
#define kmap_atomic2(...) kmap_atomic_deprecated(__VA_ARGS__)
#define kmap_atomic(...) PASTE2(kmap_atomic, NARG(__VA_ARGS__)(__VA_ARGS__))

static inline void __deprecated __kunmap_atomic_deprecated(void *addr,
enum km_type km)
{
__kunmap_atomic(addr);
}

/*
* Prevent people trying to call kunmap_atomic() as if it were kunmap()
* kunmap_atomic() should get the return value of kmap_atomic, not the page.
*/
#define kunmap_atomic(addr, args...) \
do { \
BUILD_BUG_ON(__same_type((addr), struct page *)); \
__kunmap_atomic(addr); \
#define kunmap_atomic_deprecated(addr, km) \
do { \
BUILD_BUG_ON(__same_type((addr), struct page *)); \
__kunmap_atomic_deprecated(addr, km); \
} while (0)

#define kunmap_atomic_withcheck(addr) \
do { \
BUILD_BUG_ON(__same_type((addr), struct page *)); \
__kunmap_atomic(addr); \
} while (0)

#define kunmap_atomic1(...) kunmap_atomic_withcheck(__VA_ARGS__)
#define kunmap_atomic2(...) kunmap_atomic_deprecated(__VA_ARGS__)
#define kunmap_atomic(...) PASTE2(kunmap_atomic, NARG(__VA_ARGS__)(__VA_ARGS__))
/**** End of C pre-processor tricks for deprecated macros ****/

/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
#ifndef clear_user_highpage
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
Expand Down

0 comments on commit 980c19e

Please sign in to comment.