hwmon: (abituguru) Fix checkpatch issues

Fixed:
ERROR: do not use assignment in if condition
ERROR: else should follow close brace '}'
ERROR: switch and case should be at the same indent
WARNING: simple_strtoul is obsolete, use kstrtoul instead

Modify multi-line comments to follow Documentation/CodingStyle.

Not fixed:
WARNING: msleep < 20ms can sleep for up to 20ms

Cc: Hans de Goede <9fa1be1a5b5729e4c6b404f34c9ce49ff4882fd8@redhat.com>
Signed-off-by: Guenter Roeck <ba324ca7b1c77fc20bb970d5aff6eea9377918a5@roeck-us.net>

--- drivers/hwmon/abituguru.c
+++ drivers/hwmon/abituguru.c
@@ -1,25 +1,25 @@
 /*
-    abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-/*
-    This driver supports the sensor part of the first and second revision of
-    the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because
-    of lack of specs the CPU/RAM voltage & frequency control is not supported!
-*/
+ * abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * This driver supports the sensor part of the first and second revision of
+ * the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because
+ * of lack of specs the CPU/RAM voltage & frequency control is not supported!
+ */

 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

@@ -44,8 +44,10 @@
 #define ABIT_UGURU_SENSOR_BANK2			0x26 /* fans */
 /* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */
 #define ABIT_UGURU_MAX_BANK1_SENSORS		16
-/* Warning if you increase one of the 2 MAX defines below to 10 or higher you
-   should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! */
+/*
+ * Warning if you increase one of the 2 MAX defines below to 10 or higher you
+ * should adjust the belonging _NAMES_LENGTH macro for the 2 digit number!
+ */
 /* max nr of sensors in bank2, currently mb's with max 6 fans are known */
 #define ABIT_UGURU_MAX_BANK2_SENSORS		6
 /* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */
@@ -70,16 +72,22 @@
 #define ABIT_UGURU_IN_SENSOR			0
 #define ABIT_UGURU_TEMP_SENSOR			1
 #define ABIT_UGURU_NC				2
-/* In many cases we need to wait for the uGuru to reach a certain status, most
-   of the time it will reach this status within 30 - 90 ISA reads, and thus we
-   can best busy wait. This define gives the total amount of reads to try. */
+/*
+ * In many cases we need to wait for the uGuru to reach a certain status, most
+ * of the time it will reach this status within 30 - 90 ISA reads, and thus we
+ * can best busy wait. This define gives the total amount of reads to try.
+ */
 #define ABIT_UGURU_WAIT_TIMEOUT			125
-/* However sometimes older versions of the uGuru seem to be distracted and they
-   do not respond for a long time. To handle this we sleep before each of the
-   last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */
+/*
+ * However sometimes older versions of the uGuru seem to be distracted and they
+ * do not respond for a long time. To handle this we sleep before each of the
+ * last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries.
+ */
 #define ABIT_UGURU_WAIT_TIMEOUT_SLEEP		5
-/* Normally all expected status in abituguru_ready, are reported after the
-   first read, but sometimes not and we need to poll. */
+/*
+ * Normally all expected status in abituguru_ready, are reported after the
+ * first read, but sometimes not and we need to poll.
+ */
 #define ABIT_UGURU_READY_TIMEOUT		5
 /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
 #define ABIT_UGURU_MAX_RETRIES			3
@@ -92,17 +100,25 @@
 	if (level <= verbose)						\
 		printk(KERN_DEBUG ABIT_UGURU_NAME ": "	format , ## arg)
 /* Macros to help calculate the sysfs_names array length */
-/* sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
-   in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 */
+/*
+ * sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
+ * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0
+ */
 #define ABITUGURU_IN_NAMES_LENGTH	(11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14)
-/* sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0,
-   temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 */
+/*
+ * sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0,
+ * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0
+ */
 #define ABITUGURU_TEMP_NAMES_LENGTH	(13 + 11 + 12 + 13 + 20 + 12 + 16)
-/* sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0,
-   fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 */
+/*
+ * sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0,
+ * fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0
+ */
 #define ABITUGURU_FAN_NAMES_LENGTH	(11 + 9 + 11 + 18 + 10 + 14)
-/* sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0,
-   pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 */
+/*
+ * sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0,
+ * pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0
+ */
 #define ABITUGURU_PWM_NAMES_LENGTH	(12 + 24 + 2 * 21 + 2 * 22)
 /* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */
 #define ABITUGURU_SYSFS_NAMES_LENGTH	( \
@@ -110,10 +126,12 @@
 	ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \
 	ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH)

-/* All the macros below are named identical to the oguru and oguru2 programs
-   reverse engineered by Olle Sandberg, hence the names might not be 100%
-   logical. I could come up with better names, but I prefer keeping the names
-   identical so that this driver can be compared with his work more easily. */
+/*
+ * All the macros below are named identical to the oguru and oguru2 programs
+ * reverse engineered by Olle Sandberg, hence the names might not be 100%
+ * logical. I could come up with better names, but I prefer keeping the names
+ * identical so that this driver can be compared with his work more easily.
+ */
 /* Two i/o-ports are used by uGuru */
 #define ABIT_UGURU_BASE				0x00E0
 /* Used to tell uGuru what to read and to read the actual data */
@@ -130,16 +148,22 @@
 /* Constants */
 /* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */
 static const int abituguru_bank1_max_value[2] = { 3494, 255000 };
-/* Min / Max allowed values for sensor2 (fan) alarm threshold, these values
-   correspond to 300-3000 RPM */
+/*
+ * Min / Max allowed values for sensor2 (fan) alarm threshold, these values
+ * correspond to 300-3000 RPM
+ */
 static const u8 abituguru_bank2_min_threshold = 5;
 static const u8 abituguru_bank2_max_threshold = 50;
-/* Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4
-   are temperature trip points. */
+/*
+ * Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4
+ * are temperature trip points.
+ */
 static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 };
-/* Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a
-   special case the minium allowed pwm% setting for this is 30% (77) on
-   some MB's this special case is handled in the code! */
+/*
+ * Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a
+ * special case the minium allowed pwm% setting for this is 30% (77) on
+ * some MB's this special case is handled in the code!
+ */
 static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 };
 static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 };

@@ -175,23 +199,29 @@
 	"   3 + retryable error reporting");

-/* For the Abit uGuru, we need to keep some data in memory.
-   The structure is dynamically allocated, at the same time when a new
-   abituguru device is allocated. */
+/*
+ * For the Abit uGuru, we need to keep some data in memory.
+ * The structure is dynamically allocated, at the same time when a new
+ * abituguru device is allocated.
+ */
 struct abituguru_data {
 	struct device *hwmon_dev;	/* hwmon registered device */
 	struct mutex update_lock;	/* protect access to data and uGuru */
 	unsigned long last_updated;	/* In jiffies */
 	unsigned short addr;		/* uguru base address */
 	char uguru_ready;		/* is the uguru in ready state? */
-	unsigned char update_timeouts;	/* number of update timeouts since last
-					   successful update */
-
-	/* The sysfs attr and their names are generated automatically, for bank1
-	   we cannot use a predefined array because we don't know beforehand
-	   of a sensor is a volt or a temp sensor, for bank2 and the pwms its
-	   easier todo things the same way.  For in sensors we have 9 (temp 7)
-	   sysfs entries per sensor, for bank2 and pwms 6. */
+	unsigned char update_timeouts;	/*
+					 * number of update timeouts since last
+					 * successful update
+					 */
+
+	/*
+	 * The sysfs attr and their names are generated automatically, for bank1
+	 * we cannot use a predefined array because we don't know beforehand
+	 * of a sensor is a volt or a temp sensor, for bank2 and the pwms its
+	 * easier todo things the same way.  For in sensors we have 9 (temp 7)
+	 * sysfs entries per sensor, for bank2 and pwms 6.
+	 */
 	struct sensor_device_attribute_2 sysfs_attr[
 		ABIT_UGURU_MAX_BANK1_SENSORS * 9 +
 		ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6];
@@ -203,11 +233,15 @@
 	u8 bank1_sensors[2];
 	u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS];
 	u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS];
-	/* This array holds 3 entries per sensor for the bank 1 sensor settings
-	   (flags, min, max for voltage / flags, warn, shutdown for temp). */
+	/*
+	 * This array holds 3 entries per sensor for the bank 1 sensor settings
+	 * (flags, min, max for voltage / flags, warn, shutdown for temp).
+	 */
 	u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3];
-	/* Maximum value for each sensor used for scaling in mV/millidegrees
-	   Celsius. */
+	/*
+	 * Maximum value for each sensor used for scaling in mV/millidegrees
+	 * Celsius.
+	 */
 	int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS];

 	/* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */
@@ -236,8 +270,10 @@
 		timeout--;
 		if (timeout == 0)
 			return -EBUSY;
-		/* sleep a bit before our last few tries, see the comment on
-		   this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */
+		/*
+		 * sleep a bit before our last few tries, see the comment on
+		 * this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined.
+		 */
 		if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP)
 			msleep(0);
 	}
@@ -273,8 +309,10 @@
 		msleep(0);
 	}

-	/* After this the ABIT_UGURU_DATA port should contain
-	   ABIT_UGURU_STATUS_INPUT */
+	/*
+	 * After this the ABIT_UGURU_DATA port should contain
+	 * ABIT_UGURU_STATUS_INPUT
+	 */
 	timeout = ABIT_UGURU_READY_TIMEOUT;
 	while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) {
 		timeout--;
@@ -290,27 +328,35 @@
 	return 0;
 }

-/* Send the bank and then sensor address to the uGuru for the next read/write
-   cycle. This function gets called as the first part of a read/write by
-   abituguru_read and abituguru_write. This function should never be
-   called by any other function. */
+/*
+ * Send the bank and then sensor address to the uGuru for the next read/write
+ * cycle. This function gets called as the first part of a read/write by
+ * abituguru_read and abituguru_write. This function should never be
+ * called by any other function.
+ */
 static int abituguru_send_address(struct abituguru_data *data,
 	u8 bank_addr, u8 sensor_addr, int retries)
 {
-	/* assume the caller does error handling itself if it has not requested
-	   any retries, and thus be quiet. */
+	/*
+	 * assume the caller does error handling itself if it has not requested
+	 * any retries, and thus be quiet.
+	 */
 	int report_errors = retries;

 	for (;;) {
-		/* Make sure the uguru is ready and then send the bank address,
-		   after this the uguru is no longer "ready". */
+		/*
+		 * Make sure the uguru is ready and then send the bank address,
+		 * after this the uguru is no longer "ready".
+		 */
 		if (abituguru_ready(data) != 0)
 			return -EIO;
 		outb(bank_addr, data->addr + ABIT_UGURU_DATA);
 		data->uguru_ready = 0;

-		/* Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again
-		   and send the sensor addr */
+		/*
+		 * Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again
+		 * and send the sensor addr
+		 */
 		if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) {
 			if (retries) {
 				ABIT_UGURU_DEBUG(3, "timeout exceeded "
@@ -332,8 +378,10 @@
 	}
 }

-/* Read count bytes from sensor sensor_addr in bank bank_addr and store the
-   result in buf, retry the send address part of the read retries times. */
+/*
+ * Read count bytes from sensor sensor_addr in bank bank_addr and store the
+ * result in buf, retry the send address part of the read retries times.
+ */
 static int abituguru_read(struct abituguru_data *data,
 	u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries)
 {
@@ -362,13 +410,17 @@
 	return i;
 }

-/* Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send
-   address part of the write is always retried ABIT_UGURU_MAX_RETRIES times. */
+/*
+ * Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send
+ * address part of the write is always retried ABIT_UGURU_MAX_RETRIES times.
+ */
 static int abituguru_write(struct abituguru_data *data,
 	u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
 {
-	/* We use the ready timeout as we have to wait for 0xAC just like the
-	   ready function */
+	/*
+	 * We use the ready timeout as we have to wait for 0xAC just like the
+	 * ready function
+	 */
 	int i, timeout = ABIT_UGURU_READY_TIMEOUT;

 	/* Send the address */
@@ -388,9 +440,11 @@
 		outb(buf[i], data->addr + ABIT_UGURU_CMD);
 	}

-	/* Now we need to wait till the chip is ready to be read again,
-	   so that we can read 0xAC as confirmation that our write has
-	   succeeded. */
+	/*
+	 * Now we need to wait till the chip is ready to be read again,
+	 * so that we can read 0xAC as confirmation that our write has
+	 * succeeded.
+	 */
 	if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
 		ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
 			"after write (bank: %d, sensor: %d)\n", (int)bank_addr,
@@ -416,12 +470,14 @@
 	return i;
 }

-/* Detect sensor type. Temp and Volt sensors are enabled with
-   different masks and will ignore enable masks not meant for them.
-   This enables us to test what kind of sensor we're dealing with.
-   By setting the alarm thresholds so that we will always get an
-   alarm for sensor type X and then enabling the sensor as sensor type
-   X, if we then get an alarm it is a sensor of type X. */
+/*
+ * Detect sensor type. Temp and Volt sensors are enabled with
+ * different masks and will ignore enable masks not meant for them.
+ * This enables us to test what kind of sensor we're dealing with.
+ * By setting the alarm thresholds so that we will always get an
+ * alarm for sensor type X and then enabling the sensor as sensor type
+ * X, if we then get an alarm it is a sensor of type X.
+ */
 static int __devinit
 abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
 				   u8 sensor_addr)
@@ -448,16 +504,20 @@
 		pr_warn("bank1-sensor: %d reading (%d) too close to limits, "
 			"unable to determine sensor type, skipping sensor\n",
 			(int)sensor_addr, (int)val);
-		/* assume no sensor is there for sensors for which we can't
-		   determine the sensor type because their reading is too close
-		   to their limits, this usually means no sensor is there. */
+		/*
+		 * assume no sensor is there for sensors for which we can't
+		 * determine the sensor type because their reading is too close
+		 * to their limits, this usually means no sensor is there.
+		 */
 		return ABIT_UGURU_NC;
 	}

 	ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr);
