Skip to content

Commit e769779

Browse files
bvanasschebrauner
authored andcommitted
fs: Verify write lifetime constants at compile time
The code in fs/fcntl.c converts RWH_* constants to and from WRITE_LIFE_* constants using casts. Verify at compile time that these casts will yield the intended effect. Reviewed-by: Christoph Hellwig <hch@lst.de> Suggested-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240202203926.2478590-3-bvanassche@acm.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent ec16b14 commit e769779

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/fcntl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ static int f_getowner_uids(struct file *filp, unsigned long arg)
270270

271271
static bool rw_hint_valid(u64 hint)
272272
{
273+
BUILD_BUG_ON(WRITE_LIFE_NOT_SET != RWH_WRITE_LIFE_NOT_SET);
274+
BUILD_BUG_ON(WRITE_LIFE_NONE != RWH_WRITE_LIFE_NONE);
275+
BUILD_BUG_ON(WRITE_LIFE_SHORT != RWH_WRITE_LIFE_SHORT);
276+
BUILD_BUG_ON(WRITE_LIFE_MEDIUM != RWH_WRITE_LIFE_MEDIUM);
277+
BUILD_BUG_ON(WRITE_LIFE_LONG != RWH_WRITE_LIFE_LONG);
278+
BUILD_BUG_ON(WRITE_LIFE_EXTREME != RWH_WRITE_LIFE_EXTREME);
279+
273280
switch (hint) {
274281
case RWH_WRITE_LIFE_NOT_SET:
275282
case RWH_WRITE_LIFE_NONE:

0 commit comments

Comments
 (0)