Skip to content

Commit c8bf133

Browse files
martinkpetersenJens Axboe
authored andcommitted
Consolidate min_not_zero
We have several users of min_not_zero, each of them using their own definition. Move the define to kernel.h. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Jens Axboe <axboe@carl.home.kernel.dk>
1 parent 76be97c commit c8bf133

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

block/blk-settings.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,6 @@ void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
455455
}
456456
EXPORT_SYMBOL(blk_queue_io_opt);
457457

458-
/*
459-
* Returns the minimum that is _not_ zero, unless both are zero.
460-
*/
461-
#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
462-
463458
/**
464459
* blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
465460
* @t: the stacking driver (top)

drivers/block/drbd/drbd_receiver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,6 @@ static int receive_sizes(struct drbd_conf *mdev, struct p_header *h)
29722972
* we still need to figure out whether we accept that. */
29732973
mdev->p_size = p_size;
29742974

2975-
#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
29762975
if (get_ldev(mdev)) {
29772976
warn_if_differ_considerably(mdev, "lower level device sizes",
29782977
p_size, drbd_get_max_capacity(mdev->ldev));

drivers/md/dm-snap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,6 @@ static int dm_add_exception(void *context, chunk_t old, chunk_t new)
706706
return 0;
707707
}
708708

709-
#define min_not_zero(l, r) (((l) == 0) ? (r) : (((r) == 0) ? (l) : min(l, r)))
710-
711709
/*
712710
* Return a minimum chunk size of all snapshots that have the specified origin.
713711
* Return zero if the origin has no snapshots.

drivers/md/dm-table.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
486486
return 0;
487487
}
488488

489-
/*
490-
* Returns the minimum that is _not_ zero, unless both are zero.
491-
*/
492-
#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
493-
494489
int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
495490
sector_t start, sector_t len, void *data)
496491
{

include/linux/kernel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,16 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
640640
(void) (&_max1 == &_max2); \
641641
_max1 > _max2 ? _max1 : _max2; })
642642

643+
/**
644+
* min_not_zero - return the minimum that is _not_ zero, unless both are zero
645+
* @x: value1
646+
* @y: value2
647+
*/
648+
#define min_not_zero(x, y) ({ \
649+
typeof(x) __x = (x); \
650+
typeof(y) __y = (y); \
651+
__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
652+
643653
/**
644654
* clamp - return a value clamped to a given range with strict typechecking
645655
* @val: current value

0 commit comments

Comments
 (0)