-	/* Volt sensor test, enable volt low alarm, set min value ridicously
-	   high, or vica versa if the reading is very high. If its a volt
-	   sensor this should always give us an alarm. */
+	/*
+	 * Volt sensor test, enable volt low alarm, set min value ridicously
+	 * high, or vica versa if the reading is very high. If its a volt
+	 * sensor this should always give us an alarm.
+	 */
 	if (val <= 240u) {
 		buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE;
 		buf[1] = 245;
@@ -473,8 +533,10 @@
 	if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
 			buf, 3) != 3)
 		goto abituguru_detect_bank1_sensor_type_exit;
-	/* Now we need 20 ms to give the uguru time to read the sensors
-	   and raise a voltage alarm */
+	/*
+	 * Now we need 20 ms to give the uguru time to read the sensors
+	 * and raise a voltage alarm
+	 */
 	set_current_state(TASK_UNINTERRUPTIBLE);
 	schedule_timeout(HZ/50);
 	/* Check for alarm and check the alarm is a volt low alarm. */
@@ -497,17 +559,21 @@
 		ABIT_UGURU_DEBUG(2, "  alarm not raised during volt sensor "
 			"test\n");

-	/* Temp sensor test, enable sensor as a temp sensor, set beep value
-	   ridicously low (but not too low, otherwise uguru ignores it).
-	   If its a temp sensor this should always give us an alarm. */
+	/*
+	 * Temp sensor test, enable sensor as a temp sensor, set beep value
+	 * ridicously low (but not too low, otherwise uguru ignores it).
+	 * If its a temp sensor this should always give us an alarm.
+	 */
 	buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE;
 	buf[1] = 5;
 	buf[2] = 10;
 	if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
 			buf, 3) != 3)
 		goto abituguru_detect_bank1_sensor_type_exit;
-	/* Now we need 50 ms to give the uguru time to read the sensors
-	   and raise a temp alarm */
+	/*
+	 * Now we need 50 ms to give the uguru time to read the sensors
+	 * and raise a temp alarm
+	 */
 	set_current_state(TASK_UNINTERRUPTIBLE);
 	schedule_timeout(HZ/20);
 	/* Check for alarm and check the alarm is a temp high alarm. */
@@ -532,9 +598,11 @@

 	ret = ABIT_UGURU_NC;
 abituguru_detect_bank1_sensor_type_exit:
-	/* Restore original settings, failing here is really BAD, it has been
-	   reported that some BIOS-es hang when entering the uGuru menu with
-	   invalid settings present in the uGuru, so we try this 3 times. */
+	/*
+	 * Restore original settings, failing here is really BAD, it has been
+	 * reported that some BIOS-es hang when entering the uGuru menu with
+	 * invalid settings present in the uGuru, so we try this 3 times.
+	 */
 	for (i = 0; i < 3; i++)
 		if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
 				sensor_addr, data->bank1_settings[sensor_addr],
@@ -548,23 +616,25 @@
 	return ret;
 }

-/* These functions try to find out how many sensors there are in bank2 and how
-   many pwms there are. The purpose of this is to make sure that we don't give
-   the user the possibility to change settings for non-existent sensors / pwm.
-   The uGuru will happily read / write whatever memory happens to be after the
-   memory storing the PWM settings when reading/writing to a PWM which is not
-   there. Notice even if we detect a PWM which doesn't exist we normally won't
-   write to it, unless the user tries to change the settings.
-
-   Although the uGuru allows reading (settings) from non existing bank2
-   sensors, my version of the uGuru does seem to stop writing to them, the
-   write function above aborts in this case with:
-   "CMD reg does not hold 0xAC after write"
-
-   Notice these 2 tests are non destructive iow read-only tests, otherwise
-   they would defeat their purpose. Although for the bank2_sensors detection a
-   read/write test would be feasible because of the reaction above, I've
-   however opted to stay on the safe side. */
+/*
+ * These functions try to find out how many sensors there are in bank2 and how
+ * many pwms there are. The purpose of this is to make sure that we don't give
+ * the user the possibility to change settings for non-existent sensors / pwm.
+ * The uGuru will happily read / write whatever memory happens to be after the
+ * memory storing the PWM settings when reading/writing to a PWM which is not
+ * there. Notice even if we detect a PWM which doesn't exist we normally won't
+ * write to it, unless the user tries to change the settings.
+ *
+ * Although the uGuru allows reading (settings) from non existing bank2
+ * sensors, my version of the uGuru does seem to stop writing to them, the
+ * write function above aborts in this case with:
+ * "CMD reg does not hold 0xAC after write"
+ *
+ * Notice these 2 tests are non destructive iow read-only tests, otherwise
+ * they would defeat their purpose. Although for the bank2_sensors detection a
+ * read/write test would be feasible because of the reaction above, I've
+ * however opted to stay on the safe side.
+ */
 static void __devinit
 abituguru_detect_no_bank2_sensors(struct abituguru_data *data)
 {
@@ -580,12 +650,14 @@

 	ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n");
 	for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) {
-		/* 0x89 are the known used bits:
-		   -0x80 enable shutdown
-		   -0x08 enable beep
-		   -0x01 enable alarm
-		   All other bits should be 0, but on some motherboards
-		   0x40 (bit 6) is also high for some of the fans?? */
+		/*
+		 * 0x89 are the known used bits:
+		 * -0x80 enable shutdown
+		 * -0x08 enable beep
+		 * -0x01 enable alarm
+		 * All other bits should be 0, but on some motherboards
+		 * 0x40 (bit 6) is also high for some of the fans??
+		 */
 		if (data->bank2_settings[i][0] & ~0xC9) {
 			ABIT_UGURU_DEBUG(2, "  bank2 sensor %d does not seem "
 				"to be a fan sensor: settings[0] = %02X\n",
@@ -633,9 +705,11 @@

 	ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n");
 	for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) {
-		/* 0x80 is the enable bit and the low
-		   nibble is which temp sensor to use,
-		   the other bits should be 0 */
+		/*
+		 * 0x80 is the enable bit and the low
+		 * nibble is which temp sensor to use,
+		 * the other bits should be 0
+		 */
 		if (data->pwm_settings[i][0] & ~0x8F) {
 			ABIT_UGURU_DEBUG(2, "  pwm channel %d does not seem "
 				"to be a pwm channel: settings[0] = %02X\n",
@@ -643,8 +717,10 @@
 			break;
 		}

-		/* the low nibble must correspond to one of the temp sensors
-		   we've found */
+		/*
+		 * the low nibble must correspond to one of the temp sensors
+		 * we've found
+		 */
 		for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR];
 				j++) {
 			if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] ==
@@ -711,9 +787,11 @@
 	ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms);
 }

-/* Following are the sysfs callback functions. These functions expect:
-   sensor_device_attribute_2->index:   sensor address/offset in the bank
-   sensor_device_attribute_2->nr:      register offset, bitmask or NA. */
+/*
+ * Following are the sysfs callback functions. These functions expect:
+ * sensor_device_attribute_2->index:   sensor address/offset in the bank
+ * sensor_device_attribute_2->nr:      register offset, bitmask or NA.
+ */
 static struct abituguru_data *abituguru_update_device(struct device *dev);

 static ssize_t show_bank1_value(struct device *dev,
@@ -763,10 +841,18 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	u8 val = (simple_strtoul(buf, NULL, 10) * 255 +
-		data->bank1_max_value[attr->index]/2) /
+	unsigned long val;
+	ssize_t ret;
+
+	ret = kstrtoul(buf, 10, &val);
+	if (ret)
+		return ret;
+
+	ret = count;
+	val = (val * 255 + data->bank1_max_value[attr->index] / 2) /
 		data->bank1_max_value[attr->index];
-	ssize_t ret = count;
+	if (val > 255)
+		return -EINVAL;

 	mutex_lock(&data->update_lock);
 	if (data->bank1_settings[attr->index][attr->nr] != val) {
@@ -788,13 +874,19 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	u8 val = (simple_strtoul(buf, NULL, 10)*255 + ABIT_UGURU_FAN_MAX/2) /
-		ABIT_UGURU_FAN_MAX;
-	ssize_t ret = count;
+	unsigned long val;
+	ssize_t ret;
+
+	ret = kstrtoul(buf, 10, &val);
+	if (ret)
+		return ret;
+
+	ret = count;
+	val = (val * 255 + ABIT_UGURU_FAN_MAX / 2) / ABIT_UGURU_FAN_MAX;

 	/* this check can be done before taking the lock */
-	if ((val < abituguru_bank2_min_threshold) ||
-			(val > abituguru_bank2_max_threshold))
+	if (val < abituguru_bank2_min_threshold ||
+			val > abituguru_bank2_max_threshold)
 		return -EINVAL;

 	mutex_lock(&data->update_lock);
@@ -819,11 +911,13 @@
 	struct abituguru_data *data = abituguru_update_device(dev);
 	if (!data)
 		return -EIO;
-	/* See if the alarm bit for this sensor is set, and if the
-	   alarm matches the type of alarm we're looking for (for volt
-	   it can be either low or high). The type is stored in a few
-	   readonly bits in the settings part of the relevant sensor.
-	   The bitmask of the type is passed to us in attr->nr. */
+	/*
+	 * See if the alarm bit for this sensor is set, and if the
+	 * alarm matches the type of alarm we're looking for (for volt
+	 * it can be either low or high). The type is stored in a few
+	 * readonly bits in the settings part of the relevant sensor.
+	 * The bitmask of the type is passed to us in attr->nr.
+	 */
 	if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) &&
 			(data->bank1_settings[attr->index][0] & attr->nr))
 		return sprintf(buf, "1\n");
@@ -871,10 +965,15 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	int mask = simple_strtoul(buf, NULL, 10);
-	ssize_t ret = count;
+	ssize_t ret;
 	u8 orig_val;
-
+	unsigned long mask;
+
+	ret = kstrtoul(buf, 10, &mask);
+	if (ret)
+		return ret;
+
+	ret = count;
 	mutex_lock(&data->update_lock);
 	orig_val = data->bank1_settings[attr->index][0];

@@ -899,10 +998,15 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	int mask = simple_strtoul(buf, NULL, 10);
-	ssize_t ret = count;
+	ssize_t ret;
 	u8 orig_val;
-
+	unsigned long mask;
+
+	ret = kstrtoul(buf, 10, &mask);
+	if (ret)
+		return ret;
+
+	ret = count;
 	mutex_lock(&data->update_lock);
 	orig_val = data->bank2_settings[attr->index][0];

