Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755055AbcCKGbf (ORCPT ); Fri, 11 Mar 2016 01:31:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55563 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754245AbcCKGb0 (ORCPT ); Fri, 11 Mar 2016 01:31:26 -0500 Message-Id: <20160311062953.571397512@redhat.com> User-Agent: quilt/0.64 Date: Fri, 11 Mar 2016 14:21:57 +0800 From: dyoung@redhat.com To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, d.hatayama@jp.fujitsu.com, bhe@redhat.com, vgoyal@redhat.com Cc: dyoung@redhat.com, kexec@lists.infradead.org Subject: [PATCH 1/2] [PATCH 1/2] Introduce new macros min_lt and max_lt for comparing with larger type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=0001-Introduce-new-macros-min_lt-and-max_lt-for-comparing.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1171 Lines: 35 A useful use case for min_t and max_t is comparing two values with larger type. For example comparing an u64 and an u32, usually we do not want to truncate the u64, so we need use min_t or max_t with u64. To simplify the usage introducing two more macros min_lt and max_lt, 'lt' means larger type. Signed-off-by: Dave Young --- include/linux/kernel.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- linux.orig/include/linux/kernel.h +++ linux/include/linux/kernel.h @@ -798,6 +798,19 @@ static inline void ftrace_dump(enum ftra type __max2 = (y); \ __max1 > __max2 ? __max1: __max2; }) +/* + * use type of larger size in min_lt and max_lt + */ +#define min_lt(x, y) ({ \ + int sx = sizeof(typeof(x)); \ + int sy = sizeof(typeof(y)); \ + sx > sy ? min_t(typeof(x), x, y) : min_t(typeof(y), x, y); }) + +#define max_lt(x, y) ({ \ + int sx = sizeof(typeof(x)); \ + int sy = sizeof(typeof(y)); \ + sx > sy ? max_t(typeof(x), x, y) : max_t(typeof(y), x, y); }) + /** * clamp_t - return a value clamped to a given range using a given type * @type: the type of variable to use