android_kernel_oneplus_msm8998/drivers/iio
Michal Nazarewicz df12772578 include/linux/kernel.h: change abs() macro so it uses consistent return type
commit 8f57e4d930d48217268315898212518d4d3e0773 upstream.

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>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-09-30 10:18:33 +02:00
..
accel iio: accel: kxsd9: Fix scaling bug 2016-09-24 10:07:38 +02:00
adc iio: adc: at91: unbreak channel adc channel 3 2016-09-24 10:07:38 +02:00
amplifiers spi: Updates for v4.4 2015-11-05 13:15:12 -08:00
buffer iio: Move generic buffer implementations to sub-directory 2015-08-16 10:51:21 +01:00
chemical iio: chemical: vz89x hardware i2c workaround 2015-09-30 18:20:53 +01:00
common iio: fix pressure data output unit in hid-sensor-attributes 2016-09-24 10:07:38 +02:00
dac iio: dac: mcp4725: set iio name property in sysfs 2016-02-25 12:01:17 -08:00
frequency spi: Updates for v4.4 2015-11-05 13:15:12 -08:00
gyro iio: gyro: bmg160: fix endianness when reading axes 2016-04-20 15:42:12 +09:00
humidity iio: hudmidity: hdc100x: fix incorrect shifting and scaling 2016-07-27 09:47:36 -07:00
imu iio: adis_buffer: Fix out-of-bounds memory access 2016-02-25 12:01:17 -08:00
light iio: light apds9960: Add the missing dev.parent 2016-07-27 09:47:36 -07:00
magnetometer iio: ak8975: fix maybe-uninitialized warning 2016-05-11 11:21:23 +02:00
orientation
potentiometer iio: mcp4531: Driver for Microchip digital potentiometers 2015-09-30 18:20:53 +01:00
pressure iio:st_pressure: fix sampling gains (bring inline with ABI) 2016-07-27 09:47:36 -07:00
proximity iio: proximity: as3935: set up buffer timestamps for non-zero values 2016-09-24 10:07:37 +02:00
temperature Add tsys02d meas-spec driver support 2015-10-11 10:21:19 +01:00
trigger
iio_core.h
iio_core_trigger.h
industrialio-buffer.c iio: ensure ret is initialized to zero before entering do loop 2016-09-24 10:07:38 +02:00
industrialio-core.c include/linux/kernel.h: change abs() macro so it uses consistent return type 2016-09-30 10:18:33 +02:00
industrialio-event.c iio: event: Remove negative error code from iio_event_poll 2015-08-12 19:26:39 +01:00
industrialio-trigger.c iio: Fix error handling in iio_trigger_attach_poll_func 2016-07-27 09:47:36 -07:00
industrialio-triggered-event.c iio: Support triggered events 2015-08-27 20:47:09 +01:00
inkern.c iio: inkern: fix a NULL dereference on error 2016-02-25 12:01:17 -08:00
Kconfig iio: mcp4531: Driver for Microchip digital potentiometers 2015-09-30 18:20:53 +01:00
Makefile iio: mcp4531: Driver for Microchip digital potentiometers 2015-09-30 18:20:53 +01:00