@@ -937,10 +1041,17 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	u8 min, val = (simple_strtoul(buf, NULL, 10) +
-		abituguru_pwm_settings_multiplier[attr->nr]/2) /
-		abituguru_pwm_settings_multiplier[attr->nr];
-	ssize_t ret = count;
+	u8 min;
+	unsigned long val;
+	ssize_t ret;
+
+	ret = kstrtoul(buf, 10, &val);
+	if (ret)
+		return ret;
+
+	ret = count;
+	val = (val + abituguru_pwm_settings_multiplier[attr->nr] / 2) /
+				abituguru_pwm_settings_multiplier[attr->nr];

 	/* special case pwm1 min pwm% */
 	if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2)))
@@ -949,7 +1060,7 @@
 		min = abituguru_pwm_min[attr->nr];

 	/* this check can be done before taking the lock */
-	if ((val < min) || (val > abituguru_pwm_max[attr->nr]))
+	if (val < min || val > abituguru_pwm_max[attr->nr])
 		return -EINVAL;

 	mutex_lock(&data->update_lock);
@@ -981,8 +1092,10 @@
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
 	int i;
-	/* We need to walk to the temp sensor addresses to find what
-	   the userspace id of the configured temp sensor is. */
+	/*
+	 * We need to walk to the temp sensor addresses to find what
+	 * the userspace id of the configured temp sensor is.
+	 */
 	for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++)
 		if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] ==
 				(data->pwm_settings[attr->index][0] & 0x0F))
@@ -996,27 +1109,32 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	unsigned long val = simple_strtoul(buf, NULL, 10) - 1;
-	ssize_t ret = count;
-
+	ssize_t ret;
+	unsigned long val;
+	u8 orig_val;
+	u8 address;
+
+	ret = kstrtoul(buf, 10, &val);
+	if (ret)
+		return ret;
+
+	if (val == 0 || val > data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR])
+		return -EINVAL;
+
+	val -= 1;
+	ret = count;
 	mutex_lock(&data->update_lock);
-	if (val < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) {
-		u8 orig_val = data->pwm_settings[attr->index][0];
-		u8 address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val];
-		data->pwm_settings[attr->index][0] &= 0xF0;
-		data->pwm_settings[attr->index][0] |= address;
-		if (data->pwm_settings[attr->index][0] != orig_val) {
-			if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1,
-					attr->index,
-					data->pwm_settings[attr->index],
-					5) < 1) {
-				data->pwm_settings[attr->index][0] = orig_val;
-				ret = -EIO;
-			}
-		}
-	}
-	else
-		ret = -EINVAL;
+	orig_val = data->pwm_settings[attr->index][0];
+	address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val];
+	data->pwm_settings[attr->index][0] &= 0xF0;
+	data->pwm_settings[attr->index][0] |= address;
+	if (data->pwm_settings[attr->index][0] != orig_val) {
+		if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, attr->index,
+				    data->pwm_settings[attr->index], 5) < 1) {
+			data->pwm_settings[attr->index][0] = orig_val;
+			ret = -EIO;
+		}
+	}
 	mutex_unlock(&data->update_lock);
 	return ret;
 }
@@ -1037,22 +1155,27 @@
 {
 	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct abituguru_data *data = dev_get_drvdata(dev);
-	u8 orig_val, user_val = simple_strtoul(buf, NULL, 10);
-	ssize_t ret = count;
-
+	u8 orig_val;
+	ssize_t ret;
+	unsigned long user_val;
+
+	ret = kstrtoul(buf, 10, &user_val);
+	if (ret)
+		return ret;
+
+	ret = count;
 	mutex_lock(&data->update_lock);
 	orig_val = data->pwm_settings[attr->index][0];
 	switch (user_val) {
-		case 0:
-			data->pwm_settings[attr->index][0] &=
-				~ABIT_UGURU_FAN_PWM_ENABLE;
-			break;
-		case 2:
-			data->pwm_settings[attr->index][0] |=
-				ABIT_UGURU_FAN_PWM_ENABLE;
-			break;
-		default:
-			ret = -EINVAL;
+	case 0:
+		data->pwm_settings[attr->index][0] &=
+			~ABIT_UGURU_FAN_PWM_ENABLE;
+		break;
+	case 2:
+		data->pwm_settings[attr->index][0] |= ABIT_UGURU_FAN_PWM_ENABLE;
+		break;
+	default:
+		ret = -EINVAL;
 	}
 	if ((data->pwm_settings[attr->index][0] != orig_val) &&
 			(abituguru_write(data, ABIT_UGURU_FAN_PWM + 1,
@@ -1147,13 +1270,16 @@
 	int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV;
 	char *sysfs_filename;

-	/* El weirdo probe order, to keep the sysfs order identical to the
-	   BIOS and window-appliction listing order. */
+	/*
+	 * El weirdo probe order, to keep the sysfs order identical to the
+	 * BIOS and window-appliction listing order.
+	 */
 	const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = {
 		0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02,
 		0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C };

-	if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL)))
+	data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL);
+	if (!data)
 		return -ENOMEM;

 	data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
@@ -1164,9 +1290,11 @@
 	if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT)
 		data->uguru_ready = 1;

-	/* Completely read the uGuru this has 2 purposes:
-	   - testread / see if one really is there.
-	   - make an in memory copy of all the uguru settings for future use. */
+	/*
+	 * Completely read the uGuru this has 2 purposes:
+	 * - testread / see if one really is there.
+	 * - make an in memory copy of all the uguru settings for future use.
+	 */
 	if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
 			data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3)
 		goto abituguru_probe_error;
@@ -1181,11 +1309,13 @@
 				ABIT_UGURU_MAX_RETRIES) != 3)
 			goto abituguru_probe_error;
 	}
-	/* Note: We don't know how many bank2 sensors / pwms there really are,
-	   but in order to "detect" this we need to read the maximum amount
-	   anyways. If we read sensors/pwms not there we'll just read crap
-	   this can't hurt. We need the detection because we don't want
-	   unwanted writes, which will hurt! */
+	/*
+	 * Note: We don't know how many bank2 sensors / pwms there really are,
+	 * but in order to "detect" this we need to read the maximum amount
+	 * anyways. If we read sensors/pwms not there we'll just read crap
+	 * this can't hurt. We need the detection because we don't want
+	 * unwanted writes, which will hurt!
+	 */
 	for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) {
 		if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i,
 				&data->bank2_value[i], 1,
@@ -1332,24 +1462,26 @@
 	mutex_lock(&data->update_lock);
 	if (time_after(jiffies, data->last_updated + HZ)) {
 		success = 0;
-		if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
-				data->alarms, 3, 0)) != 3)
+		err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
+				     data->alarms, 3, 0);
+		if (err != 3)
 			goto LEAVE_UPDATE;
 		for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) {
-			if ((err = abituguru_read(data,
-					ABIT_UGURU_SENSOR_BANK1, i,
-					&data->bank1_value[i], 1, 0)) != 1)
+			err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1,
+					     i, &data->bank1_value[i], 1, 0);
+			if (err != 1)
 				goto LEAVE_UPDATE;
-			if ((err = abituguru_read(data,
-					ABIT_UGURU_SENSOR_BANK1 + 1, i,
-					data->bank1_settings[i], 3, 0)) != 3)
+			err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
+					     i, data->bank1_settings[i], 3, 0);
+			if (err != 3)
 				goto LEAVE_UPDATE;
 		}
-		for (i = 0; i < data->bank2_sensors; i++)
-			if ((err = abituguru_read(data,
-					ABIT_UGURU_SENSOR_BANK2, i,
-					&data->bank2_value[i], 1, 0)) != 1)
+		for (i = 0; i < data->bank2_sensors; i++) {
+			err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i,
+					     &data->bank2_value[i], 1, 0);
+			if (err != 1)
 				goto LEAVE_UPDATE;
+		}
 		/* success! */
 		success = 1;
 		data->update_timeouts = 0;
@@ -1385,8 +1517,10 @@
 static int abituguru_suspend(struct platform_device *pdev, pm_message_t state)
 {
 	struct abituguru_data *data = platform_get_drvdata(pdev);
-	/* make sure all communications with the uguru are done and no new
-	   ones are started */
+	/*
+	 * make sure all communications with the uguru are done and no new
+	 * ones are started
+	 */
 	mutex_lock(&data->update_lock);
 	return 0;
 }
@@ -1418,12 +1552,14 @@

 static int __init abituguru_detect(void)
 {
-	/* See if there is an uguru there. After a reboot uGuru will hold 0x00
-	   at DATA and 0xAC, when this driver has already been loaded once
-	   DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either
-	   scenario but some will hold 0x00.
-	   Some uGuru's initially hold 0x09 at DATA and will only hold 0x08
-	   after reading CMD first, so CMD must be read first! */
+	/*
+	 * See if there is an uguru there. After a reboot uGuru will hold 0x00
+	 * at DATA and 0xAC, when this driver has already been loaded once
+	 * DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either
+	 * scenario but some will hold 0x00.
+	 * Some uGuru's initially hold 0x09 at DATA and will only hold 0x08
+	 * after reading CMD first, so CMD must be read first!
+	 */
 	u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD);
 	u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA);
 	if (((data_val == 0x00) || (data_val == 0x08)) &&


[PATCH] hwmon: abituguru timeout fixes

[PATCH] hwmon: abituguru timeout fixes

This patch contains 2 sets of fixes for the abituguru:
 1) Much improved timeout handling, drasticly reducing the amount of
    timeout errors on some motherboards
 2) Fix the exit paths in the bank1 sensor type detect code to always
    restore the original settings even on an error. Without this our
    special test settings could remain seriously confusing the system
    BIOS's setup menu.

Both are very much related and are must haves, to avoid messing up the
uguru CMOS settings.

Detailed changes:
- Much improved timeout / wait for status handling. Many thanks to Sunil
  Kumar, for all his testing, ideas and patches! The code now first busy
  waits, polling the uguru for the expected status as this usually
  succeeds pretty quickly (within 90 reads). To avoid unnecessary CPU burn
  in timeout conditions, the amount of busy waiting has been halved from
  previous versions (120 tries instead of 250). This is not a problem,
  because this version goes to sleep after 120 attemps for 1 jiffy and
  then tries again, it does this sleep and try again 5 times before
  finally giving up. This (almost?) completly removes the timeout errors
  some people have seen regulary. Apparently some older uguru versions
  sometimes are distracted for a (relatively) long time. This solves this.
- These timeout errors not only occur in the sending address part of
  reading the uguru but also in the wait for read state, so errors in
  this state are now handled as retryable just like send address state
  errors and are only logged and reported to userspace if 3 executive
  tries fail.
- Fix a very nasty bug in the bank1 sensor type detection code, where it
  would not restore the original settings in any of the error paths!
- Since not successfully restoring the original settings can seriously
  confuse the system BIOS (hang when entering the relevant setup menu),
  we now try restoring them 3 times before giving up.

Signed-off-by: Hans de Goede <fb8d0494a9e27cd2eb05a840cc9c91dc67195d23@hhs.nl>
Signed-off-by: Jean Delvare <49ad6a9f5aa17024c23048df346d55bda6837e01@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <4645f7897fd33786a2ee1264d590b3c400559d85@suse.de>

--- drivers/hwmon/abituguru.c
+++ drivers/hwmon/abituguru.c
@@ -26,6 +26,7 @@
 #include <linux/jiffies.h>
 #include <linux/mutex.h>
 #include <linux/err.h>
+#include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
@@ -64,17 +65,17 @@
 #define ABIT_UGURU_IN_SENSOR			0
 #define ABIT_UGURU_TEMP_SENSOR			1
 #define ABIT_UGURU_NC				2
-/* Timeouts / Retries, if these turn out to need a lot of fiddling we could
-   convert them to params. */
-/* 250 was determined by trial and error, 200 works most of the time, but not
-   always. I assume this is cpu-speed independent, since the ISA-bus and not
-   the CPU should be the bottleneck. Note that 250 sometimes is still not
-   enough (only reported on AN7 mb) this is handled by a higher layer. */
-#define ABIT_UGURU_WAIT_TIMEOUT			250
+/* In many cases we need to wait for the uGuru to reach a certain status, most
+   of the time it will reach this status within 30 - 90 ISA reads, and thus we
+   can best busy wait. This define gives the total amount of reads to try. */
+#define ABIT_UGURU_WAIT_TIMEOUT			125
+/* However sometimes older versions of the uGuru seem to be distracted and they
+   do not respond for a long time. To handle this we sleep before each of the
+   last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */
+#define ABIT_UGURU_WAIT_TIMEOUT_SLEEP		5
 /* Normally all expected status in abituguru_ready, are reported after the
-   first read, but sometimes not and we need to poll, 5 polls was not enough
-   50 sofar is. */
-#define ABIT_UGURU_READY_TIMEOUT		50
+   first read, but sometimes not and we need to poll. */
+#define ABIT_UGURU_READY_TIMEOUT		5
 /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
 #define ABIT_UGURU_MAX_RETRIES			3
 #define ABIT_UGURU_RETRY_DELAY			(HZ/5)
