On Sun, Mar 17, 2019 at 12:11:14PM +0200, Leon Romanovsky wrote: > From: Leon Romanovsky <leonro@xxxxxxxxxxxx> > > Attempt to use check_shl_overflow() with inputs of unsigned type > produces the following compilation warnings. > > drivers/infiniband/hw/mlx5/qp.c: In function _set_user_rq_size_: > ./include/linux/overflow.h:230:6: warning: comparison of unsigned > expression >= 0 is always true [-Wtype-limits] > _s >= 0 && _s < 8 * sizeof(*d) ? _s : 0; \ > ^~ > drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ > if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, > &rwq->buf_size)) > ^~~~~~~~~~~~~~~~~~ > ./include/linux/overflow.h:232:26: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] > (_to_shift != _s || *_d < 0 || _a < 0 || \ > ^ > drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ > if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) > ^~~~~~~~~~~~~~~~~~ > ./include/linux/overflow.h:232:36: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] > (_to_shift != _s || *_d < 0 || _a < 0 || \ > ^ > drivers/infiniband/hw/mlx5/qp.c:5820:6: note: in expansion of macro _check_shl_overflow_ > if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift,&rwq->buf_size)) > ^~~~~~~~~~~~~~~~~~ > > Fixes: 0c66847793d1 ("overflow.h: Add arithmetic shift helper") > Reviewed-by: Bart Van Assche <bvanassche@xxxxxxx> > Acked-by: Kees Cook <keescook@xxxxxxxxxxxx> > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> > --- > Changelog: > v2->v3: > * Change _s to be is_non_negative() too. > v1->v2: > * Added Bart's and Kees's tags > * Added is_negative()/is_non_negative() macro as Rasmus suggested > v0->v1: > * Fixed wrong checks > --- > include/linux/overflow.h | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) Applied to for-next Thanks, Jason