linux/drivers/net/wireless/intel/iwlwifi
Michal Nazarewicz 8f57e4d930 include/linux/kernel.h: change abs() macro so it uses consistent return type
Rewrite abs() so that its return type does not depend on the
architecture and no unexpected type conversion happen inside of it.  The
only conversion is from unsigned to signed type.  char is left as a
return type but treated as a signed type regradless of it's actual
signedness.

With the old version, int arguments were promoted to long and depending
on architecture a long argument might result in s64 or long return type
(which may or may not be the same).

This came after some back and forth with Nicolas.  The current macro has
different return type (for the same input type) depending on
architecture which might be midly iritating.

An alternative version would promote to int like so:

	#define abs(x)	__abs_choose_expr(x, long long,			\
			__abs_choose_expr(x, long,			\
			__builtin_choose_expr(				\
				sizeof(x) <= sizeof(int),		\
				({ int __x = (x); __x<0?-__x:__x; }),	\
				((void)0))))

I have no preference but imagine Linus might.  :] Nicolas argument against
is that promoting to int causes iconsistent behaviour:

	int main(void) {
		unsigned short a = 0, b = 1, c = a - b;
		unsigned short d = abs(a - b);
		unsigned short e = abs(c);
		printf("%u %u\n", d, e);  // prints: 1 65535
	}

Then again, no sane person expects consistent behaviour from C integer
arithmetic.  ;)

Note:

  __builtin_types_compatible_p(unsigned char, char) is always false, and
  __builtin_types_compatible_p(signed char, char) is also always false.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: Nicolas Pitre <nico@linaro.org>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-01-16 11:17:22 -08:00
..
dvm include/linux/kernel.h: change abs() macro so it uses consistent return type 2016-01-16 11:17:22 -08:00
mvm iwlwifi: mvm: fix memory leaks in error paths upon fw error dump 2016-01-07 19:01:32 +02:00
pcie iwlwifi: pcie: properly configure the debug buffer size for 8000 2016-01-07 19:01:33 +02:00
Kconfig
Makefile
iwl-1000.c
iwl-2000.c
iwl-5000.c
iwl-6000.c
iwl-7000.c iwlwifi: mvm: bump max API to 20 2016-01-07 19:01:26 +02:00
iwl-8000.c iwlwifi: mvm: bump max API to 20 2016-01-07 19:01:26 +02:00
iwl-9000.c iwlwifi: mvm: bump max API to 20 2016-01-07 19:01:26 +02:00
iwl-agn-hw.h
iwl-config.h
iwl-csr.h
iwl-debug.c
iwl-debug.h
iwl-devtrace-data.h iwlwifi: pcie: build an A-MSDU using TSO core 2015-12-20 23:27:37 +02:00
iwl-devtrace-io.h
iwl-devtrace-iwlwifi.h
iwl-devtrace-msg.h
iwl-devtrace-ucode.h
iwl-devtrace.c
iwl-devtrace.h
iwl-drv.c
iwl-drv.h
iwl-eeprom-parse.c iwlwifi: fix printf specifier 2015-12-21 10:12:08 +02:00
iwl-eeprom-parse.h
iwl-eeprom-read.c
iwl-eeprom-read.h
iwl-fh.h
iwl-fw-error-dump.h iwlwifi: mvm: dump the radio registers when the firmware crashes 2016-01-07 19:01:28 +02:00
iwl-fw-file.h iwlwifi: mvm: add a non-trigger window to fw dbg triggers 2016-01-07 19:01:28 +02:00
iwl-fw.h
iwl-io.c iwlwifi: remove unused parameter from grab_nic_access 2015-12-21 10:11:39 +02:00
iwl-io.h
iwl-modparams.h
iwl-notif-wait.c
iwl-notif-wait.h
iwl-nvm-parse.c
iwl-nvm-parse.h
iwl-op-mode.h
iwl-phy-db.c
iwl-phy-db.h
iwl-prph.h iwlwifi: mvm: dump the radio registers when the firmware crashes 2016-01-07 19:01:28 +02:00
iwl-scd.h
iwl-trans.c
iwl-trans.h iwlwifi: mvm: constify the parameters of a few functions in fw-dbg.c 2016-01-07 19:01:32 +02:00