@@ -226,6 +227,10 @@
 		timeout--;
 		if (timeout == 0)
 			return -EBUSY;
+		/* sleep a bit before our last few tries, see the comment on
+		   this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */
+		if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP)
+			msleep(0);
 	}
 	return 0;
 }
@@ -256,6 +261,7 @@
 			   "CMD reg does not hold 0xAC after ready command\n");
 			return -EIO;
 		}
+		msleep(0);
 	}

 	/* After this the ABIT_UGURU_DATA port should contain
@@ -268,6 +274,7 @@
 				"state != more input after ready command\n");
 			return -EIO;
 		}
+		msleep(0);
 	}

 	data->uguru_ready = 1;
@@ -331,7 +338,8 @@
 	/* And read the data */
 	for (i = 0; i < count; i++) {
 		if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
-			ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for "
+			ABIT_UGURU_DEBUG(retries ? 1 : 3,
+				"timeout exceeded waiting for "
 				"read state (bank: %d, sensor: %d)\n",
 				(int)bank_addr, (int)sensor_addr);
 			break;
@@ -350,7 +358,9 @@
 static int abituguru_write(struct abituguru_data *data,
 	u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
 {
-	int i;
+	/* We use the ready timeout as we have to wait for 0xAC just like the
+	   ready function */
+	int i, timeout = ABIT_UGURU_READY_TIMEOUT;

 	/* Send the address */
 	i = abituguru_send_address(data, bank_addr, sensor_addr,
@@ -370,7 +380,8 @@
 	}

 	/* Now we need to wait till the chip is ready to be read again,
-	   don't ask why */
+	   so that we can read 0xAC as confirmation that our write has
+	   succeeded. */
 	if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
 		ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
 			"after write (bank: %d, sensor: %d)\n", (int)bank_addr,
@@ -379,11 +390,15 @@
 	}

 	/* Cmd port MUST be read now and should contain 0xAC */
-	if (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
-		ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after write "
-			"(bank: %d, sensor: %d)\n", (int)bank_addr,
-			(int)sensor_addr);
-		return -EIO;
+	while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
+		timeout--;
+		if (timeout == 0) {
+			ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after "
+				"write (bank: %d, sensor: %d)\n",
+				(int)bank_addr, (int)sensor_addr);
+			return -EIO;
+		}
+		msleep(0);
 	}

 	/* Last put the chip back in ready state */
@@ -403,7 +418,7 @@
 				   u8 sensor_addr)
 {
 	u8 val, buf[3];
-	int ret = ABIT_UGURU_NC;
+	int i, ret = -ENODEV; /* error is the most common used retval :| */

 	/* If overriden by the user return the user selected type */
 	if (bank1_types[sensor_addr] >= ABIT_UGURU_IN_SENSOR &&
@@ -439,7 +454,7 @@
 	buf[2] = 250;
 	if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
 			buf, 3) != 3)
-		return -ENODEV;
+		goto abituguru_detect_bank1_sensor_type_exit;
 	/* Now we need 20 ms to give the uguru time to read the sensors
 	   and raise a voltage alarm */
 	set_current_state(TASK_UNINTERRUPTIBLE);
@@ -447,21 +462,16 @@
 	/* Check for alarm and check the alarm is a volt low alarm. */
 	if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
 			ABIT_UGURU_MAX_RETRIES) != 3)
-		return -ENODEV;
+		goto abituguru_detect_bank1_sensor_type_exit;
 	if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
 		if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
 				sensor_addr, buf, 3,
 				ABIT_UGURU_MAX_RETRIES) != 3)
-			return -ENODEV;
+			goto abituguru_detect_bank1_sensor_type_exit;
 		if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) {
-			/* Restore original settings */
-			if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
-					sensor_addr,
-					data->bank1_settings[sensor_addr],
-					3) != 3)
-				return -ENODEV;
 			ABIT_UGURU_DEBUG(2, "  found volt sensor\n");
-			return ABIT_UGURU_IN_SENSOR;
+			ret = ABIT_UGURU_IN_SENSOR;
+			goto abituguru_detect_bank1_sensor_type_exit;
 		} else
 			ABIT_UGURU_DEBUG(2, "  alarm raised during volt "
 				"sensor test, but volt low flag not set\n");
@@ -477,7 +487,7 @@
 	buf[2] = 10;
 	if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
 			buf, 3) != 3)
-		return -ENODEV;
+		goto abituguru_detect_bank1_sensor_type_exit;
 	/* Now we need 50 ms to give the uguru time to read the sensors
 	   and raise a temp alarm */
 	set_current_state(TASK_UNINTERRUPTIBLE);
@@ -485,15 +495,16 @@
 	/* Check for alarm and check the alarm is a temp high alarm. */
 	if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
 			ABIT_UGURU_MAX_RETRIES) != 3)
-		return -ENODEV;
+		goto abituguru_detect_bank1_sensor_type_exit;
 	if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
 		if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
 				sensor_addr, buf, 3,
 				ABIT_UGURU_MAX_RETRIES) != 3)
-			return -ENODEV;
+			goto abituguru_detect_bank1_sensor_type_exit;
 		if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) {
+			ABIT_UGURU_DEBUG(2, "  found temp sensor\n");
 			ret = ABIT_UGURU_TEMP_SENSOR;
-			ABIT_UGURU_DEBUG(2, "  found temp sensor\n");
+			goto abituguru_detect_bank1_sensor_type_exit;
 		} else
 			ABIT_UGURU_DEBUG(2, "  alarm raised during temp "
 				"sensor test, but temp high flag not set\n");
@@ -501,11 +512,23 @@
 		ABIT_UGURU_DEBUG(2, "  alarm not raised during temp sensor "
 			"test\n");

-	/* Restore original settings */
-	if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
-			data->bank1_settings[sensor_addr], 3) != 3)
+	ret = ABIT_UGURU_NC;
+abituguru_detect_bank1_sensor_type_exit:
+	/* Restore original settings, failing here is really BAD, it has been
+	   reported that some BIOS-es hang when entering the uGuru menu with
+	   invalid settings present in the uGuru, so we try this 3 times. */
+	for (i = 0; i < 3; i++)
+		if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
+				sensor_addr, data->bank1_settings[sensor_addr],
+				3) == 3)
+			break;
+	if (i == 3) {
+		printk(KERN_ERR ABIT_UGURU_NAME
+			": Fatal error could not restore original settings. "
+			"This should never happen please report this to the "
+			"abituguru maintainer (see MAINTAINERS)\n");
 		return -ENODEV;
-
+	}
 	return ret;
 }

@@ -1305,7 +1328,7 @@
 		data->update_timeouts = 0;
 LEAVE_UPDATE:
 		/* handle timeout condition */
-		if (err == -EBUSY) {
+		if (!success && (err == -EBUSY || err >= 0)) {
 			/* No overflow please */
 			if (data->update_timeouts < 255u)
 				data->update_timeouts++;


ide/arm/ide_arm.c: add MODULE_LICENSE

ide/arm/ide_arm.c: add MODULE_LICENSE

Now that it can be built modular it needs a MODULE_LICENSE.

Signed-off-by: Adrian Bunk <0b86548ef377da0031a3ff3f0c4e06f016e20105@kernel.org>
Cc: Sam Ravnborg <f16bed56189e249fe4ca8ed10a1ecae60e8ceac0@ravnborg.org>
Signed-off-by: Bartlomiej Zolnierkiewicz <248de9df611a028e5eceb9d893a2ed6c24c89ef4@gmail.com>

--- drivers/ide/arm/ide_arm.c
+++ drivers/ide/arm/ide_arm.c
@@ -46,3 +46,5 @@
 }

 module_init(ide_arm_init);
+
+MODULE_LICENSE("GPL");


[PATCH] siimage: enable interrupts on Adaptec SA-1210 card

The siimage driver proports to support the Adaptec SA-1210 SATA
controller.  However, at least some of those cards boot-up with their
interrupts disabled internally.  The siimage driver currently ignores
that fact, so that driver does not actually work with those cards.
This patch enables those interrupts on cards that need it.

[ This is implemented based on similar code in the libata-based
  sata_sil driver. ]

Signed-off-by: John W. Linville <2a53bac7a5d324865ef46ec4c38b2c0fba1456b4@tuxdriver.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <248de9df611a028e5eceb9d893a2ed6c24c89ef4@gmail.com>

--- drivers/ide/pci/siimage.c
+++ drivers/ide/pci/siimage.c
@@ -701,6 +701,7 @@
 	unsigned long barsize	= pci_resource_len(dev, 5);
 	u8 tmpbyte	= 0;
 	void __iomem *ioaddr;
+	u32 tmp, irq_mask;

 	/*
 	 *	Drop back to PIO if we can't map the mmio. Some
@@ -726,6 +727,14 @@
 	pci_set_drvdata(dev, (void *) ioaddr);

 	if (pdev_is_sata(dev)) {
+		/* make sure IDE0/1 interrupts are not masked */
+		irq_mask = (1 << 22) | (1 << 23);
+		tmp = readl(ioaddr + 0x48);
+		if (tmp & irq_mask) {
+			tmp &= ~irq_mask;
+			writel(tmp, ioaddr + 0x48);
+			readl(ioaddr + 0x48); /* flush */
+		}
 		writel(0, ioaddr + 0x148);
 		writel(0, ioaddr + 0x1C8);
 	}


irqchip: gic: use dmb ishst instead of dsb when raising a softirq

When sending an SGI to another CPU, we require a barrier to ensure that
any pending stores to normal memory are made visible to the recipient
before the interrupt arrives.

Rather than use a vanilla dsb() (which will soon cause an assembly error
on arm64) before the writel_relaxed, we can instead use dsb(ishst),
since we just need to ensure that any pending normal writes are visible
within the inner-shareable domain before we poke the GIC.

With this observation, we can then further weaken the barrier to a
dmb(ishst), since other CPUs in the inner-shareable domain must observe
the write to the distributor before the SGI is generated.

Cc: Thomas Gleixner <00e4cf8f46a57000a44449bf9dd8cbbcc209fd2a@linutronix.de>
Acked-by: Marc Zyngier <a16cc0c82647c52d401177f8e50567df5499e36c@arm.com>
Acked-by: Catalin Marinas <15ce75b290ebaf27c3f9fd73ab848685ed3d8261@arm.com>
Signed-off-by: Will Deacon <b913f13ef92ac157955c954ccaaff7be065faba4@arm.com>
Signed-off-by: Arnd Bergmann <f2c659f01951776204a6c5b902787d9019fbeebd@arndb.de>


drivers: kscan: Convert DEVICE_AND_API_INIT to DEVICE_DEFINE

Convert driver(s) to DEVICE_DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.

Signed-off-by: Kumar Gala <a5e5248af4cd4f0ed8c515f61d40a6e2db46a66e@linaro.org>

--- drivers/kscan/kscan_sdl.c
+++ drivers/kscan/kscan_sdl.c
@@ -106,7 +106,7 @@

 static struct sdl_data sdl_data;

