lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 10 Mar 2015 11:27:12 -0700
From:	Joe Perches <joe@...ches.com>
To:	Bartosz Golaszewski <bgolaszewski@...libre.com>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Guenter Roeck <linux@...ck-us.net>,
	lm-sensors <lm-sensors@...sensors.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Steven Rostedt <srostedt@...hat.com>
Subject: Re: [PATCH v2 1/4] kernel.h: add find_closest() macro

On Tue, 2015-03-10 at 18:27 +0100, Bartosz Golaszewski wrote:
> Searching for the member of an array closest to 'x' is
> duplicated in several places.
[]
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
[]
> @@ -116,6 +116,29 @@
>  }							\
>  )
>  
> +#define __find_closest(x, a, as, op)(					\
> +{									\
> +	typeof(as) _i, _as = (as) - 1;						\
> +	typeof(x) _x = (x);						\
> +	typeof(*a) *_a = (a);						\
> +	for (_i = 0; _i < _as; _i++) {					\
> +		if (_x op DIV_ROUND_CLOSEST(_a[_i] + _a[_i + 1], 2))	\
> +			break;						\
> +	}								\
> +	(_i);								\
> +}									\
> +)

Please use more descriptive variable names.

Most kernel statement expression macros consolidate
the "({" and "})" uses on single lines

#define sem(args) {(		\
	etc...			\
)}

> +
> +/*
> + * Given an array 'a' (sorted in ascending order) of size 'as' return
> + * the index of the element in that array closest to 'x'.
> + */

It'd be nice to use kernel-doc comments here.

> +#define find_closest(x, a, as) __find_closest(x, a, as, <=)
> +/*
> + * Similar to find_closest(), but 'a' is expected to be sorted
> + * in descending order.
> + */

And here.

> +#define find_closest_desc(x, a, as) __find_closest(x, a, as, >)

Shouldn't find_closest and find_closest_dest use
equivalent comparison?

>= ?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