Skip to content

Commit fcf865e

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: convert features and flags to __bitwise types
... and let sparse help us catch mismatches or abuses. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ec9b1cf commit fcf865e

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

block/blk-sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static ssize_t queue_dma_alignment_show(struct request_queue *q, char *page)
288288
}
289289

290290
static ssize_t queue_feature_store(struct request_queue *q, const char *page,
291-
size_t count, unsigned int feature)
291+
size_t count, blk_features_t feature)
292292
{
293293
struct queue_limits lim;
294294
unsigned long val;
@@ -418,7 +418,7 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
418418

419419
static ssize_t queue_poll_show(struct request_queue *q, char *page)
420420
{
421-
return queue_var_show(q->limits.features & BLK_FEAT_POLL, page);
421+
return queue_var_show(!!(q->limits.features & BLK_FEAT_POLL), page);
422422
}
423423

424424
static ssize_t queue_poll_store(struct request_queue *q, const char *page,
@@ -492,7 +492,7 @@ static ssize_t queue_fua_show(struct request_queue *q, char *page)
492492

493493
static ssize_t queue_dax_show(struct request_queue *q, char *page)
494494
{
495-
return queue_var_show(blk_queue_dax(q), page);
495+
return queue_var_show(!!blk_queue_dax(q), page);
496496
}
497497

498498
#define QUEUE_RO_ENTRY(_prefix, _name) \

include/linux/blkdev.h

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -283,55 +283,56 @@ static inline bool blk_op_is_passthrough(blk_opf_t op)
283283
}
284284

285285
/* flags set by the driver in queue_limits.features */
286-
enum {
287-
/* supports a volatile write cache */
288-
BLK_FEAT_WRITE_CACHE = (1u << 0),
286+
typedef unsigned int __bitwise blk_features_t;
289287

290-
/* supports passing on the FUA bit */
291-
BLK_FEAT_FUA = (1u << 1),
288+
/* supports a volatile write cache */
289+
#define BLK_FEAT_WRITE_CACHE ((__force blk_features_t)(1u << 0))
292290

293-
/* rotational device (hard drive or floppy) */
294-
BLK_FEAT_ROTATIONAL = (1u << 2),
291+
/* supports passing on the FUA bit */
292+
#define BLK_FEAT_FUA ((__force blk_features_t)(1u << 1))
295293

296-
/* contributes to the random number pool */
297-
BLK_FEAT_ADD_RANDOM = (1u << 3),
294+
/* rotational device (hard drive or floppy) */
295+
#define BLK_FEAT_ROTATIONAL ((__force blk_features_t)(1u << 2))
298296

299-
/* do disk/partitions IO accounting */
300-
BLK_FEAT_IO_STAT = (1u << 4),
297+
/* contributes to the random number pool */
298+
#define BLK_FEAT_ADD_RANDOM ((__force blk_features_t)(1u << 3))
301299

302-
/* don't modify data until writeback is done */
303-
BLK_FEAT_STABLE_WRITES = (1u << 5),
300+
/* do disk/partitions IO accounting */
301+
#define BLK_FEAT_IO_STAT ((__force blk_features_t)(1u << 4))
304302

305-
/* always completes in submit context */
306-
BLK_FEAT_SYNCHRONOUS = (1u << 6),
303+
/* don't modify data until writeback is done */
304+
#define BLK_FEAT_STABLE_WRITES ((__force blk_features_t)(1u << 5))
307305

308-
/* supports REQ_NOWAIT */
309-
BLK_FEAT_NOWAIT = (1u << 7),
306+
/* always completes in submit context */
307+
#define BLK_FEAT_SYNCHRONOUS ((__force blk_features_t)(1u << 6))
310308

311-
/* supports DAX */
312-
BLK_FEAT_DAX = (1u << 8),
309+
/* supports REQ_NOWAIT */
310+
#define BLK_FEAT_NOWAIT ((__force blk_features_t)(1u << 7))
313311

314-
/* supports I/O polling */
315-
BLK_FEAT_POLL = (1u << 9),
312+
/* supports DAX */
313+
#define BLK_FEAT_DAX ((__force blk_features_t)(1u << 8))
316314

317-
/* is a zoned device */
318-
BLK_FEAT_ZONED = (1u << 10),
315+
/* supports I/O polling */
316+
#define BLK_FEAT_POLL ((__force blk_features_t)(1u << 9))
319317

320-
/* supports Zone Reset All */
321-
BLK_FEAT_ZONE_RESETALL = (1u << 11),
318+
/* is a zoned device */
319+
#define BLK_FEAT_ZONED ((__force blk_features_t)(1u << 10))
322320

323-
/* supports PCI(e) p2p requests */
324-
BLK_FEAT_PCI_P2PDMA = (1u << 12),
321+
/* supports Zone Reset All */
322+
#define BLK_FEAT_ZONE_RESETALL ((__force blk_features_t)(1u << 11))
325323

326-
/* skip this queue in blk_mq_(un)quiesce_tagset */
327-
BLK_FEAT_SKIP_TAGSET_QUIESCE = (1u << 13),
324+
/* supports PCI(e) p2p requests */
325+
#define BLK_FEAT_PCI_P2PDMA ((__force blk_features_t)(1u << 12))
328326

329-
/* bounce all highmem pages */
330-
BLK_FEAT_BOUNCE_HIGH = (1u << 14),
327+
/* skip this queue in blk_mq_(un)quiesce_tagset */
328+
#define BLK_FEAT_SKIP_TAGSET_QUIESCE ((__force blk_features_t)(1u << 13))
331329

332-
/* undocumented magic for bcache */
333-
BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE = (1u << 15),
334-
};
330+
/* bounce all highmem pages */
331+
#define BLK_FEAT_BOUNCE_HIGH ((__force blk_features_t)(1u << 14))
332+
333+
/* undocumented magic for bcache */
334+
#define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \
335+
((__force blk_features_t)(1u << 15))
335336

336337
/*
337338
* Flags automatically inherited when stacking limits.
@@ -342,17 +343,17 @@ enum {
342343
BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE)
343344

344345
/* internal flags in queue_limits.flags */
345-
enum {
346-
/* do not send FLUSH/FUA commands despite advertising a write cache */
347-
BLK_FLAG_WRITE_CACHE_DISABLED = (1u << 0),
346+
typedef unsigned int __bitwise blk_flags_t;
348347

349-
/* I/O topology is misaligned */
350-
BLK_FLAG_MISALIGNED = (1u << 1),
351-
};
348+
/* do not send FLUSH/FUA commands despite advertising a write cache */
349+
#define BLK_FLAG_WRITE_CACHE_DISABLED ((__force blk_flags_t)(1u << 0))
350+
351+
/* I/O topology is misaligned */
352+
#define BLK_FLAG_MISALIGNED ((__force blk_flags_t)(1u << 1))
352353

353354
struct queue_limits {
354-
unsigned int features;
355-
unsigned int flags;
355+
blk_features_t features;
356+
blk_flags_t flags;
356357
unsigned long seg_boundary_mask;
357358
unsigned long virt_boundary_mask;
358359

0 commit comments

Comments
 (0)