-DEVICE_AND_API_INIT(sdl, CONFIG_SDL_POINTER_KSCAN_DEV_NAME, sdl_init,
-		    &sdl_data, NULL,
+DEVICE_DEFINE(sdl, CONFIG_SDL_POINTER_KSCAN_DEV_NAME, sdl_init,
+		    device_pm_control_nop, &sdl_data, NULL,
 		    POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY,
 		    &sdl_driver_api);


drivers/lsm6dsl: fix typos

drivers/lsm6dsl: fix typos

--- drivers/lsm6dsl/lsm6dsl.c
+++ drivers/lsm6dsl/lsm6dsl.c
@@ -34,13 +34,13 @@
 #define ADDR        (dev->params.addr)

 /**
- * order in arry [0, 1, 2, 3] is
+ * order in array [0, 1, 2, 3] is
  * LSM6DSL_ACC_FS_2G, LSM6DSL_ACC_FS_16G, LSM6DSL_ACC_FS_4G, LSM6DSL_ACC_FS_8G
  */
 static const int16_t range_acc[] = { 2000, 16000, 4000, 8000 };

 /**
- * order in arry [0, 1, 2, 3] is
+ * order in array [0, 1, 2, 3] is
  * LSM6DSL_GYRO_FS_245DPS, LSM6DSL_GYRO_FS_500DPS,
  * LSM6DSL_GYRO_FS_1000DPS, LSM6DSL_GYRO_FS_2000DPS
  */


tests: dac_loopback: Convert to use DEVICE_DT_GET

Move to use DEVICE_DT_GET instead of device_get_binding as
we work on phasing out use of DTS 'label' property.

Signed-off-by: Kumar Gala <383ef5577c6e1178b93f59ec8d0936f76d2a98c4@kernel.org>

--- tests/drivers/dac/dac_loopback/src/test_dac.c
+++ tests/drivers/dac/dac_loopback/src/test_dac.c
@@ -39,11 +39,11 @@
  * ADC input read from PA1 (Arduino A1 pin of Nucleo board)
  */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac1))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac1)
 #define DAC_CHANNEL_ID		1
 #define DAC_RESOLUTION		12

-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc1))
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc1)
 #define ADC_CHANNEL_ID		1
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1
@@ -59,11 +59,11 @@
  * ADC input read from PA0
  */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac1))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac1)
 #define DAC_CHANNEL_ID		1
 #define DAC_RESOLUTION		12

-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc1))
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc1)
 #define ADC_CHANNEL_ID		0
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1
@@ -77,11 +77,11 @@
  * is enabled.
  */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac0))
-#define DAC_RESOLUTION		12
-#define DAC_CHANNEL_ID		0
-
-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc0))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac0)
+#define DAC_RESOLUTION		12
+#define DAC_CHANNEL_ID		0
+
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc0)
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1
 #define ADC_REFERENCE		ADC_REF_INTERNAL
@@ -92,11 +92,11 @@

 /* DAC0 output is internally available on ADC0_SE23 */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac0))
-#define DAC_RESOLUTION		12
-#define DAC_CHANNEL_ID		0
-
-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc0))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac0)
+#define DAC_RESOLUTION		12
+#define DAC_CHANNEL_ID		0
+
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc0)
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1
 #define ADC_REFERENCE		ADC_REF_INTERNAL
@@ -107,11 +107,11 @@

 /* DAC0 output is internally available on ADC0_SE23 */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac0))
-#define DAC_RESOLUTION		12
-#define DAC_CHANNEL_ID		0
-
-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc0))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac0)
+#define DAC_RESOLUTION		12
+#define DAC_CHANNEL_ID		0
+
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc0)
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1
 #define ADC_REFERENCE		ADC_REF_INTERNAL
@@ -130,11 +130,11 @@
   * BL654_DVK at factory
   */

-#define DAC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(dac0))
-#define DAC_RESOLUTION		12
-#define DAC_CHANNEL_ID		0
-
-#define ADC_DEVICE_NAME		DT_LABEL(DT_NODELABEL(adc))
+#define DAC_DEVICE_NODE		DT_NODELABEL(dac0)
+#define DAC_RESOLUTION		12
+#define DAC_CHANNEL_ID		0
+
+#define ADC_DEVICE_NODE		DT_NODELABEL(adc)
 #define ADC_RESOLUTION		12
 #define ADC_GAIN		ADC_GAIN_1_4
 #define ADC_REFERENCE		ADC_REF_VDD_1_4
@@ -168,9 +168,9 @@
 static const struct device *init_dac(void)
 {
 	int ret;
-	const struct device *dac_dev = device_get_binding(DAC_DEVICE_NAME);
-
-	zassert_not_null(dac_dev, "Cannot get DAC device");
+	const struct device *dac_dev = DEVICE_DT_GET(DAC_DEVICE_NODE);
+
+	zassert_true(device_is_ready(dac_dev), "DAC device is not ready");

 	ret = dac_channel_setup(dac_dev, &dac_ch_cfg);
 	zassert_equal(ret, 0,
@@ -183,9 +183,9 @@
 static const struct device *init_adc(void)
 {
 	int ret;
-	const struct device *adc_dev = device_get_binding(ADC_DEVICE_NAME);
-
-	zassert_not_null(adc_dev, "Cannot get ADC device");
+	const struct device *adc_dev = DEVICE_DT_GET(ADC_DEVICE_NODE);
+
+	zassert_true(device_is_ready(adc_dev), "ADC device is not ready");

 	ret = adc_channel_setup(adc_dev, &adc_ch_cfg);
 	zassert_equal(ret, 0,


mfd: cros_ec: spi: Add mutex to cros_ec_spi

The main transfer function for cros_ec_spi can be called by more than
one client at a time.  Make sure that those clients don't stomp on
each other by locking the bus for the duration of the transfer
function.

Signed-off-by: Doug Anderson <49983c4a76b998672954ed5edf4a62db4a336502@chromium.org>
Reviewed-by: Simon Glass <c00b0378376498bd9cd974c388df8854c0131d27@chromium.org>
Tested-by: Andrew Bresticker <6f9d97df82107736b1c4f0e11d74242c25499ec8@chromium.org>
Tested-by: Stephen Warren <5ef2a23ba3aff51d1cfc8c113c1ec34b608b3b13@nvidia.com>
Signed-off-by: Lee Jones <630e34333487a351a857f6b705e04d30b37c1629@linaro.org>

--- drivers/mfd/cros_ec_spi.c
+++ drivers/mfd/cros_ec_spi.c
@@ -65,11 +65,13 @@
  *	if no record
  * @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that
  *      is sent when we want to turn off CS at the end of a transaction.
+ * @lock: mutex to ensure only one user of cros_ec_command_spi_xfer at a time
  */
 struct cros_ec_spi {
 	struct spi_device *spi;
 	s64 last_transfer_ns;
 	unsigned int end_of_msg_delay;
+	struct mutex lock;
 };

 static void debug_packet(struct device *dev, const char *name, u8 *ptr,
@@ -208,6 +210,13 @@
 	int ret = 0, final_ret;
 	struct timespec ts;

+	/*
+	 * We have the shared ec_dev buffer plus we do lots of separate spi_sync
+	 * calls, so we need to make sure only one person is using this at a
+	 * time.
+	 */
+	mutex_lock(&ec_spi->lock);
+
 	len = cros_ec_prepare_tx(ec_dev, ec_msg);
 	dev_dbg(ec_dev->dev, "prepared, len=%d\n", len);

@@ -260,7 +269,7 @@
 		ret = final_ret;
 	if (ret < 0) {
 		dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
-		return ret;
+		goto exit;
 	}

 	/* check response error code */
@@ -269,14 +278,16 @@
 		dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n",
 			 ec_msg->cmd, ptr[0]);
 		debug_packet(ec_dev->dev, "in_err", ptr, len);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto exit;
 	}
 	len = ptr[1];
 	sum = ptr[0] + ptr[1];
 	if (len > ec_msg->in_len) {
 		dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)",
 			len, ec_msg->in_len);
-		return -ENOSPC;
+		ret = -ENOSPC;
+		goto exit;
 	}

 	/* copy response packet payload and compute checksum */
@@ -293,10 +304,14 @@
 		dev_err(ec_dev->dev,
 			"bad packet checksum, expected %02x, got %02x\n",
 			sum, ptr[len + 2]);
-		return -EBADMSG;
-	}
-
-	return 0;
+		ret = -EBADMSG;
+		goto exit;
+	}
+
+	ret = 0;
+exit:
+	mutex_unlock(&ec_spi->lock);
+	return ret;
 }

 static void cros_ec_spi_dt_probe(struct cros_ec_spi *ec_spi, struct device *dev)
@@ -327,6 +342,7 @@
 	if (ec_spi == NULL)
 		return -ENOMEM;
 	ec_spi->spi = spi;
+	mutex_init(&ec_spi->lock);
 	ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
 	if (!ec_dev)
 		return -ENOMEM;


Fix stat_lyc_onoff

Fix stat_lyc_onoff

--- Core/display.c
+++ Core/display.c
@@ -266,11 +266,9 @@
     gb->display_cycles = 0;
     /* When the LCD is disabled, state is constant */

-    /* When the LCD is off, LY is 0 and STAT mode is 0.
-     Todo: Verify the LY=LYC flag should be on. */
+    /* When the LCD is off, LY is 0 and STAT mode is 0.  */
     gb->io_registers[GB_IO_LY] = 0;
     gb->io_registers[GB_IO_STAT] &= ~3;
-    gb->io_registers[GB_IO_STAT] |= 4;
     if (gb->hdma_on_hblank) {
         gb->hdma_on_hblank = false;
         gb->hdma_on = false;
@@ -278,7 +276,6 @@
         /* Todo: is this correct? */
         gb->hdma_steps_left = 0xff;
     }
-    gb->stat_interrupt_line = false;

     gb->oam_read_blocked = false;
     gb->vram_read_blocked = false;


mfd: Fix mc13xxx SPI regmap

mfd: Fix mc13xxx SPI regmap

This fix the SPI regmap configuration, the wrong write flag was used.
Also, bits_per_word should not be set as the regmap spi implementation
uses a 8bits transfert granularity.

Signed-off-by: Philippe Rétornaz <bbdf5650fcb9cf641e53caa5c21057ef19341353@epfl.ch>
Tested-by: Fabio Estevam <679188261afeb60eb822cd934fd7b46a48ddd743@freescale.com>
Signed-off-by: Samuel Ortiz <0ba86cb3f08bbb861958e54bd3438887adb4263c@linux.intel.com>

--- drivers/mfd/mc13xxx-spi.c
+++ drivers/mfd/mc13xxx-spi.c
@@ -49,6 +49,7 @@
 	.reg_bits = 7,
 	.pad_bits = 1,
 	.val_bits = 24,
+	.write_flag_mask = 0x80,

 	.max_register = MC13XXX_NUMREGS,

@@ -73,7 +74,6 @@

 	dev_set_drvdata(&spi->dev, mc13xxx);
 	spi->mode = SPI_MODE_0 | SPI_CS_HIGH;
-	spi->bits_per_word = 32;

 	mc13xxx->dev = &spi->dev;
 	mutex_init(&mc13xxx->lock);


mmc: mvsdio: add pinctrl integration

mmc: mvsdio: add pinctrl integration

On many Marvell SoCs, the pins used for the SDIO interface are part of
the MPP pins, that are muxable pins. In order to get the muxing of
those pins correct, this commit integrates the mvsdio driver with the
pinctrl infrastructure by calling devm_pinctrl_get_select_default()
during ->probe().

Note that we permit this function to fail because not all Marvell
platforms have yet been fully converted to using the pinctrl
infrastructure.

Signed-off-by: Thomas Petazzoni <a5d87d2bd7c424ee5cbdb4e978635bf653d5a005@free-electrons.com>
Signed-off-by: Andrew Lunn <02e0a999c50b1f88df7a8f5a04e1b76b35ea6a88@lunn.ch>
Tested-by: Stefan Peter <8c85a02258ac67d7b307616c18c8320737f15370@mpl.ch>
Tested-by: Florian Fainelli <73262ad0334ab37227b2f7a0205f51db1e606681@openwrt.org>
Signed-off-by: Jason Cooper <68c46a606457643eab92053c1c05574abb26f861@lakedaemon.net>
Signed-off-by: Chris Ball <6ca7faee6ca9a094b1ee341f11b840a5608a8746@laptop.org>

--- drivers/mmc/host/mvsdio.c
+++ drivers/mmc/host/mvsdio.c
@@ -25,6 +25,7 @@
 #include <linux/of_irq.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/slot-gpio.h>
+#include <linux/pinctrl/consumer.h>

 #include <asm/sizes.h>
 #include <asm/unaligned.h>
@@ -690,6 +691,7 @@
 	struct resource *r;
 	int ret, irq;
 	int gpio_card_detect, gpio_write_protect;
+	struct pinctrl *pinctrl;

 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(pdev, 0);
@@ -705,6 +707,10 @@
 	host = mmc_priv(mmc);
 	host->mmc = mmc;
 	host->dev = &pdev->dev;
