Skip to content

Commit

Permalink
linux/kernel.h: Add ALIGN_DOWN macro
Browse files Browse the repository at this point in the history
Few parts of kernel define their own macro for aligning down so provide
a common define for this, with the same usage and assumptions as existing
ALIGN.

Convert also three existing implementations to this one.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
krzk authored and herbertx committed Apr 21, 2017
1 parent 7e207d8 commit ed067d4
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions arch/metag/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ static void tbi_boing_init(void)
}
#endif

#define ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))

/*
* Unwind the current stack frame and store the new register values in the
* structure passed as argument. Unwinding is equivalent to a function return,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/udl/udl_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct udl_fbdev {
};

#define DL_ALIGN_UP(x, a) ALIGN(x, a)
#define DL_ALIGN_DOWN(x, a) ALIGN(x-(a-1), a)
#define DL_ALIGN_DOWN(x, a) ALIGN_DOWN(x, a)

/** Read the red component (0..255) of a 32 bpp colour. */
#define DLO_RGB_GETRED(col) (uint8_t)((col) & 0xFF)
Expand Down
1 change: 1 addition & 0 deletions include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

/* @a is a power of 2 value */
#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
#define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a))
#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask))
#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
Expand Down
2 changes: 1 addition & 1 deletion include/video/udlfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ struct dlfb_data {

/* remove these once align.h patch is taken into kernel */
#define DL_ALIGN_UP(x, a) ALIGN(x, a)
#define DL_ALIGN_DOWN(x, a) ALIGN(x-(a-1), a)
#define DL_ALIGN_DOWN(x, a) ALIGN_DOWN(x, a)

#endif

0 comments on commit ed067d4

Please sign in to comment.