+
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl))
+		dev_warn(&pdev->dev, "no pins associated\n");

 	/*
 	 * Some non-DT platforms do not pass a clock, and the clock


[MTD] cmdlinepart: Missing partition info is not an error

Return 0 partitions instead of -EINVAL on no mtdpart= argument in kernel
cmdline or missing partition info for device.

Signed-off-by: Peter Korsgaard <109eb201e07c93b5f5b6b8c6537366649a85e9a2@sunsite.dk>
Acked-by: Stefan Roese <44b7497c4bb5f3e8c071b12b7ece82766a88068d@denx.de>
Signed-off-by: David Woodhouse <97b3379caa91f4ee97e44013ae4dc6350540fa9d@infradead.org>

--- drivers/mtd/cmdlinepart.c
+++ drivers/mtd/cmdlinepart.c
@@ -309,9 +309,6 @@
 	int i;
 	struct cmdline_mtd_partition *part;
 	char *mtd_id = master->name;
-
-	if(!cmdline)
-		return -EINVAL;

 	/* parse command line */
 	if (!cmdline_parsed)
@@ -343,7 +340,7 @@
 			return part->num_parts;
 		}
 	}
-	return -EINVAL;
+	return 0;
 }


mtd: elm: compile suspend/resume only with PM_SLEEP

Fixes:
drivers/mtd/devices/elm.c:480:12: warning: 'elm_suspend' defined but not used [-Wunused-function]
drivers/mtd/devices/elm.c:488:12: warning: 'elm_resume' defined but not used [-Wunused-function]

Signed-off-by: Wolfram Sang <fd4ce474653598159cad06f3c83387a05cd53a44@sang-engineering.com>
Acked-by: Pekon Gupta <9c832910b22e9984746268496e467a6536ae8491@ti.com>
Signed-off-by: Brian Norris <ac73eed4b8a8c9127255a2696c52b2e7503720b8@gmail.com>

--- drivers/mtd/devices/elm.c
+++ drivers/mtd/devices/elm.c
@@ -418,6 +418,7 @@
 	return 0;
 }

+#ifdef CONFIG_PM_SLEEP
 /**
  * elm_context_save
  * saves ELM configurations to preserve them across Hardware powered-down
@@ -509,6 +510,7 @@
 	elm_context_restore(info);
 	return 0;
 }
+#endif

 static SIMPLE_DEV_PM_OPS(elm_pm_ops, elm_suspend, elm_resume);


UBI: Fastmap: Remove bogus ubi_assert()

UBI: Fastmap: Remove bogus ubi_assert()

It is legal to have PEBs left in the used list.
This can happen if UBI copies a PEB and a powercut happens
between writing a new fastmap and adding this PEB into the EBA table.
In this case the old PEB will be used.

Signed-off-by: Richard Weinberger <320bca71fc381a4a025636043ca86e734e31cf8b@nod.at>

--- drivers/mtd/ubi/fastmap.c
+++ drivers/mtd/ubi/fastmap.c
@@ -814,7 +814,9 @@
 	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list)
 		list_move_tail(&tmp_aeb->u.list, &ai->free);

-	ubi_assert(list_empty(&used));
+	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list)
+		list_move_tail(&tmp_aeb->u.list, &ai->erase);
+
 	ubi_assert(list_empty(&eba_orphans));
 	ubi_assert(list_empty(&free));


Create keyboard.c

Create keyboard.c

error: pathspec 'tools/src/disturber/baremetal/smallos/src_c/keyboard.c' did not match any file(s) known to git

--- tools/src/disturber/baremetal/smallos/src_c/keyboard.c
+++ tools/src/disturber/baremetal/smallos/src_c/keyboard.c
@@ -0,0 +1,301 @@
+/******************************************************************************
+
+  Copyright (c) 2001-2009, Intel Corporation
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   3. Neither the name of the Intel Corporation nor the names of its
+      contributors may be used to endorse or promote products derived from
+      this software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  POSSIBILITY OF SUCH DAMAGE.
+
+******************************************************************************/
+/*
+ * This file contains the keyboard related functions.
+ *
+ * We maintain a circular buffer for keyboard input.
+ * When a thread requests data we just make data available in the
+ * circular buffer to whoever requests it.
+ *
+ */
+
+#include <param.h>
+#include <multiboot.h>
+#include <utilities.h>
+#include <segments.h>
+#include <page.h>
+#include <console.h>
+#include <video.h>
+#include <mp.h>
+#include <keyboard.h>
+
+extern struct lwConsole defConsole;
+volatile u8 keyBoardBuffer[KEYBOARD_BUFFER_SZ];
+volatile u32 keyIndx;
+volatile u8 escapePressed;
+volatile u32 numCharsInBuffer;
+volatile u8 shiftPressed;
+volatile u8 capsLockPressed;
+volatile u8 numLockPressed;
+
+/*
+ * We will provide two functions for user entities to interface
+ * a getchar () and get_keypress ();
+ *
+ * Both of these will
+
+/*
+ * These are the scan codes.
+ */
+
+u8 no_shift_scan_map[] = {0x00,ESC_CODE,'1','2','3','4','5','6','7','8','9','0',
+  		  '-','=',BS,'\t','q','w','e','r','t','y','u',
+			  'i','o','p','[',']',NEWLINE,LEFT_CTRL,'a','s',
+			  'd','f','g','h','j','k','l',';',QUOTE,BACK_QUOTE,
+			  LEFT_SHIFT,BACK_SLASH,'z','x','c','v','b','n',
+			  'm',',','.','/',RIGHT_SHIFT,PRINT_SCREEN,
+			  LEFT_ALT,' ',CAPS_LOCK};
+
+
+u8 shift_scan_map[] = {0x00,ESC_CODE,'!','@','#','$','%','^','&','*','(',')',
+		       '_','+',BS,'\t','Q','W','E','R','T','Y','U',
+		       'I','O','P','{','}',NEWLINE,LEFT_CTRL,'A','S',
+		       'D','F','G','H','J','K','L',':',DBL_QUOTE,BACK_QUOTE,
+		       LEFT_SHIFT,BACK_SLASH,'Z','X','C','V','B','N',
+		       'M','<','>','?',RIGHT_SHIFT,PRINT_SCREEN,
+		       LEFT_ALT,' ',CAPS_LOCK};
+
+
+/*
+ * MAP the numlock elements to what we need.
+ */
+u8 numKBDScan[] = {'7','8','9','-','4','5','6','+','1','2','3','0','.'};
+u8 numKBDScanNoLock[] = {KP_HOME, KP_UP, KP_PGUP,'-',
+			KP_LEFT, '5',KP_RIGHT, '+',
+			KP_END, KP_DOWN, KP_PGDN, KP_INS, KP_DELETE};
+
+
+/*
+ * In the ISR we grab all the data we can get in the buffer.
+ * All scan codes are put in. We don't capture break codes.
+ *
+ * It will be up to the processing code to translate this to appropriate
+ * keypress codes. Whether they consist of single or multiple key strokes.
+ * We also store escape codes, but we don't store escape codes for key release.
+ */
+
+
+void kbcISR(registers_t regs)
+{
+  u8 scan_code;
+
+  scan_code = inb(KEYBOARD_PORT);
+
+  /*
+   * The general process is some to look at the input code
+   * and determine what to do.
+   */
+  switch (scan_code)
+    {
+    case KBD_ERROR:
+      break;
+    case ESCAPE_CODE:
+      if (escapePressed==FALSE)
+	{
+	  escapePressed = TRUE;
+	  keyBoardBuffer[keyIndx] = scan_code;
+	  INC_KEYINDX(keyIndx);
+	  numCharsInBuffer++;
+	}
+      else
+	{
+	  escapePressed = FALSE;
+	}
+      break;
+    case NUM_LOCK_PRESSED:
+    case NUM_LOCK_UNPRESSED:
+    case CAPS_LOCK_PRESSED:
+    case CAPS_LOCK_UNPRESSED:
+    case LEFT_SHIFT_UNPRESSED:
+    case RIGHT_SHIFT_UNPRESSED:
+      keyBoardBuffer[keyIndx] = scan_code;
+      INC_KEYINDX(keyIndx);
+      numCharsInBuffer++;
+      break;
+    default:
+      if (!(scan_code & KBD_BREAK_MASK))
+	{
+	  keyBoardBuffer[keyIndx] = scan_code;
+	  INC_KEYINDX(keyIndx);
+	  numCharsInBuffer++;
+	}
+      break;
+    }
+  return;
+
+} /* kbcISR */
+
+
+void kbcInit()
+{
+
+  keyIndx = 0;
+  escapePressed = FALSE;
+  numCharsInBuffer = 0;
+  shiftPressed = FALSE;
+  capsLockPressed = FALSE;
+}
+
+
+/*
+ * Set the keyboard buffer.
+ */
+
+void setKeyboardBuffer (struct lwConsole *console)
+{
+
+  console->keyBuffer = keyBoardBuffer;
+
+}
+
+/*
+ * Ideally we want to create a proper keyboard map that will return the
+ * right set of characters.
+ *
+ * In short a keyboard state machine that will iterate and produce the
+ * right keycodes as necessary.
+ *
+ * But right now we shall not do that.
+ * So we will just make a simple state machine that will check the following
+ * - Key shift
+ * - Capslock
+ * - Numlock
+ *
+ * We will also return a limited number of control codes
+ * Ctrl-C, Ctrl-D, Ctrl-X, Ctrl-A, Ctrl-k, Ctrl-L
+ *
+ */
+
+
+unsigned char kbd_getchar (struct lwConsole *cons)
+{
+
+  u8 nxtChar;
+
+  /*
+   * First check whether we have any more character to read
+   * If not we return 0x00.
+   */
+  //  if (numCharsInBuffer <= 0)
+  // {
+  //  return 0x00;
+  //}
+
+  while (numCharsInBuffer <= 0);
+
+  nxtChar = cons->keyBuffer[cons->keyBufferOutIndx];
+  INC_KEYINDX(cons->keyBufferOutIndx);
+  numCharsInBuffer--;
+
+  switch (nxtChar)
+    {
+    case LEFT_SHIFT:
+    case RIGHT_SHIFT:
+      if (capsLockPressed)
+	{
+	  shiftPressed = SHIFT_UNPRESSED;
+	}
+      else
+	shiftPressed = SHIFT_PRESSED;
+      break;
+    case LEFT_SHIFT_UNPRESSED:
+    case RIGHT_SHIFT_UNPRESSED:
+      shiftPressed = SHIFT_UNPRESSED;
+      break;
+    case ESCAPE_CODE:
+      if (escapePressed == TRUE)
+	escapePressed = FALSE;
+      else
+	{
+	  escapePressed = TRUE;
+
+	  if (numCharsInBuffer <=0)
+	    {
+	      return 0x00;
+	    }
+	  numCharsInBuffer--;
+	  nxtChar = cons->keyBuffer[cons->keyBufferOutIndx];
+	  INC_KEYINDX(cons->keyBufferOutIndx);
+	}
+      break;
+    case NUM_LOCK_PRESSED:
+      numLockPressed = TRUE;
+      break;
+    case NUM_LOCK_UNPRESSED:
+      numLockPressed = FALSE;
+      break;
+    case CAPS_LOCK_PRESSED:
+      capsLockPressed = TRUE;
+      break;
+    case CAPS_LOCK_UNPRESSED:
+      capsLockPressed = FALSE;
+      break;
+    default:
+      /* Here we deal with the translations.
+       * As said before what we really nead is a state machine that just
+       * steps through the key combinations and returns the right key codes.
+       * But for now we will have this ugly hack,
+       *
+       * Wo what we do is to check which map array we need to pick and return
+       * the key from there. Otherwise we just return a 0x00.
+       */
+      /*
+       * If the keys are in the shift range then map it against the shift maps.
+       */
+      if ((nxtChar >= SHIFT_RANGE_START) && (nxtChar <= SHIFT_RANGE_END))
+	{
+	  if (shiftPressed == SHIFT_PRESSED)
+	    {
+	      return (shift_scan_map[nxtChar]);
+	    }
+	  else
+	    return (no_shift_scan_map[nxtChar]);
+	}
+      /* If we are in the numlock range, then lookup the numlok map.
+       */
+      if ((nxtChar >= KEYPAD_HOME_7) && (nxtChar <= KEYPAD_DEL_DOT))
+	{
+	  if (numLockPressed)
+	    {
+	      return (numKBDScan[nxtChar - KEYPAD_HOME_7]);
+	    }
+	  else
+	    {
+	      return (numKBDScanNoLock[nxtChar-KEYPAD_HOME_7]);
+	    }
+
+	}
+    } /* End of switch */
+  return 0x00;
+
+} /* kbd_getchar */


Seprated the value setting from _map_memory to _map_value.

--- drivers/mysql/dbd_mysql.c
+++ drivers/mysql/dbd_mysql.c
@@ -221,23 +221,20 @@
 void _map_memory(dbi_row_t *row, const char *raw, const long len, int idx)
 {
 	if(row->field_types[idx] == DBI_TYPE_INTEGER){
-		if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE4){
+		if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE2)
+			row->field_values[idx] = malloc(sizeof(char));
+		else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE3)
 			row->field_values[idx] = malloc(sizeof(short));
-			if(row->field_type_attributes[idx] & DBI_INTEGER_UNSIGNED)
-				*((unsigned short*)row->field_values[idx]) = (unsigned short) atoi(raw);
-			else
-				*((short*)row->field_values[idx]) = (short) atoi(raw);
-		} else {
+		else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE4)
 			row->field_values[idx] = malloc(sizeof(long));
-			*((long*)row->field_values[idx]) = (long) atol(raw);
-		}
+		else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE8)
+			row->field_values[idx] = malloc(sizeof(long long));
 	}else if(row->field_types[idx] == DBI_TYPE_DECIMAL){
+
 		if(row->field_type_attributes[idx] & DBI_DECIMAL_SIZE4){
 			row->field_values[idx] = malloc(sizeof(float));
-			*((float*)row->field_values[idx]) = atof(raw);
 		}else{
 			row->field_values[idx] = malloc(sizeof(double));
-			*((double*)row->field_values[idx]) = atof(raw);
 		}

 	} else if(row->field_types[idx] == DBI_TYPE_STRING){
@@ -248,12 +245,9 @@

 			*((void**)row->field_values[idx]) = malloc(sizeof(char) * len);

-			memcpy( *( (void**) row->field_values[idx] ), (void*)raw, len);
-			row->field_type_attributes[idx] = len;
 		} else {
 			row->field_values[idx] = malloc(sizeof(char*));
 			*((char**)row->field_values[idx]) = malloc(sizeof(char) *(len+1));
-			strcpy(*((char**)row->field_values[idx]), raw);
 		}
 	}
 }
@@ -262,21 +256,41 @@
 /* _MAP_VALUE                                                                */
 /*****************************************************************************/
 /*
- * Precondtion: str2 != NULL
- * Postcondition: str1 is freed if not null
+ * Precondtion: row != NULL, idx is legal index of row->field_*, row->
+ * 		field_values[idx] has been correctly allocated
+ * Postcondition: sets
  * Returns: A newly allocated copy of str2
  */
+
 void _map_value(dbi_row_t *row, const char *raw, const long len, int idx)
 {
 	if(row->field_types[idx] == DBI_TYPE_INTEGER){
-		if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE4){
+		if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE2){
 			if(row->field_type_attributes[idx] & DBI_INTEGER_UNSIGNED)
+				*((unsigned char*)row->field_values[idx]) = (unsigned char) atoi(raw);
+			else
+				*((char*)row->field_values[idx]) = (char) atoi(raw);
+
+		}else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE3){
+			if(row->field_type_attributes[idx] & DBI_INTEGER_UNSIGNED){
 				*((unsigned short*)row->field_values[idx]) = (unsigned short) atoi(raw);
+			}else
+				*((short*)row->field_values[idx]) = (short) atoi(raw);
+
+		}else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE4){
+			if(row->field_type_attributes[idx] & DBI_INTEGER_UNSIGNED)
+				*((unsigned long*)row->field_values[idx]) = (unsigned long) atoi(raw);
 			else
-				*((short*)row->field_values[idx]) = (short) atoi(raw);
-		} else {
-			*((long*)row->field_values[idx]) = (long) atol(raw);
+				*((long*)row->field_values[idx]) = (long) atoi(raw);
+
+		}else if(row->field_type_attributes[idx] & DBI_INTEGER_SIZE8){
+			if(row->field_type_attributes[idx] & DBI_INTEGER_UNSIGNED)
+				*((unsigned long long*)row->field_values[idx]) = (unsigned long long) atoll(raw);
+			else
+				*((long long*)row->field_values[idx]) = (long long) atoll(raw);
+
 		}
+
 	}else if(row->field_types[idx] == DBI_TYPE_DECIMAL){
 		if(row->field_type_attributes[idx] & DBI_DECIMAL_SIZE4){
 			*((float*)row->field_values[idx]) = atof(raw);
@@ -604,12 +618,10 @@
 		if(len[i] != 0 && *myrow != NULL)
 			memcpy((void*)string, *(myrow)[i], len[i]);

-		fprintf(stderr, "Debugging Statement (sorry): String Value [%s]\n",
-				string);
-
 		row->field_types[i] = _map_type(myfield[i].type);
 		row->field_type_attributes[i] = _map_type_attributes(myfield[i].type);
 		_map_memory(row, string, len[i], i);
+		_map_value(row, string, len[i], i);

 		free(string);
 		string = NULL;


drivers/net/can: Correct NULL test

drivers/net/can: Correct NULL test

Test the just-allocated value for NULL rather than some other value.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,y;
statement S;
@@

x = \(kmalloc\|kcalloc\|kzalloc\)(...);
(
if ((x) == NULL) S
|
if (
-   y
+   x
       == NULL)
 S
)
// </smpl>

Signed-off-by: Julia Lawall <b43b0ad1e8108e7ab870d7a54feac93ae8b8600e@diku.dk>
Acked-by: Oliver Hartkopp <c539153ba1f947bd4b6f910263b967c4a0a62357@hartkopp.net>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/can/mcp251x.c
+++ drivers/net/can/mcp251x.c
@@ -990,7 +990,7 @@
 			goto error_tx_buf;
 		}
 		priv->spi_rx_buf = kmalloc(SPI_TRANSFER_BUF_LEN, GFP_KERNEL);
-		if (!priv->spi_tx_buf) {
+		if (!priv->spi_rx_buf) {
 			ret = -ENOMEM;
 			goto error_rx_buf;
 		}


cxgb3: fix 2 ports 1G regression

cxgb3: fix 2 ports 1G regression

commit 88045b3cf0f8981129cb489c7b6bc36c21dd33a7
	cxgb3: fix mac index mapping

	Override the mac index computation for the gen2 adapter,
	as each port is expected to use index 0.

introduces a regression on 2 port 1G adapter
as its xauicfg vpd value is null.
Add a check on the device id.

Signed-off-by: Divy Le Ray <c440f8554972344360c4411616466cde120c39c9@chelsio.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/cxgb3/t3_hw.c
+++ drivers/net/cxgb3/t3_hw.c
@@ -3692,8 +3692,12 @@

 void mac_prep(struct cmac *mac, struct adapter *adapter, int index)
 {
+	u16 devid;
+
 	mac->adapter = adapter;
-	if (!adapter->params.vpd.xauicfg[1])
+	pci_read_config_word(adapter->pdev, 0x2, &devid);
+
+	if (devid == 0x37 && !adapter->params.vpd.xauicfg[1])
 		index = 0;
 	mac->offset = (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR) * index;
 	mac->nucast = 1;


net: dp83640: fix broken calibration routine.

Currently, the calibration function that corrects the initial offsets
among multiple devices only works the first time.  If the function is
called more than once, the calibration fails and bogus offsets will be
programmed into the devices.

In a well hidden spot, the device documentation tells that trigger indexes
0 and 1 are special in allowing the TRIG_IF_LATE flag to actually work.

This patch fixes the issue by using one of the special triggers during the
recalibration method.

Signed-off-by: Richard Cochran <e27030aebe9cad8817d34b8c31dbaf301fb798b9@gmail.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>


net: ppp_generic - use DEFINE_IDR for static initialization

We could use DEFINE_IDR for statically allocated idr
that allow us to save a few lines of code.

And spell fix.

Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@openvz.org>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/ppp_generic.c
+++ drivers/net/ppp_generic.c
@@ -179,7 +179,7 @@
  */
 static DEFINE_MUTEX(all_ppp_mutex);
 static atomic_t ppp_unit_count = ATOMIC_INIT(0);
-static struct idr ppp_units_idr;
+static DEFINE_IDR(ppp_units_idr);

 /*
  * all_channels_lock protects all_channels and last_channel_index,
@@ -852,8 +852,6 @@
 			      "ppp");
 	}

-	idr_init(&ppp_units_idr);
-
 out:
 	if (err)
 		printk(KERN_ERR "failed to register PPP device (%d)\n", err);
@@ -2435,7 +2433,7 @@
 		if (unit_find(&ppp_units_idr, unit))
 			goto out2; /* unit already exists */
 		else {
-			/* darn, someone is cheatting us? */
+			/* darn, someone is cheating us? */
 			*retp = -EINVAL;
 			goto out2;
 		}


intel-iommu: Defer the iotlb flush and iova free for intel_unmap_sg() too.

I see no reason why we did this _only_ in intel_unmap_page().

Signed-off-by: David Woodhouse <b460d66aaf00c296a3db1c1d9eeafc081d5f7d70@intel.com>

--- drivers/pci/intel-iommu.c
+++ drivers/pci/intel-iommu.c
@@ -2815,11 +2815,18 @@
 	/* free page tables */
 	dma_pte_free_pagetable(domain, start_pfn, last_pfn);

-	iommu_flush_iotlb_psi(iommu, domain->id, start_pfn,
-			      (last_pfn - start_pfn + 1));
-
-	/* free iova */
-	__free_iova(&domain->iovad, iova);
+	if (intel_iommu_strict) {
+		iommu_flush_iotlb_psi(iommu, domain->id, start_pfn,
+				      last_pfn - start_pfn + 1);
+		/* free iova */
+		__free_iova(&domain->iovad, iova);
+	} else {
+		add_unmap(domain, iova);
+		/*
+		 * queue up the release of the unmap to save the 1/6th of the
+		 * cpu used up by the iotlb flush operation...
+		 */
+	}
 }

 static int intel_nontranslate_map_sg(struct device *hddev,


intel-iommu: fix compile warnings

intel-iommu: fix compile warnings

Impact: cleanup

I got the following warnings on IA64:

  linux-2.6/drivers/pci/intel-iommu.c: In function 'init_dmars':
  linux-2.6/drivers/pci/intel-iommu.c:1658: warning: format '%Lx' expects type 'long long unsigned int', but argument 2 has type 'u64'
  linux-2.6/drivers/pci/intel-iommu.c:1663: warning: format '%Lx' expects type 'long long unsigned int', but argument 2 has type 'u64'

Another victim of int-ll64.h versus int-l64.h confusion between platforms.

->reg_base_addr has a type of u64 - which can only be printed out
consistently if we cast its type up to LL.

[ Eventually reg_base_addr should be converted to phys_addr_t, for which
  we have the %pR printk helper - but that is out of the scope of late
  -rc's. ]

Signed-off-by: FUJITA Tomonori <93dac1fe9c4b2a3957982200319981492ad4976e@lab.ntt.co.jp>
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@elte.hu>

--- drivers/pci/intel-iommu.c
+++ drivers/pci/intel-iommu.c
@@ -1655,12 +1655,14 @@
 			iommu->flush.flush_context = __iommu_flush_context;
 			iommu->flush.flush_iotlb = __iommu_flush_iotlb;
 			printk(KERN_INFO "IOMMU 0x%Lx: using Register based "
-			       "invalidation\n", drhd->reg_base_addr);
+			       "invalidation\n",
+			       (unsigned long long)drhd->reg_base_addr);
 		} else {
 			iommu->flush.flush_context = qi_flush_context;
 			iommu->flush.flush_iotlb = qi_flush_iotlb;
 			printk(KERN_INFO "IOMMU 0x%Lx: using Queued "
-			       "invalidation\n", drhd->reg_base_addr);
+			       "invalidation\n",
+			       (unsigned long long)drhd->reg_base_addr);
 		}
 	}


sofd: skip strcpy in case of same source and destination

--- dgl/src/sofd/libsofd.c
+++ dgl/src/sofd/libsofd.c
@@ -1257,7 +1257,8 @@
 	} else {
 		int i;
 		struct dirent *de;
-		strcpy (_cur_path, path);
+		if (path != _cur_path)
+			strcpy (_cur_path, path);

 		if (_cur_path[strlen (_cur_path) -1] != '/')
 			strcat (_cur_path, "/");


Fix pg_dump so pg_upgrade'ing an extension with simple opfamilies works.

As reported by Michael Feld, pg_upgrade'ing an installation having
extensions with operator families that contain just a single operator class
failed to reproduce the extension membership of those operator families.
This caused no immediate ill effects, but would create problems when later
trying to do a plain dump and restore, because the seemingly-not-part-of-
the-extension operator families would appear separately in the pg_dump
output, and then would conflict with the families created by loading the
extension.  This has been broken ever since extensions were introduced,
and many of the standard contrib extensions are affected, so it's a bit
astonishing nobody complained before.

The cause of the problem is a perhaps-ill-considered decision to omit
such operator families from pg_dump's output on the grounds that the
CREATE OPERATOR CLASS commands could recreate them, and having explicit
CREATE OPERATOR FAMILY commands would impede loading the dump script into
pre-8.3 servers.  Whatever the merits of that decision when 8.3 was being
written, it looks like a poor tradeoff now.  We can fix the pg_upgrade
problem simply by removing that code, so that the operator families are
dumped explicitly (and then will be properly made to be part of their
extensions).

Although this fixes the behavior of future pg_upgrade runs, it does nothing
to clean up existing installations that may have improperly-linked operator
families.  Given the small number of complaints to date, maybe we don't
need to worry about providing an automated solution for that; anyone who
needs to clean it up can do so with manual "ALTER EXTENSION ADD OPERATOR
FAMILY" commands, or even just ignore the duplicate-opfamily errors they
get during a pg_restore.  In any case we need this fix.

Back-patch to all supported branches.

Discussion: <0ac1f701478c780678fc50c39be248ebb679264e@sss.pgh.pa.us>

--- src/bin/pg_dump/pg_dump.c
+++ src/bin/pg_dump/pg_dump.c
@@ -10860,9 +10860,7 @@
 	appendPQExpBuffer(q, "FOR TYPE %s USING %s",
 					  opcintype,
 					  fmtId(amname));
-	if (strlen(opcfamilyname) > 0 &&
-		(strcmp(opcfamilyname, opcinfo->dobj.name) != 0 ||
-		 strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0))
+	if (strlen(opcfamilyname) > 0)
 	{
 		appendPQExpBufferStr(q, " FAMILY ");
 		if (strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0)
@@ -11145,15 +11143,6 @@
 	if (!opfinfo->dobj.dump || dataOnly)
 		return;

-	/*
-	 * We want to dump the opfamily only if (1) it contains "loose" operators
-	 * or functions, or (2) it contains an opclass with a different name or
-	 * owner.  Otherwise it's sufficient to let it be created during creation
-	 * of the contained opclass, and not dumping it improves portability of
-	 * the dump.  Since we have to fetch the loose operators/funcs anyway, do
-	 * that first.
-	 */
-
 	query = createPQExpBuffer();
 	q = createPQExpBuffer();
 	delq = createPQExpBuffer();
@@ -11235,40 +11224,6 @@
 					  opfinfo->dobj.catId.oid);

 	res_procs = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
-
-	if (PQntuples(res_ops) == 0 && PQntuples(res_procs) == 0)
-	{
-		/* No loose members, so check contained opclasses */
-		resetPQExpBuffer(query);
-
-		appendPQExpBuffer(query, "SELECT 1 "
-						  "FROM pg_catalog.pg_opclass c, pg_catalog.pg_opfamily f, pg_catalog.pg_depend "
-						  "WHERE f.oid = '%u'::pg_catalog.oid "
-			"AND refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
-						  "AND refobjid = f.oid "
-				"AND classid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
-						  "AND objid = c.oid "
-						  "AND (opcname != opfname OR opcnamespace != opfnamespace OR opcowner != opfowner) "
-						  "LIMIT 1",
-						  opfinfo->dobj.catId.oid);
-
-		res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
-
-		if (PQntuples(res) == 0)
-		{
-			/* no need to dump it, so bail out */
-			PQclear(res);
-			PQclear(res_ops);
-			PQclear(res_procs);
-			destroyPQExpBuffer(query);
-			destroyPQExpBuffer(q);
-			destroyPQExpBuffer(delq);
-			destroyPQExpBuffer(labelq);
-			return;
-		}
-
-		PQclear(res);
-	}

 	/* Get additional fields from the pg_opfamily row */
 	resetPQExpBuffer(query);


Fix timeouts

Fix timeouts

--- applications/mosaic-harness/sources/mosaic_harness.c
+++ applications/mosaic-harness/sources/mosaic_harness.c
@@ -95,7 +95,7 @@
 };

 unsigned int const _timeout_slice = 100;
-unsigned int const _timeout_waitpid = 2 * 100;
+unsigned int const _timeout_waitpid = 6 * 1000;

 // ----------------------------------------


add nullability annotations to BBMediaPickerViewController.h

--- BBFrameworks/BBMediaPicker/BBMediaPickerViewController.h
+++ BBFrameworks/BBMediaPicker/BBMediaPickerViewController.h
@@ -17,6 +17,8 @@
 #import "BBMediaPickerDefines.h"
 #import "BBMediaPickerViewControllerDelegate.h"

+NS_ASSUME_NONNULL_BEGIN
+
 /**
  BBMediaPickerViewController is a UIViewController subclass that mirrors the media browsing functionality provided by UIImagePickerController.
  */
@@ -34,7 +36,7 @@

  @see BBMediaPickerViewControllerDelegate
  */
-@property (weak,nonatomic) id<BBMediaPickerViewControllerDelegate> delegate;
+@property (weak,nonatomic,nullable) id<BBMediaPickerViewControllerDelegate> delegate;

 /**
  Set and get whether the receiver allows multiple selection.
@@ -59,7 +61,7 @@

  The default is nil.
  */
-@property (copy,nonatomic) NSString *cancelBarButtonItemTitle;
+@property (copy,nonatomic,nullable) NSString *cancelBarButtonItemTitle;

 /**
  Set and get the allowed media types of the receiver.
@@ -77,7 +79,7 @@

  @see BBMediaPickerMediaFilterBlock
  */
-@property (copy,nonatomic) BBMediaPickerMediaFilterBlock mediaFilterBlock;
+@property (copy,nonatomic,nullable) BBMediaPickerMediaFilterBlock mediaFilterBlock;

 /**
  Set and get the cancel confirm block of the receiver. If non-nil, this will be invoked and the completion block value consulted before dismissing the receiver. This can be used to provide confirmation to the user before ending interaction with the receiver.
@@ -86,14 +88,14 @@

  @see BBMediaPickerCancelConfirmBlock
  */
-@property (copy,nonatomic) BBMediaPickerCancelConfirmBlock cancelConfirmBlock;
+@property (copy,nonatomic,nullable) BBMediaPickerCancelConfirmBlock cancelConfirmBlock;

 /**
  Set and get the asset bottom accessory view. If non-nil, this view is placed at the bottom of the asset collection view anchored to the bottom of its superview. It should implement the `sizeThatFits:` so its desired height can be determined. It will always have its width set to the width of its superview.

  The default is nil.
  */
-@property (strong,nonatomic) UIView *assetBottomAccessoryView;
+@property (strong,nonatomic,nullable) UIView *assetBottomAccessoryView;

 /**
  Returns the number of media objects being displayed.
@@ -114,7 +116,7 @@
  @param index The index of the media object to return
  @return The media object or nil
  */
-- (id<BBMediaPickerMedia>)mediaAtIndex:(NSInteger)index;
+- (nullable id<BBMediaPickerMedia>)mediaAtIndex:(NSInteger)index;

 /**
  Scrolls the collection view containing media so that it is visible, centered vertically. If the media does not exist in the collection view, does nothing.
@@ -138,3 +140,5 @@
 - (BBMediaPickerViewController *)BB_mediaPickerViewController;

 @end
+
+NS_ASSUME_NONNULL_END


Singleton: refactored, expand thread-safety.

--- Finagle/Singleton.h
+++ Finagle/Singleton.h
@@ -43,7 +43,6 @@
 class Singleton {
 public:
   Singleton( void );
-  Singleton( Type const &init );
  ~Singleton( void );

   Type &operator ()( void );
@@ -51,9 +50,10 @@

 private:
   Type &alloc( void );
-  Type &alloc( Type const &init );
+  void  free( void );

 private:
+  static Finagle::Mutex _guard;
   static unsigned _useCount;
   static TypePtr _inst;
 };
@@ -62,6 +62,9 @@

 template <typename Type, typename TypePtr>
 unsigned Singleton<Type, TypePtr>::_useCount = 0;
+
+template <typename Type, typename TypePtr>
+Finagle::Mutex Singleton<Type, TypePtr>::_guard;

 template <typename Type, typename TypePtr>
 TypePtr Singleton<Type, TypePtr>::_inst = 0;
@@ -74,32 +77,27 @@
 }

 template <typename Type, typename TypePtr>
-inline Singleton<Type, TypePtr>::Singleton( Type const &that )
-{
-  _useCount++;
-  _inst = new Type(that);
-}
-
-template <typename Type, typename TypePtr>
 inline Singleton<Type, TypePtr>::~Singleton( void )
 {
-  if ( _inst && !--_useCount ) {
-    delete _inst;
-    _inst = 0;
-  }
+  if ( _inst && !--_useCount )
+    free();
 }

 template <typename Type, typename TypePtr>
 inline Type &Singleton<Type, TypePtr>::operator ()( void )
 {
+  Finagle::Lock lock( _guard );
   return _inst ? *_inst : alloc();
 }

 template <typename Type, typename TypePtr>
 inline Type &Singleton<Type, TypePtr>::operator ()( Type *that )
 {
-  delete _inst;
-  _inst = that;
+  if ( that != _inst ) {
+    Finagle::Lock lock( _guard );
+    free();
+    _inst = that;
+  }
   return *_inst;
 }

@@ -107,13 +105,16 @@
 template <typename Type, typename TypePtr>
 Type &Singleton<Type, TypePtr>::alloc( void )
 {
-  static Finagle::Mutex guard;
-  Finagle::Lock lock( guard );
-
   if ( !_inst )
     _inst = new Type;
+  return *_inst;
+}

-  return *_inst;
+template <typename Type, typename TypePtr>
+void Singleton<Type, TypePtr>::free( void )
+{
+  delete _inst;
+  _inst = 0;
 }

 };


[DEBUG][io] use sleep instead of usleep

[DEBUG][io] use sleep instead of usleep

Change-Id: I7c804e9df6a53c5e2a36ac2b8d9a872e8b90cea1

--- libioutils/tests/io_src_pid_test.c
+++ libioutils/tests/io_src_pid_test.c
@@ -103,7 +103,7 @@
 	/* normal use cases */
 	ret = io_mon_init(&mon);
 	CU_ASSERT_EQUAL_FATAL(ret, 0);
-	pid = launch("usleep", "10000", NULL);
+	pid = launch("sleep", ".01", NULL);
 	CU_ASSERT_NOT_EQUAL_FATAL(pid, -1);
 	ret = io_src_pid_init(&pid_src, cb);
 	CU_ASSERT_EQUAL(ret, 0);
@@ -173,7 +173,7 @@
 	/* normal use cases */
 	ret = io_mon_init(&mon);
 	CU_ASSERT_EQUAL_FATAL(ret, 0);
-	pid = launch("usleep", "10000", NULL);
+	pid = launch("sleep", ".01", NULL);
 	CU_ASSERT_NOT_EQUAL_FATAL(pid, -1);
 	ret = io_src_pid_init(&pid_src, cb);
 	CU_ASSERT_EQUAL(ret, 0);
@@ -212,7 +212,7 @@

 	/* reuse the pid source */
 	process_dead = false;
-	pid = launch("usleep", "10000", NULL);
+	pid = launch("sleep", ".01", NULL);
 	CU_ASSERT_NOT_EQUAL_FATAL(pid, -1);
 	ret = io_src_pid_set_pid(&pid_src, pid);
 	CU_ASSERT_EQUAL(ret, 0);


whoops, one more pthread_getname_np

whoops, one more pthread_getname_np

https://github.com/facebook/libphenom/issues/38

--- corelib/log.c
+++ corelib/log.c
@@ -75,7 +75,7 @@
   tid = (uint64_t)(intptr_t)self;
 #endif

-#if defined(__linux__) || defined(__MACH__)
+#ifdef HAVE_PTHREAD_GETNAME_NP
   if (pthread_getname_np(pthread_self(), buf, size) == 0) {
     int len = strlen(buf);
     if (len > 0) {