[PATCH v2 13/23] staging: iio: tsl2583: change newlines to improve readability

2016-11-08 Thread Brian Masney
Add and remove newlines to improve code readability in preparation for
moving the driver out of staging.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 8be135b..eff59f37 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -202,7 +202,6 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
ret = i2c_smbus_write_byte(chip->client,
   (TSL2583_CMD_REG | TSL2583_CMD_SPL_FN |
TSL2583_CMD_ALS_INT_CLR));
-
if (ret < 0) {
dev_err(&chip->client->dev, "%s failed to clear the interrupt 
bit\n",
__func__);
@@ -225,8 +224,10 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
chip->als_cur_info.lux = 0;
goto done;
}
+
/* calculate ratio */
ratio = (ch1 << 15) / ch0;
+
/* convert to unscaled lux using the pointer to the table */
for (p = (struct tsl2583_lux *)tsl2583_device_lux;
 p->ratio != 0 && p->ratio < ratio; p++)
@@ -273,6 +274,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
lux64 >>= 13;
lux = lux64;
lux = (lux + 500) / 1000;
+
if (lux > TSL2583_LUX_CALC_OVER_FLOW) { /* check for overflow */
 return_max:
lux = TSL2583_LUX_CALC_OVER_FLOW;
@@ -318,20 +320,22 @@ static int tsl2583_als_calibrate(struct iio_dev 
*indio_dev)
"%s failed: STATUS - ADC not valid.\n", __func__);
return -ENODATA;
}
+
lux_val = tsl2583_get_lux(indio_dev);
if (lux_val < 0) {
dev_err(&chip->client->dev, "%s failed to get lux\n", __func__);
return lux_val;
}
+
gain_trim_val = (unsigned int)(((chip->als_settings.als_cal_target)
* chip->als_settings.als_gain_trim) / lux_val);
-
if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {
dev_err(&chip->client->dev,
"%s failed: trim_val of %d is not within the range 
[250, 4000]\n",
__func__, gain_trim_val);
return -ENODATA;
}
+
chip->als_settings.als_gain_trim = (int)gain_trim_val;
 
return (int)gain_trim_val;
@@ -525,6 +529,7 @@ static ssize_t in_illuminance_lux_table_show(struct device 
*dev,
}
 
offset += sprintf(buf + offset, "\n");
+
return offset;
 }
 
@@ -772,6 +777,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
if (!indio_dev)
return -ENOMEM;
+
chip = iio_priv(indio_dev);
chip->client = clientp;
i2c_set_clientdata(clientp, indio_dev);
@@ -799,6 +805,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
indio_dev->dev.parent = &clientp->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->name = chip->client->name;
+
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
if (ret) {
dev_err(&clientp->dev, "%s: iio registration failed\n",
@@ -815,6 +822,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
return ret;
 
dev_info(&clientp->dev, "Light sensor found.\n");
+
return 0;
 }
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 11/23] staging: iio: tsl2583: fix alignment of #define values

2016-11-08 Thread Brian Masney
Most of the values in the #defines have their values aligned on a single
column, but some do not. This changes the remaining defines to use
consistent alignment with the majority to improve code readability.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index d4cd143..ad6866a 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -44,19 +44,19 @@
 /* tsl2583 cmd reg masks */
 #define TSL2583_CMD_REG0x80
 #define TSL2583_CMD_SPL_FN 0x60
-#define TSL2583_CMD_ALS_INT_CLR0X01
+#define TSL2583_CMD_ALS_INT_CLR0x01
 
 /* tsl2583 cntrl reg masks */
-#define TSL2583_CNTL_ADC_ENBL  0x02
+#define TSL2583_CNTL_ADC_ENBL  0x02
 #define TSL2583_CNTL_PWR_OFF   0x00
 #define TSL2583_CNTL_PWR_ON0x01
 
 /* tsl2583 status reg masks */
-#define TSL2583_STA_ADC_VALID  0x01
-#define TSL2583_STA_ADC_INTR   0x10
+#define TSL2583_STA_ADC_VALID  0x01
+#define TSL2583_STA_ADC_INTR   0x10
 
 /* Lux calculation constants */
-#defineTSL2583_LUX_CALC_OVER_FLOW  65535
+#defineTSL2583_LUX_CALC_OVER_FLOW  65535
 
 #define TSL2583_INTERRUPT_DISABLED 0x00
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 02/23] staging: iio: tsl2583: fix issue with changes to calibscale and int_time not being set on the chip

2016-11-08 Thread Brian Masney
When updating the in_illuminance_calibscale and
in_illuminance_integration_time sysfs attributes, these values were not
actually written to the chip. The chip would continue to use the old
parameters. Extracted out tsl2583_set_als_gain() and
tsl2583_set_als_time() functions that are now called when these sysfs
attributes are updated. The chip initialization also calls these these
new functions.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 85 +++--
 1 file changed, 52 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index f17f919..cf5fd5f 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -352,6 +352,51 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
return (int)gain_trim_val;
 }
 
+static int tsl2583_set_als_time(struct tsl2583_chip *chip)
+{
+   int als_count, als_time, ret;
+   u8 val;
+
+   /* determine als integration register */
+   als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
+   if (!als_count)
+   als_count = 1; /* ensure at least one cycle */
+
+   /* convert back to time (encompasses overrides) */
+   als_time = (als_count * 27 + 5) / 10;
+
+   val = 256 - als_count;
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_ALS_TIME,
+   val);
+   if (ret < 0) {
+   dev_err(&chip->client->dev, "%s failed to set the als time to 
%d\n",
+   __func__, val);
+   return ret;
+   }
+
+   /* set chip struct re scaling and saturation */
+   chip->als_saturation = als_count * 922; /* 90% of full scale */
+   chip->als_time_scale = (als_time + 25) / 50;
+
+   return ret;
+}
+
+static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
+{
+   int ret;
+
+   /* Set the gain based on taos_settings struct */
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_GAIN,
+   chip->taos_settings.als_gain);
+   if (ret < 0)
+   dev_err(&chip->client->dev, "%s failed to set the gain to %d\n",
+   __func__, chip->taos_settings.als_gain);
+
+   return ret;
+}
+
 static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
 {
int ret;
@@ -371,10 +416,8 @@ static int tsl2583_set_power_state(struct tsl2583_chip 
*chip, u8 state)
  */
 static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 {
-   int ret, val;
-   int als_count;
-   int als_time;
struct tsl2583_chip *chip = iio_priv(indio_dev);
+   int ret;
 
/* and make sure we're not already on */
if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
@@ -397,37 +440,13 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev 
*indio_dev)
return ret;
}
 
-   /* determine als integration register */
-   als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
-   if (!als_count)
-   als_count = 1; /* ensure at least one cycle */
-
-   /* convert back to time (encompasses overrides) */
-   als_time = (als_count * 27 + 5) / 10;
-
-   val = 256 - als_count;
-   ret = i2c_smbus_write_byte_data(chip->client,
-   TSL258X_CMD_REG | TSL258X_ALS_TIME,
-   val);
-   if (ret < 0) {
-   dev_err(&chip->client->dev, "%s failed to set the als time to 
%d\n",
-   __func__, val);
+   ret = tsl2583_set_als_time(chip);
+   if (ret < 0)
return ret;
-   }
 
-   /* Set the gain based on taos_settings struct */
-   ret = i2c_smbus_write_byte_data(chip->client,
-   TSL258X_CMD_REG | TSL258X_GAIN,
-   chip->taos_settings.als_gain);
-   if (ret < 0) {
-   dev_err(&chip->client->dev, "%s failed to set the gain to %d\n",
-   __func__, chip->taos_settings.als_gain);
+   ret = tsl2583_set_als_gain(chip);
+   if (ret < 0)
return ret;
-   }
-
-   /* set chip struct re scaling and saturation */
-   chip->als_saturation = als_count * 922; /* 90% of full scale */
-   chip->als_time_scale = (als_time + 25) / 50;
 
usleep_range(3000, 3500);
 
@@ -707,7 +726,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
if (gainadj[i].mean == val) {
chip->taos_settings.als_gain = i;
-   ret = 0;
+   ret = ts

[PATCH v2 00/23] staging: iio: tsl2583: move out of staging

2016-11-08 Thread Brian Masney
The first 7 patches in this series contains version 2 of the patches
7-9 that I sent out on 2016-11-03. The only change is that the patches
are split up further to make the code review easier.

Patches 8-23 in this series are new and some of the highlights include:

- Moved from a global lux table to a per device lux table.
- Combined redundant sysfs ABI documentation
- Made log messages clearer
- Code style and formatting cleanups
- Staging graduation

I verified that the driver functions correctly using a TSL2581 hooked up
to a Raspberry Pi 2.

Brian Masney (23):
  staging: iio: tsl2583: split out functionality of taos_chip_on()
  staging: iio: tsl2583: fix issue with changes to calibscale and
int_time not being set on the chip
  staging: iio: tsl2583: check if chip is suspended in
in_illuminance_calibrate_store
  staging: iio: tsl2583: remove unnecessary chip status check in
taos_get_lux
  staging: iio: tsl2583: remove unnecessary chip status checks in
suspend/resume
  staging: iio: tsl2583: change current chip state from a tristate to a
bool
  staging: iio: tsl2583: remove redundant write to the control register
in taos_probe()
  staging: iio: tsl2583: remove the FSF's mailing address
  staging: iio: tsl2583: cleaned up logging
  staging: iio: tsl2583: unify function and variable prefix to tsl2583_
  staging: iio: tsl2583: fix alignment of #define values
  staging: iio: tsl2583: fix comparison between signed and unsigned
integers
  staging: iio: tsl2583: change newlines to improve readability
  staging: iio: tsl2583: combine sysfs documentation
  staging: iio: tsl2583: fix multiline comment syntax
  staging: iio: tsl2583: updated code comment to match what the code
does
  staging: iio: tsl2583: moved code block inside else statement
  staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on
success
  staging: iio: tsl2583: remove unnecessary parentheses
  staging: iio: tsl2583: don't assume an unsigned int is 32 bits
  staging: iio: tsl2583: move from a global to a per device lux table
  staging: iio: tsl2583: updated copyright and MODULE_AUTHOR
  staging: iio: tsl2583: move out of staging

 .../ABI/testing/sysfs-bus-iio-light-tsl2583|  20 +
 drivers/iio/light/Kconfig  |   7 +
 drivers/iio/light/Makefile |   1 +
 drivers/iio/light/tsl2583.c| 916 +
 .../light/sysfs-bus-iio-light-tsl2583  |   6 -
 .../iio/Documentation/sysfs-bus-iio-light-tsl2583  |  20 -
 drivers/staging/iio/light/Kconfig  |   7 -
 drivers/staging/iio/light/Makefile |   1 -
 drivers/staging/iio/light/tsl2583.c| 892 
 9 files changed, 944 insertions(+), 926 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
 create mode 100644 drivers/iio/light/tsl2583.c
 delete mode 100644 
drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
 delete mode 100644 
drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583
 delete mode 100644 drivers/staging/iio/light/tsl2583.c

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 07/23] staging: iio: tsl2583: remove redundant write to the control register in taos_probe()

2016-11-08 Thread Brian Masney
taos_probe() calls i2c_smbus_write_byte() to select the control
register, however there are no subsequent calls to
i2c_smbus_read_byte(). The write call is unnecessary and is removed by
this patch.

Verified that the driver still functions correctly using a TSL2581
hooked up to a Raspberry Pi 2.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 9880e41..0f5f544 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -788,14 +788,6 @@ static int taos_probe(struct i2c_client *clientp,
return -EINVAL;
}
 
-   ret = i2c_smbus_write_byte(clientp, (TSL258X_CMD_REG | TSL258X_CNTRL));
-   if (ret < 0) {
-   dev_err(&clientp->dev,
-   "i2c_smbus_write_byte() to cmd reg failed in 
taos_probe(), err = %d\n",
-   ret);
-   return ret;
-   }
-
indio_dev->info = &tsl2583_info;
indio_dev->channels = tsl2583_channels;
indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 08/23] staging: iio: tsl2583: remove the FSF's mailing address

2016-11-08 Thread Brian Masney
Address warning from checkpatch:

CHECK: Do not include the paragraph about writing to the Free Software
Foundation's mailing address from the sample GPL notice. The FSF has
changed addresses in the past, and may do so again. Linux already
includes a copy of the GPL.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 0f5f544..a03f845 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -13,10 +13,6 @@
  * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 04/23] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux

2016-11-08 Thread Brian Masney
taos_get_lux checks to see if the chip is in a working state. This
check is not necessary since it is only called from tsl2583_read_raw
and in_illuminance_calibrate_store (via taos_als_calibrate). The chip
state is already checked by these functions.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 6c46253..2a3db3f 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -178,13 +178,6 @@ static int taos_get_lux(struct iio_dev *indio_dev)
u32 ch0lux = 0;
u32 ch1lux = 0;
 
-   if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
-   /* device is not enabled */
-   dev_err(&chip->client->dev, "taos_get_lux device is not 
enabled\n");
-   ret = -EBUSY;
-   goto done;
-   }
-
ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
if (ret < 0) {
dev_err(&chip->client->dev, "taos_get_lux failed to read 
CMD_REG\n");
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 03/23] staging: iio: tsl2583: check if chip is suspended in in_illuminance_calibrate_store

2016-11-08 Thread Brian Masney
in_illuminance_calibrate_store() did not check to see if the chip is
suspended. This patch adds the proper check. The return value from
taos_als_calibrate() was also not checked in this function, so the
proper check was also added while changes are being made here.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index cf5fd5f..6c46253 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -501,16 +501,27 @@ static ssize_t in_illuminance_calibrate_store(struct 
device *dev,
 {
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
-   int value;
+   int value, ret;
 
if (kstrtoint(buf, 0, &value) || value != 1)
return -EINVAL;
 
mutex_lock(&chip->als_mutex);
-   taos_als_calibrate(indio_dev);
+
+   if (chip->suspended) {
+   ret = -EBUSY;
+   goto done;
+   }
+
+   ret = taos_als_calibrate(indio_dev);
+   if (ret < 0)
+   goto done;
+
+   ret = len;
+done:
mutex_unlock(&chip->als_mutex);
 
-   return len;
+   return ret;
 }
 
 static ssize_t in_illuminance_lux_table_show(struct device *dev,
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging

2016-11-08 Thread Brian Masney
There are several places in the code where the function name is
hardcoded in the log message. Use the __func__ constant string to build
the log message. This also clarifies some of the error messages to match
the code and ensures that the correct priority is used since the message
is already being changed.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 51 ++---
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index a03f845..c797ab0 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 
ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
if (ret < 0) {
-   dev_err(&chip->client->dev, "taos_get_lux failed to read 
CMD_REG\n");
+   dev_err(&chip->client->dev, "%s failed to read CMD_REG 
register\n",
+   __func__);
goto done;
}
 
/* is data new & valid */
if (!(ret & TSL258X_STA_ADC_INTR)) {
-   dev_err(&chip->client->dev, "taos_get_lux data not valid\n");
+   dev_err(&chip->client->dev, "%s: data not valid; returning last 
value\n",
+   __func__);
ret = chip->als_cur_info.lux; /* return LAST VALUE */
goto done;
}
@@ -186,9 +188,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 
ret = i2c_smbus_read_byte_data(chip->client, reg);
if (ret < 0) {
-   dev_err(&chip->client->dev,
-   "taos_get_lux failed to read register %x\n",
-   reg);
+   dev_err(&chip->client->dev, "%s failed to read register 
%x\n",
+   __func__, reg);
goto done;
}
buf[i] = ret;
@@ -203,9 +204,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
TSL258X_CMD_ALS_INT_CLR));
 
if (ret < 0) {
-   dev_err(&chip->client->dev,
-   "taos_i2c_write_command failed in taos_get_lux, err = 
%d\n",
-   ret);
+   dev_err(&chip->client->dev, "%s failed to clear the interrupt 
bit\n",
+   __func__);
goto done; /* have no data, so return failure */
}
 
@@ -246,7 +246,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 
/* note: lux is 31 bit max at this point */
if (ch1lux > ch0lux) {
-   dev_dbg(&chip->client->dev, "No Data - Return last value\n");
+   dev_dbg(&chip->client->dev, "%s: No Data - Returning 0\n",
+   __func__);
ret = 0;
chip->als_cur_info.lux = 0;
goto done;
@@ -309,16 +310,17 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
if ((ret & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
dev_err(&chip->client->dev,
-   "taos_als_calibrate failed: device not powered on with 
ADC enabled\n");
+   "%s failed: device not powered on with ADC enabled\n",
+   __func__);
return -EINVAL;
} else if ((ret & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
dev_err(&chip->client->dev,
-   "taos_als_calibrate failed: STATUS - ADC not valid.\n");
+   "%s failed: STATUS - ADC not valid.\n", __func__);
return -ENODATA;
}
lux_val = taos_get_lux(indio_dev);
if (lux_val < 0) {
-   dev_err(&chip->client->dev, "taos_als_calibrate failed to get 
lux\n");
+   dev_err(&chip->client->dev, "%s failed to get lux\n", __func__);
return lux_val;
}
gain_trim_val = (unsigned int)(((chip->taos_settings.als_cal_target)
@@ -326,8 +328,8 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 
if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {
dev_err(&chip->client->dev,
-   "taos_als_calibrate failed: trim_val of %d is out of 
range\n",
-   gain_trim_val);
+   "%s failed: trim_val of %d is not within the range 
[250, 4000]\n",
+   __func__, gain_trim_val);
return -ENODATA;
}
chip->taos_settings.als_gain_trim = (int)gain_trim_val;
@@ -526,6 +528,8 @@ static ssize_t in_illuminance_lux_table_show(struct device 
*dev,
return offset;
 }
 
+#define TSL2583_MAX_LUX_INTS ((ARRAY_SIZE(taos_device_lux) - 1) * 3)
+
 static ssize_t in_illuminance_lux_table_store(struct device *dev,
 

[PATCH v2 05/23] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume

2016-11-08 Thread Brian Masney
The device probing and the suspend/resume code checks a flag internal to
the driver that determines whether or not the chip is in a working
state. These checks are not needed. This patch removes the unnecessary
checks. It will do no harm to the hardware if the chip is
reinitialized if it is already powered on.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 16 +++-
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 2a3db3f..3be2213 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -412,13 +412,6 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev 
*indio_dev)
struct tsl2583_chip *chip = iio_priv(indio_dev);
int ret;
 
-   /* and make sure we're not already on */
-   if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
-   /* if forcing a register update - turn off, then on */
-   dev_info(&chip->client->dev, "device is already enabled\n");
-   return -EINVAL;
-   }
-
/* Power on the device; ADC off. */
ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
if (ret < 0)
@@ -842,10 +835,8 @@ static int taos_suspend(struct device *dev)
 
mutex_lock(&chip->als_mutex);
 
-   if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
-   ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
-   chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
-   }
+   ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
+   chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
 
mutex_unlock(&chip->als_mutex);
return ret;
@@ -859,8 +850,7 @@ static int taos_resume(struct device *dev)
 
mutex_lock(&chip->als_mutex);
 
-   if (chip->taos_chip_status == TSL258X_CHIP_SUSPENDED)
-   ret = tsl2583_chip_init_and_power_on(indio_dev);
+   ret = tsl2583_chip_init_and_power_on(indio_dev);
 
mutex_unlock(&chip->als_mutex);
return ret;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 12/23] staging: iio: tsl2583: fix comparison between signed and unsigned integers

2016-11-08 Thread Brian Masney
Fixed warning found by make W=2:

warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index ad6866a..8be135b 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -506,7 +506,7 @@ static ssize_t in_illuminance_lux_table_show(struct device 
*dev,
 struct device_attribute *attr,
 char *buf)
 {
-   int i;
+   unsigned int i;
int offset = 0;
 
for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
@@ -537,7 +537,8 @@ static ssize_t in_illuminance_lux_table_store(struct device 
*dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
int value[ARRAY_SIZE(tsl2583_device_lux) * 3 + 1];
-   int n, ret = -EINVAL;
+   int ret = -EINVAL;
+   unsigned int n;
 
mutex_lock(&chip->als_mutex);
 
@@ -715,7 +716,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_CALIBSCALE:
if (chan->type == IIO_LIGHT) {
-   int i;
+   unsigned int i;
 
for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
if (gainadj[i].mean == val) {
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 01/23] staging: iio: tsl2583: split out functionality of taos_chip_on()

2016-11-08 Thread Brian Masney
taos_chip_on() reads an eight member array called taos_config
that contains the desired state of the chip's registers. Only four
of the registers actually need to be written to. The four that do
not need to be written to are for the {low,high} byte of the lower
interrupt threshold and the {low,high} byte of the upper interrupt
threshold. Interrupts are currently not supported by this driver
so there is no need to write to these registers.

This patch removes the taos_config array and separates out the
i2c calls that write to the CONTROL, TIMING, INTERRUPT and ANALOG
registers. This is part of a larger refactor that was split up to
make the code review easier.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 122 +---
 1 file changed, 58 insertions(+), 64 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 7eab17f..f17f919 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -31,9 +31,6 @@
 #include 
 #include 
 
-/* Triton register offsets */
-#defineTSL258X_REG_MAX 8
-
 /* Device Registers and Masks */
 #define TSL258X_CNTRL  0x00
 #define TSL258X_ALS_TIME   0X01
@@ -55,6 +52,7 @@
 
 /* tsl2583 cntrl reg masks */
 #define TSL258X_CNTL_ADC_ENBL  0x02
+#define TSL258X_CNTL_PWR_OFF   0x00
 #define TSL258X_CNTL_PWR_ON0x01
 
 /* tsl2583 status reg masks */
@@ -64,6 +62,8 @@
 /* Lux calculation constants */
 #defineTSL258X_LUX_CALC_OVER_FLOW  65535
 
+#define TSL2583_INTERRUPT_DISABLED 0x00
+
 #define TSL2583_CHIP_ID0x90
 #define TSL2583_CHIP_ID_MASK   0xf0
 
@@ -95,18 +95,8 @@ struct tsl2583_chip {
int als_time_scale;
int als_saturation;
int taos_chip_status;
-   u8 taos_config[8];
 };
 
-/*
- * Initial values for device - this values can/will be changed by driver.
- * and applications as needed.
- * These values are dynamic.
- */
-static const u8 taos_config[8] = {
-   0x00, 0xee, 0x00, 0x03, 0x00, 0xFF, 0xFF, 0x00
-}; /*  cntrl atime intC  Athl0 Athl1 Athh0 Athh1 gain */
-
 struct taos_lux {
unsigned int ratio;
unsigned int ch0;
@@ -362,16 +352,26 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
return (int)gain_trim_val;
 }
 
+static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
+{
+   int ret;
+
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_CNTRL, state);
+   if (ret < 0)
+   dev_err(&chip->client->dev, "%s failed to set the power state 
to %d\n",
+   __func__, state);
+
+   return ret;
+}
+
 /*
  * Turn the device on.
  * Configuration must be set before calling this function.
  */
-static int taos_chip_on(struct iio_dev *indio_dev)
+static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 {
-   int i;
-   int ret;
-   u8 *uP;
-   u8 utmp;
+   int ret, val;
int als_count;
int als_time;
struct tsl2583_chip *chip = iio_priv(indio_dev);
@@ -383,6 +383,20 @@ static int taos_chip_on(struct iio_dev *indio_dev)
return -EINVAL;
}
 
+   /* Power on the device; ADC off. */
+   ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
+   if (ret < 0)
+   return ret;
+
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_INTERRUPT,
+   TSL2583_INTERRUPT_DISABLED);
+   if (ret < 0) {
+   dev_err(&chip->client->dev, "%s failed to disable interrupts\n",
+   __func__);
+   return ret;
+   }
+
/* determine als integration register */
als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
if (!als_count)
@@ -390,62 +404,43 @@ static int taos_chip_on(struct iio_dev *indio_dev)
 
/* convert back to time (encompasses overrides) */
als_time = (als_count * 27 + 5) / 10;
-   chip->taos_config[TSL258X_ALS_TIME] = 256 - als_count;
+
+   val = 256 - als_count;
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_ALS_TIME,
+   val);
+   if (ret < 0) {
+   dev_err(&chip->client->dev, "%s failed to set the als time to 
%d\n",
+   __func__, val);
+   return ret;
+   }
 
/* Set the gain based on taos_settings struct */
-   chip->taos_config[TSL258X_GAIN] = chip->taos_settings.als_gain;
+   ret = i2c_smbus_write_byte_data(chip->client,
+   TSL258X_CMD_REG | TSL258X_GAIN,
+   chip->taos_settings.als_gain);
+   i

[PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR

2016-11-08 Thread Brian Masney
Added Brian Masney's copyright to the header and to the MODULE_AUTHOR
for all of the staging cleanups that has been done to this driver.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 013e7f6..5cb4ae3 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -3,6 +3,7 @@
  * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
  *
  * Copyright (c) 2011, TAOS Corporation.
+ * Copyright (c) 2016 Brian Masney 
  *
  * 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
@@ -910,6 +911,6 @@ static struct i2c_driver tsl2583_driver = {
 };
 module_i2c_driver(tsl2583_driver);
 
-MODULE_AUTHOR("J. August Brenner");
+MODULE_AUTHOR("J. August Brenner  and Brian Masney 
");
 MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
 MODULE_LICENSE("GPL");
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 20/23] staging: iio: tsl2583: don't assume an unsigned int is 32 bits

2016-11-08 Thread Brian Masney
in_illuminance_lux_table_store assumes that an unsigned int is 32 bits.
Replace this with sizeof(unsigned int).

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 29153fa..6644374 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -574,7 +574,7 @@ static ssize_t in_illuminance_lux_table_store(struct device 
*dev,
 
/* Zero out the table */
memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
-   memcpy(tsl2583_device_lux, &value[1], value[0] * 4);
+   memcpy(tsl2583_device_lux, &value[1], value[0] * sizeof(unsigned int));
 
ret = len;
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 14/23] staging: iio: tsl2583: combine sysfs documentation

2016-11-08 Thread Brian Masney
There are two separate files describing the tsl2583 sysfs attributes.
Combine the two files into one. Updated the name of the sysfs attributes
to match the current ABI.

Signed-off-by: Brian Masney 
Suggested-by: Peter Meerwald-Stadler 
---
 .../Documentation/light/sysfs-bus-iio-light-tsl2583  | 16 +++-
 .../iio/Documentation/sysfs-bus-iio-light-tsl2583| 20 
 2 files changed, 15 insertions(+), 21 deletions(-)
 delete mode 100644 
drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583

diff --git 
a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 
b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
index 470f7ad..a2e1996 100644
--- a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
+++ b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
@@ -1,6 +1,20 @@
-What:  /sys/bus/iio/devices/device[n]/in_illuminance0_calibrate
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_calibrate
 KernelVersion: 2.6.37
 Contact:   linux-...@vger.kernel.org
 Description:
This property causes an internal calibration of the als gain 
trim
value which is later used in calculating illuminance in lux.
+
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_lux_table
+KernelVersion: 2.6.37
+Contact:   linux-...@vger.kernel.org
+Description:
+   This property gets/sets the table of coefficients
+   used in calculating illuminance in lux.
+
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_input_target
+KernelVersion: 2.6.37
+Contact:   linux-...@vger.kernel.org
+Description:
+   This property is the known externally illuminance (in lux).
+   It is used in the process of calibrating the device accuracy.
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583 
b/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583
deleted file mode 100644
index 660781d..000
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583
+++ /dev/null
@@ -1,20 +0,0 @@
-What:  /sys/bus/iio/devices/device[n]/lux_table
-KernelVersion: 2.6.37
-Contact:   linux-...@vger.kernel.org
-Description:
-   This property gets/sets the table of coefficients
-   used in calculating illuminance in lux.
-
-What:  /sys/bus/iio/devices/device[n]/illuminance0_calibrate
-KernelVersion: 2.6.37
-Contact:   linux-...@vger.kernel.org
-Description:
-   This property causes an internal calibration of the als gain 
trim
-   value which is later used in calculating illuminance in lux.
-
-What:  /sys/bus/iio/devices/device[n]/illuminance0_input_target
-KernelVersion: 2.6.37
-Contact:   linux-...@vger.kernel.org
-Description:
-   This property is the known externally illuminance (in lux).
-   It is used in the process of calibrating the device accuracy.
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 10/23] staging: iio: tsl2583: unify function and variable prefix to tsl2583_

2016-11-08 Thread Brian Masney
Some functions and variables were prefixed with either taos, tsl258x or
tsl2583. Change everything to use the tsl2583 prefix since that is the
name of the .c file. The taos_settings member inside the taos_settings
struct was renamed to als_settings.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 208 ++--
 1 file changed, 104 insertions(+), 104 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index c797ab0..d4cd143 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -28,35 +28,35 @@
 #include 
 
 /* Device Registers and Masks */
-#define TSL258X_CNTRL  0x00
-#define TSL258X_ALS_TIME   0X01
-#define TSL258X_INTERRUPT  0x02
-#define TSL258X_GAIN   0x07
-#define TSL258X_REVID  0x11
-#define TSL258X_CHIPID 0x12
-#define TSL258X_ALS_CHAN0LO0x14
-#define TSL258X_ALS_CHAN0HI0x15
-#define TSL258X_ALS_CHAN1LO0x16
-#define TSL258X_ALS_CHAN1HI0x17
-#define TSL258X_TMR_LO 0x18
-#define TSL258X_TMR_HI 0x19
+#define TSL2583_CNTRL  0x00
+#define TSL2583_ALS_TIME   0X01
+#define TSL2583_INTERRUPT  0x02
+#define TSL2583_GAIN   0x07
+#define TSL2583_REVID  0x11
+#define TSL2583_CHIPID 0x12
+#define TSL2583_ALS_CHAN0LO0x14
+#define TSL2583_ALS_CHAN0HI0x15
+#define TSL2583_ALS_CHAN1LO0x16
+#define TSL2583_ALS_CHAN1HI0x17
+#define TSL2583_TMR_LO 0x18
+#define TSL2583_TMR_HI 0x19
 
 /* tsl2583 cmd reg masks */
-#define TSL258X_CMD_REG0x80
-#define TSL258X_CMD_SPL_FN 0x60
-#define TSL258X_CMD_ALS_INT_CLR0X01
+#define TSL2583_CMD_REG0x80
+#define TSL2583_CMD_SPL_FN 0x60
+#define TSL2583_CMD_ALS_INT_CLR0X01
 
 /* tsl2583 cntrl reg masks */
-#define TSL258X_CNTL_ADC_ENBL  0x02
-#define TSL258X_CNTL_PWR_OFF   0x00
-#define TSL258X_CNTL_PWR_ON0x01
+#define TSL2583_CNTL_ADC_ENBL  0x02
+#define TSL2583_CNTL_PWR_OFF   0x00
+#define TSL2583_CNTL_PWR_ON0x01
 
 /* tsl2583 status reg masks */
-#define TSL258X_STA_ADC_VALID  0x01
-#define TSL258X_STA_ADC_INTR   0x10
+#define TSL2583_STA_ADC_VALID  0x01
+#define TSL2583_STA_ADC_INTR   0x10
 
 /* Lux calculation constants */
-#defineTSL258X_LUX_CALC_OVER_FLOW  65535
+#defineTSL2583_LUX_CALC_OVER_FLOW  65535
 
 #define TSL2583_INTERRUPT_DISABLED 0x00
 
@@ -64,13 +64,13 @@
 #define TSL2583_CHIP_ID_MASK   0xf0
 
 /* Per-device data */
-struct taos_als_info {
+struct tsl2583_als_info {
u16 als_ch0;
u16 als_ch1;
u16 lux;
 };
 
-struct taos_settings {
+struct tsl2583_settings {
int als_time;
int als_gain;
int als_gain_trim;
@@ -80,14 +80,14 @@ struct taos_settings {
 struct tsl2583_chip {
struct mutex als_mutex;
struct i2c_client *client;
-   struct taos_als_info als_cur_info;
-   struct taos_settings taos_settings;
+   struct tsl2583_als_info als_cur_info;
+   struct tsl2583_settings als_settings;
int als_time_scale;
int als_saturation;
bool suspended;
 };
 
-struct taos_lux {
+struct tsl2583_lux {
unsigned int ratio;
unsigned int ch0;
unsigned int ch1;
@@ -96,7 +96,7 @@ struct taos_lux {
 /* This structure is intentionally large to accommodate updates via sysfs. */
 /* Sized to 11 = max 10 segments + 1 termination segment */
 /* Assumption is one and only one type of glass used  */
-static struct taos_lux taos_device_lux[11] = {
+static struct tsl2583_lux tsl2583_device_lux[11] = {
{  9830,  8520, 15729 },
{ 12452, 10807, 23344 },
{ 14746,  6383, 11705 },
@@ -121,25 +121,25 @@ static const struct gainadj gainadj[] = {
  * Provides initial operational parameter defaults.
  * These defaults may be changed through the device's sysfs files.
  */
-static void taos_defaults(struct tsl2583_chip *chip)
+static void tsl2583_defaults(struct tsl2583_chip *chip)
 {
/*
 * The integration time must be a multiple of 50ms and within the
 * range [50, 600] ms.
 */
-   chip->taos_settings.als_time = 100;
+   chip->als_settings.als_time = 100;
 
/*
 * This is an index into the gainadj table. Assume clear glass as the
 * default.
 */
-   chip->taos_settings.als_gain = 0;
+   chip->als_settings.als_gain = 0;
 
/* Default gain trim to account for aperture effects */
-   chip->taos_settings.als_gain_trim = 1000;
+   chip->als_settings.als_gain_trim = 1000;
 
/* Known external ALS reading used for calibration */
- 

[PATCH v2 15/23] staging: iio: tsl2583: fix multiline comment syntax

2016-11-08 Thread Brian Masney
The definition of the tsl2583_device_lux struct has a series of single
line comments. There are two other cases where the multiline comments
did not have an initial blank line. Change these comments to use the
proper multiline syntax.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index eff59f37..5ef403c 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -93,9 +93,11 @@ struct tsl2583_lux {
unsigned int ch1;
 };
 
-/* This structure is intentionally large to accommodate updates via sysfs. */
-/* Sized to 11 = max 10 segments + 1 termination segment */
-/* Assumption is one and only one type of glass used  */
+/*
+ * This structure is intentionally large to accommodate updates via sysfs.
+ * Sized to 11 = max 10 segments + 1 termination segment. Assumption is that
+ * one and only one type of glass used.
+ */
 static struct tsl2583_lux tsl2583_device_lux[11] = {
{  9830,  8520, 15729 },
{ 12452, 10807, 23344 },
@@ -261,7 +263,8 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
lux = (lux + (chip->als_time_scale >> 1)) /
chip->als_time_scale;
 
-   /* Adjust for active gain scale.
+   /*
+* Adjust for active gain scale.
 * The tsl2583_device_lux tables above have a factor of 8192 built in,
 * so we need to shift right.
 * User-specified gain provides a multiplier.
@@ -549,7 +552,8 @@ static ssize_t in_illuminance_lux_table_store(struct device 
*dev,
 
get_options(buf, ARRAY_SIZE(value), value);
 
-   /* We now have an array of ints starting at value[1], and
+   /*
+* We now have an array of ints starting at value[1], and
 * enumerated by value[0].
 * We expect each group of three ints is one table entry,
 * and the last table entry is all 0.
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 18/23] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success

2016-11-08 Thread Brian Masney
tsl2583_als_calibrate() returns the newly computed gain_trim if the
calibration was successful. This function is only called by
in_illuminance_calibrate_store() and the return value inside that
sysfs attribute is only checked to see if an error was returned.
This patch changes tsl2583_als_calibrate() to return 0 on success.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 5cdfe06..f1c9bb9 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -342,7 +342,7 @@ static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
 
chip->als_settings.als_gain_trim = (int)gain_trim_val;
 
-   return (int)gain_trim_val;
+   return 0;
 }
 
 static int tsl2583_set_als_time(struct tsl2583_chip *chip)
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 17/23] staging: iio: tsl2583: moved code block inside else statement

2016-11-08 Thread Brian Masney
The check for ch1lux > ch0lux inside tsl2583_get_lux is only valid if
the ratio is not equal to zero. Move the code block inside the else
statement. This does away with the need to initialize the variables to
zero.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 8d9176d..5cdfe06 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -167,8 +167,6 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
struct tsl2583_lux *p;
struct tsl2583_chip *chip = iio_priv(indio_dev);
int i, ret;
-   u32 ch0lux = 0;
-   u32 ch1lux = 0;
 
ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
if (ret < 0) {
@@ -238,22 +236,25 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
if (p->ratio == 0) {
lux = 0;
} else {
+   u32 ch0lux, ch1lux;
+
ch0lux = ((ch0 * p->ch0) +
  (gainadj[chip->als_settings.als_gain].ch0 >> 1))
 / gainadj[chip->als_settings.als_gain].ch0;
ch1lux = ((ch1 * p->ch1) +
  (gainadj[chip->als_settings.als_gain].ch1 >> 1))
 / gainadj[chip->als_settings.als_gain].ch1;
-   lux = ch0lux - ch1lux;
-   }
 
-   /* note: lux is 31 bit max at this point */
-   if (ch1lux > ch0lux) {
-   dev_dbg(&chip->client->dev, "%s: No Data - Returning 0\n",
-   __func__);
-   ret = 0;
-   chip->als_cur_info.lux = 0;
-   goto done;
+   /* note: lux is 31 bit max at this point */
+   if (ch1lux > ch0lux) {
+   dev_dbg(&chip->client->dev, "%s: No Data - Returning 
0\n",
+   __func__);
+   ret = 0;
+   chip->als_cur_info.lux = 0;
+   goto done;
+   }
+
+   lux = ch0lux - ch1lux;
}
 
/* adjust for active time scale */
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 06/23] staging: iio: tsl2583: change current chip state from a tristate to a bool

2016-11-08 Thread Brian Masney
The current chip state is represented as a tristate (working, suspended,
and unknown). The unknown state was not used. This patch changes the
chip state so that it is now represented as a single boolean value
(suspended).

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 3be2213..9880e41 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -67,12 +67,6 @@
 #define TSL2583_CHIP_ID0x90
 #define TSL2583_CHIP_ID_MASK   0xf0
 
-enum {
-   TSL258X_CHIP_UNKNOWN = 0,
-   TSL258X_CHIP_WORKING = 1,
-   TSL258X_CHIP_SUSPENDED = 2
-};
-
 /* Per-device data */
 struct taos_als_info {
u16 als_ch0;
@@ -94,7 +88,7 @@ struct tsl2583_chip {
struct taos_settings taos_settings;
int als_time_scale;
int als_saturation;
-   int taos_chip_status;
+   bool suspended;
 };
 
 struct taos_lux {
@@ -441,7 +435,7 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev 
*indio_dev)
if (ret < 0)
return ret;
 
-   chip->taos_chip_status = TSL258X_CHIP_WORKING;
+   chip->suspended = false;
 
return ret;
 }
@@ -627,7 +621,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 
mutex_lock(&chip->als_mutex);
 
-   if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+   if (chip->suspended) {
ret = -EBUSY;
goto read_done;
}
@@ -704,7 +698,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 
mutex_lock(&chip->als_mutex);
 
-   if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+   if (chip->suspended) {
ret = -EBUSY;
goto write_done;
}
@@ -778,7 +772,7 @@ static int taos_probe(struct i2c_client *clientp,
i2c_set_clientdata(clientp, indio_dev);
 
mutex_init(&chip->als_mutex);
-   chip->taos_chip_status = TSL258X_CHIP_UNKNOWN;
+   chip->suspended = true;
 
ret = i2c_smbus_read_byte_data(clientp,
   TSL258X_CMD_REG | TSL258X_CHIPID);
@@ -836,7 +830,7 @@ static int taos_suspend(struct device *dev)
mutex_lock(&chip->als_mutex);
 
ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
-   chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
+   chip->suspended = true;
 
mutex_unlock(&chip->als_mutex);
return ret;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 19/23] staging: iio: tsl2583: remove unnecessary parentheses

2016-11-08 Thread Brian Masney
in_illuminance_lux_table_store() contains some unnecessary parentheses.
This patch removes them since they provide no value.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index f1c9bb9..29153fa 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -566,7 +566,7 @@ static ssize_t in_illuminance_lux_table_store(struct device 
*dev,
__func__, TSL2583_MAX_LUX_INTS);
goto done;
}
-   if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
+   if ((value[n - 2] | value[n - 1] | value[n]) != 0) {
dev_err(dev, "%s: The last 3 entries in the lux table must be 
zeros.\n",
__func__);
goto done;
@@ -574,7 +574,7 @@ static ssize_t in_illuminance_lux_table_store(struct device 
*dev,
 
/* Zero out the table */
memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
-   memcpy(tsl2583_device_lux, &value[1], (value[0] * 4));
+   memcpy(tsl2583_device_lux, &value[1], value[0] * 4);
 
ret = len;
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 23/23] staging: iio: tsl2583: move out of staging

2016-11-08 Thread Brian Masney
Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline.

Signed-off-by: Brian Masney 
---
 .../ABI/testing/sysfs-bus-iio-light-tsl2583|  20 +
 drivers/iio/light/Kconfig  |   7 +
 drivers/iio/light/Makefile |   1 +
 drivers/iio/light/tsl2583.c| 916 +
 .../light/sysfs-bus-iio-light-tsl2583  |  20 -
 drivers/staging/iio/light/Kconfig  |   7 -
 drivers/staging/iio/light/Makefile |   1 -
 drivers/staging/iio/light/tsl2583.c| 916 -
 8 files changed, 944 insertions(+), 944 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
 create mode 100644 drivers/iio/light/tsl2583.c
 delete mode 100644 
drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
 delete mode 100644 drivers/staging/iio/light/tsl2583.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583 
b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
new file mode 100644
index 000..a2e1996
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
@@ -0,0 +1,20 @@
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_calibrate
+KernelVersion: 2.6.37
+Contact:   linux-...@vger.kernel.org
+Description:
+   This property causes an internal calibration of the als gain 
trim
+   value which is later used in calculating illuminance in lux.
+
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_lux_table
+KernelVersion: 2.6.37
+Contact:   linux-...@vger.kernel.org
+Description:
+   This property gets/sets the table of coefficients
+   used in calculating illuminance in lux.
+
+What:  /sys/bus/iio/devices/device[n]/in_illuminance_input_target
+KernelVersion: 2.6.37
+Contact:   linux-...@vger.kernel.org
+Description:
+   This property is the known externally illuminance (in lux).
+   It is used in the process of calibrating the device accuracy.
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index d011720..298ea50 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -338,6 +338,13 @@ config SENSORS_TSL2563
 This driver can also be built as a module.  If so, the module
 will be called tsl2563.
 
+config TSL2583
+   tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
+   depends on I2C
+   help
+Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
+Access ALS data via iio, sysfs.
+
 config TSL4531
tristate "TAOS TSL4531 ambient light sensors"
depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 15f24c5..4de5200 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_SI1145)  += si1145.o
 obj-$(CONFIG_STK3310)  += stk3310.o
 obj-$(CONFIG_TCS3414)  += tcs3414.o
 obj-$(CONFIG_TCS3472)  += tcs3472.o
+obj-$(CONFIG_TSL2583)  += tsl2583.o
 obj-$(CONFIG_TSL4531)  += tsl4531.o
 obj-$(CONFIG_US5182D)  += us5182d.o
 obj-$(CONFIG_VCNL4000) += vcnl4000.o
diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
new file mode 100644
index 000..5cb4ae3
--- /dev/null
+++ b/drivers/iio/light/tsl2583.c
@@ -0,0 +1,916 @@
+/*
+ * Device driver for monitoring ambient light intensity (lux)
+ * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
+ *
+ * Copyright (c) 2011, TAOS Corporation.
+ * Copyright (c) 2016 Brian Masney 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Device Registers and Masks */
+#define TSL2583_CNTRL  0x00
+#define TSL2583_ALS_TIME   0X01
+#define TSL2583_INTERRUPT  0x02
+#define TSL2583_GAIN   0x07
+#define TSL2583_REVID  0x11
+#define TSL2583_CHIPID 0x12
+#define TSL2583_ALS_CHAN0LO0x14
+#define TSL2583_ALS_CHAN0HI0x15
+#define TSL2583_ALS_CHAN1LO0x16
+#define TSL2583_ALS_CHAN1HI0x17
+#define TSL2583_TMR_LO 0x18
+#define TSL2583_TMR_HI 0x19
+
+/* tsl2583 cmd reg masks */
+#define TSL2583_CMD_REG0x80
+#d

[PATCH v2 21/23] staging: iio: tsl2583: move from a global to a per device lux table

2016-11-08 Thread Brian Masney
The driver contains a global lux table that can be updated via sysfs.
Change this to a per device lux table so that multiple devices can be
hooked up to the same system with different lux tables.

There are 10 entries, plus 1 for the termination segment, set aside for
the entries in the lux table. When updating the lux table via sysfs,
only 9 entries, plus the terminator, could be added. This changes
the code to allow for the 10 entries, plus the terminator.

Signed-off-by: Brian Masney 
---
I also included the change for the lux table size since I feel that it will
make the review of the overall change easier.

 drivers/staging/iio/light/tsl2583.c | 79 +
 1 file changed, 45 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 6644374..013e7f6 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -70,11 +70,32 @@ struct tsl2583_als_info {
u16 lux;
 };
 
+struct tsl2583_lux {
+   unsigned int ratio;
+   unsigned int ch0;
+   unsigned int ch1;
+};
+
+static const struct tsl2583_lux tsl2583_default_lux[] = {
+   {  9830,  8520, 15729 },
+   { 12452, 10807, 23344 },
+   { 14746,  6383, 11705 },
+   { 17695,  4063,  6554 },
+   { 0, 0, 0 }  /* Termination segment */
+};
+
 struct tsl2583_settings {
int als_time;
int als_gain;
int als_gain_trim;
int als_cal_target;
+
+   /*
+* This structure is intentionally large to accommodate updates via
+* sysfs. Sized to 11 = max 10 segments + 1 termination segment.
+* Assumption is that one and only one type of glass used.
+*/
+   struct tsl2583_lux als_device_lux[11];
 };
 
 struct tsl2583_chip {
@@ -87,24 +108,6 @@ struct tsl2583_chip {
bool suspended;
 };
 
-struct tsl2583_lux {
-   unsigned int ratio;
-   unsigned int ch0;
-   unsigned int ch1;
-};
-
-/*
- * This structure is intentionally large to accommodate updates via sysfs.
- * Sized to 11 = max 10 segments + 1 termination segment. Assumption is that
- * one and only one type of glass used.
- */
-static struct tsl2583_lux tsl2583_device_lux[11] = {
-   {  9830,  8520, 15729 },
-   { 12452, 10807, 23344 },
-   { 14746,  6383, 11705 },
-   { 17695,  4063,  6554 },
-};
-
 struct gainadj {
s16 ch0;
s16 ch1;
@@ -142,6 +145,10 @@ static void tsl2583_defaults(struct tsl2583_chip *chip)
 
/* Known external ALS reading used for calibration */
chip->als_settings.als_cal_target = 130;
+
+   /* Default lux table. */
+   memcpy(chip->als_settings.als_device_lux, tsl2583_default_lux,
+  sizeof(tsl2583_default_lux));
 }
 
 /*
@@ -151,7 +158,7 @@ static void tsl2583_defaults(struct tsl2583_chip *chip)
  * Time scale factor array values are adjusted based on the integration time.
  * The raw values are multiplied by a scale factor, and device gain is obtained
  * using gain index. Limit checks are done next, then the ratio of a multiple
- * of ch1 value, to the ch0 value, is calculated. The array 
tsl2583_device_lux[]
+ * of ch1 value, to the ch0 value, is calculated. The array als_device_lux[]
  * declared above is then scanned to find the first ratio value that is just
  * above the ratio we just calculated. The ch0 and ch1 multiplier constants in
  * the array are then used along with the time scale factor array values, to
@@ -229,7 +236,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
ratio = (ch1 << 15) / ch0;
 
/* convert to unscaled lux using the pointer to the table */
-   for (p = (struct tsl2583_lux *)tsl2583_device_lux;
+   for (p = (struct tsl2583_lux *)chip->als_settings.als_device_lux;
 p->ratio != 0 && p->ratio < ratio; p++)
;
 
@@ -266,7 +273,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
 
/*
 * Adjust for active gain scale.
-* The tsl2583_device_lux tables above have a factor of 8192 built in,
+* The tsl2583_default_lux tables above have a factor of 8192 built in,
 * so we need to shift right.
 * User-specified gain provides a multiplier.
 * Apply user-specified gain before shifting right to retain precision.
@@ -514,15 +521,17 @@ static ssize_t in_illuminance_lux_table_show(struct 
device *dev,
 struct device_attribute *attr,
 char *buf)
 {
+   struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+   struct tsl2583_chip *chip = iio_priv(indio_dev);
unsigned int i;
int offset = 0;
 
-   for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
+   for (i = 0; i < ARRAY_SIZE(chip->als_settings.als_device_lux); i++) {
offset += sprintf(buf + offset, "%u,%u,%u,",
- tsl2583_dev

[PATCH v2 16/23] staging: iio: tsl2583: updated code comment to match what the code does

2016-11-08 Thread Brian Masney
If channel 0 does not have any data, then the code sets the lux to zero.
The corresponding comment says that the last value is returned. This
updates the comment to correctly reflect what the code does.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2583.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 5ef403c..8d9176d 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -221,7 +221,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
goto return_max;
 
if (!ch0) {
-   /* have no data, so return LAST VALUE */
+   /* have no data, so return 0 */
ret = 0;
chip->als_cur_info.lux = 0;
goto done;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging

2016-11-08 Thread Joe Perches
On Tue, 2016-11-08 at 05:16 -0500, Brian Masney wrote:
> There are several places in the code where the function name is
> hardcoded in the log message. Use the __func__ constant string to build
> the log message. This also clarifies some of the error messages to match
> the code and ensures that the correct priority is used since the message
> is already being changed.
[]
> diff --git a/drivers/staging/iio/light/tsl2583.c 
> b/drivers/staging/iio/light/tsl2583.c
[]
> @@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  
>   ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
>   if (ret < 0) {
> - dev_err(&chip->client->dev, "taos_get_lux failed to read 
> CMD_REG\n");
> + dev_err(&chip->client->dev, "%s failed to read CMD_REG 
> register\n",
> + __func__);

Please use "%s: ", __func__ consistently

> @@ -545,12 +549,15 @@ static ssize_t in_illuminance_lux_table_store(struct 
> device *dev,
>* and the last table entry is all 0.
>*/
>   n = value[0];
> - if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
> - dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
> + if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
> + dev_err(dev,
> + "%s: The number of entries in the lux table must be a 
> multiple of 3 and within the range [6, %zu]",
> + __func__, TSL2583_MAX_LUX_INTS);

Missing terminating '\n"

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: vc04_services: Add 32-bit compatibility ioctls

2016-11-08 Thread Arnd Bergmann
On Monday, November 7, 2016 4:48:35 PM CET Michael Zoran wrote:
>  .../vc04_services/interface/vchiq_arm/vchiq_arm.c  | 269 
> +
>  .../vc04_services/interface/vchiq_arm/vchiq_if.h   |  25 ++
>  .../interface/vchiq_arm/vchiq_ioctl.h  | 102 
>  3 files changed, 396 insertions(+)
> 
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c 
> b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index 8fcd940..df343a0 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -573,12 +573,40 @@ vchiq_ioctl(struct file *file, unsigned int cmd, 
> unsigned long arg)
>   "vchiq: could not connect: %d", status);
>   break;
>  
> +#if defined(CONFIG_64BIT)
> + case VCHIQ_IOC_CREATE_SERVICE32:
> +#endif

>   case VCHIQ_IOC_CREATE_SERVICE: {
>   VCHIQ_CREATE_SERVICE_T args;
>   USER_SERVICE_T *user_service = NULL;
>   void *userdata;
>   int srvstate;
>  
> +#if defined(CONFIG_64BIT)
> + if (cmd == VCHIQ_IOC_CREATE_SERVICE32) {

Better use CONFIG_COMPAT here. Also, a simple #ifdef is sufficient
as neither of those symbols can be a loadable module.

Also, just move all the compat handling into the .compat_ioctl
callback function and move out the common parts into helpers
for simplicity.

> +#if defined(CONFIG_64BIT)
> + if (cmd == VCHIQ_IOC_AWAIT_COMPLETION32) {
> + VCHIQ_AWAIT_COMPLETION32_T args32;
> +
> + if (copy_from_user(&args32, (const void __user *)arg,
> +sizeof(args32)) != 0) {
> + ret = -EFAULT;
> + break;
> + }
> +
> + args.count = args32.count;
> + args.buf =
> + (VCHIQ_COMPLETION_DATA_T *)(unsigned long)
> + args32.buf;
> + args.msgbufsize = args32.msgbufsize;
> + args.msgbufcount = args32.msgbufcount;
> + args.msgbufs = (void **)(unsigned long)args32.msgbufs;
> + } else
> +#endif

There seems to be a bit of confusion about the address space
here. args.buf should be a user space pointer, right?

> +#if defined(CONFIG_64BIT)
> +typedef struct {
> + u32 data;
> + unsigned int size;
> +} VCHIQ_ELEMENT32_T;
> +#endif

remove the typedefs, it just forces someone to clean it up later.

>  #define VCHIQ_IOC_CONNECT  _IO(VCHIQ_IOC_MAGIC,   0)
>  #define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC,   1)
>  #define VCHIQ_IOC_CREATE_SERVICE \
>   _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
> +#if defined(CONFIG_64BIT)
> +#define VCHIQ_IOC_CREATE_SERVICE32 \
> + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE32_T)
> +#endif

No need for the #ifdef here.

Arnd

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: lustre: llite: use u64 instead of loff_t in lov_object_fiemap()

2016-11-08 Thread Xu, Bobijam
Change loff_t to u64 in lov_object_fiemap() since loff_t is a signed
value type.

Otherwise there could be an overflow in
drivers/staging/lustre/lustre/lov/lov_object.c:1241 lov_object_fiemap()
warn: signed overflow undefined. 'fm_start + fm_length < fm_start'

Reported-by: Dan Carpenter 
Signed-off-by: Bobi Jam 
---
 drivers/staging/lustre/lustre/lov/lov_object.c | 38 +-
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c 
b/drivers/staging/lustre/lustre/lov/lov_object.c
index 82b99e0..63bcc50 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -962,12 +962,12 @@ int lov_lock_init(const struct lu_env *env, struct 
cl_object *obj,
  * \retval last_stripe return the last stripe of the mapping
  */
 static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm,
-  loff_t fm_start, loff_t fm_end,
+  u64 fm_start, u64 fm_end,
   int start_stripe, int *stripe_count)
 {
int last_stripe;
-   loff_t obd_start;
-   loff_t obd_end;
+   u64 obd_start;
+   u64 obd_end;
int i, j;
 
if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
@@ -1035,14 +1035,14 @@ static void fiemap_prepare_and_copy_exts(struct fiemap 
*fiemap,
  * \param fm_end [in]  logical end of mapping
  * \param start_stripe [out]   starting stripe will be returned in this
  */
-static loff_t fiemap_calc_fm_end_offset(struct fiemap *fiemap,
-   struct lov_stripe_md *lsm,
-   loff_t fm_start, loff_t fm_end,
-   int *start_stripe)
+static u64 fiemap_calc_fm_end_offset(struct fiemap *fiemap,
+struct lov_stripe_md *lsm,
+u64 fm_start, u64 fm_end,
+int *start_stripe)
 {
-   loff_t local_end = fiemap->fm_extents[0].fe_logical;
-   loff_t lun_start, lun_end;
-   loff_t fm_end_offset;
+   u64 local_end = fiemap->fm_extents[0].fe_logical;
+   u64 lun_start, lun_end;
+   u64 fm_end_offset;
int stripe_no = -1;
int i;
 
@@ -1109,10 +1109,10 @@ static int lov_object_fiemap(const struct lu_env *env, 
struct cl_object *obj,
struct cl_object *subobj = NULL;
struct fiemap *fm_local = NULL;
struct lov_stripe_md *lsm;
-   loff_t fm_start;
-   loff_t fm_end;
-   loff_t fm_length;
-   loff_t fm_end_offset;
+   u64 fm_start;
+   u64 fm_end;
+   u64 fm_length;
+   u64 fm_end_offset;
int count_local;
int ost_index = 0;
int start_stripe;
@@ -1209,11 +1209,11 @@ static int lov_object_fiemap(const struct lu_env *env, 
struct cl_object *obj,
for (cur_stripe = start_stripe; stripe_count > 0;
 --stripe_count,
 cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
-   loff_t req_fm_len; /* Stores length of required mapping */
-   loff_t len_mapped_single_call;
-   loff_t lun_start;
-   loff_t lun_end;
-   loff_t obd_object_end;
+   u64 req_fm_len; /* Stores length of required mapping */
+   u64 len_mapped_single_call;
+   u64 lun_start;
+   u64 lun_end;
+   u64 obd_object_end;
unsigned int ext_count;
 
cur_stripe_wrap = cur_stripe;
-- 
2.10.2


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: lustre: llite: refactor lov_object_fiemap()

2016-11-08 Thread Xu, Bobijam
Add fiemap_for_stripe() to get file map extent from each stripe
device.

Signed-off-by: Bobi Jam 
---
 drivers/staging/lustre/lustre/lov/lov_object.c | 441 +
 1 file changed, 225 insertions(+), 216 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c 
b/drivers/staging/lustre/lustre/lov/lov_object.c
index 63bcc50..9c87d1e 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -1085,6 +1085,190 @@ static u64 fiemap_calc_fm_end_offset(struct fiemap 
*fiemap,
return fm_end_offset;
 }
 
+struct fiemap_state {
+   struct fiemap   *fs_fm;
+   u64 fs_start;
+   u64 fs_length;
+   u64 fs_end;
+   u64 fs_end_offset;
+   int fs_cur_extent;
+   int fs_cnt_need;
+   int fs_start_stripe;
+   int fs_last_stripe;
+   boolfs_device_done;
+   boolfs_finish;
+   boolfs_enough;
+};
+
+int fiemap_for_stripe(const struct lu_env *env, struct cl_object *obj,
+ struct lov_stripe_md *lsm,
+ struct fiemap *fiemap, size_t *buflen,
+ struct ll_fiemap_info_key *fmkey, int stripeno,
+ struct fiemap_state *fs)
+{
+   struct cl_object *subobj;
+   struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
+   struct fiemap_extent *fm_ext = &fs->fs_fm->fm_extents[0];
+   u64 req_fm_len; /* Stores length of required mapping */
+   u64 len_mapped_single_call;
+   u64 lun_start;
+   u64 lun_end;
+   u64 obd_object_end;
+   unsigned int ext_count;
+   /* EOF for object */
+   bool ost_eof = false;
+   /* done with required mapping for this OST? */
+   bool ost_done = false;
+   int ost_index;
+   int rc = 0;
+
+   fs->fs_device_done = false;
+   /* Find out range of mapping on this stripe */
+   if ((lov_stripe_intersects(lsm, stripeno, fs->fs_start, fs->fs_end,
+  &lun_start, &obd_object_end)) == 0)
+   return 0;
+
+   if (lov_oinfo_is_dummy(lsm->lsm_oinfo[stripeno]))
+   return -EIO;
+
+   /* If this is a continuation FIEMAP call and we are on
+* starting stripe then lun_start needs to be set to
+* end_offset */
+   if (fs->fs_end_offset != 0 && stripeno == fs->fs_start_stripe)
+   lun_start = fs->fs_end_offset;
+
+   lun_end = fs->fs_length;
+   if (lun_end != ~0ULL) {
+   /* Handle fs->fs_start + fs->fs_length overflow */
+   if (fs->fs_start + fs->fs_length < fs->fs_start)
+   fs->fs_length = ~0ULL - fs->fs_start;
+   lun_end = lov_size_to_stripe(lsm, fs->fs_start + fs->fs_length,
+stripeno);
+   }
+
+   if (lun_start == lun_end)
+   return 0;
+
+   req_fm_len = obd_object_end - lun_start;
+   fs->fs_fm->fm_length = 0;
+   len_mapped_single_call = 0;
+
+   /* find lobsub object */
+   subobj = lov_find_subobj(env, cl2lov(obj), lsm, stripeno);
+   if (IS_ERR(subobj))
+   return PTR_ERR(subobj);
+   /* If the output buffer is very large and the objects have many
+* extents we may need to loop on a single OST repeatedly */
+   do {
+   if (fiemap->fm_extent_count > 0) {
+   /* Don't get too many extents. */
+   if (fs->fs_cur_extent + fs->fs_cnt_need >
+   fiemap->fm_extent_count)
+   fs->fs_cnt_need = fiemap->fm_extent_count -
+ fs->fs_cur_extent;
+   }
+
+   lun_start += len_mapped_single_call;
+   fs->fs_fm->fm_length = req_fm_len - len_mapped_single_call;
+   req_fm_len = fs->fs_fm->fm_length;
+   fs->fs_fm->fm_extent_count = fs->fs_enough ?
+1 : fs->fs_cnt_need;
+   fs->fs_fm->fm_mapped_extents = 0;
+   fs->fs_fm->fm_flags = fiemap->fm_flags;
+
+   ost_index = lsm->lsm_oinfo[stripeno]->loi_ost_idx;
+
+   if (ost_index < 0 || ost_index >= lov->desc.ld_tgt_count) {
+   rc = -EINVAL;
+   goto obj_put;
+   }
+   /* If OST is inactive, return extent with UNKNOWN flag. */
+   if (!lov->lov_tgts[ost_index]->ltd_active) {
+   fs->fs_fm->fm_flags |= FIEMAP_EXTENT_LAST;
+   fs->fs_fm->fm_mapped_extents = 1;
+
+   fm_ext[0].fe_logical = lun_start;
+   fm_ext[0].fe_length = obd_object_end - lun_start;
+   fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
+
+  

[PATCH 2/2] staging: greybus: use get_icount tty operation

2016-11-08 Thread Johan Hovold
Use the tty get_icount operation instead of implementing TIOCGICOUNT
directly.

Signed-off-by: Johan Hovold 
---
 drivers/staging/greybus/uart.c | 31 ---
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 15563e2b21b1..1e05fd2e71fb 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -708,25 +708,20 @@ static int wait_serial_change(struct gb_tty *gb_tty, 
unsigned long arg)
return retval;
 }
 
-static int get_serial_usage(struct gb_tty *gb_tty,
-   struct serial_icounter_struct __user *count)
+static int gb_tty_get_icount(struct tty_struct *tty,
+struct serial_icounter_struct *icount)
 {
-   struct serial_icounter_struct icount;
-   int retval = 0;
-
-   memset(&icount, 0, sizeof(icount));
-   icount.dsr = gb_tty->iocount.dsr;
-   icount.rng = gb_tty->iocount.rng;
-   icount.dcd = gb_tty->iocount.dcd;
-   icount.frame = gb_tty->iocount.frame;
-   icount.overrun = gb_tty->iocount.overrun;
-   icount.parity = gb_tty->iocount.parity;
-   icount.brk = gb_tty->iocount.brk;
+   struct gb_tty *gb_tty = tty->driver_data;
 
-   if (copy_to_user(count, &icount, sizeof(icount)) > 0)
-   retval = -EFAULT;
+   icount->dsr = gb_tty->iocount.dsr;
+   icount->rng = gb_tty->iocount.rng;
+   icount->dcd = gb_tty->iocount.dcd;
+   icount->frame = gb_tty->iocount.frame;
+   icount->overrun = gb_tty->iocount.overrun;
+   icount->parity = gb_tty->iocount.parity;
+   icount->brk = gb_tty->iocount.brk;
 
-   return retval;
+   return 0;
 }
 
 static int gb_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
@@ -743,9 +738,6 @@ static int gb_tty_ioctl(struct tty_struct *tty, unsigned 
int cmd,
   (struct serial_struct __user *)arg);
case TIOCMIWAIT:
return wait_serial_change(gb_tty, arg);
-   case TIOCGICOUNT:
-   return get_serial_usage(gb_tty,
-   (struct serial_icounter_struct __user 
*)arg);
}
 
return -ENOIOCTLCMD;
@@ -827,6 +819,7 @@ static const struct tty_operations gb_ops = {
.set_termios =  gb_tty_set_termios,
.tiocmget = gb_tty_tiocmget,
.tiocmset = gb_tty_tiocmset,
+   .get_icount =   gb_tty_get_icount,
 };
 
 static struct tty_port_operations gb_port_ops = {
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: greybus: uart: fix invalid user-pointer check

2016-11-08 Thread Johan Hovold
Drop invalid user-pointer check from TIOCGSERIAL handler.

A NULL-pointer can be valid in user space and copy_to_user() takes care
of sanity checking.

Signed-off-by: Johan Hovold 
---
 drivers/staging/greybus/uart.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 2633d2bfb1b4..15563e2b21b1 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -623,9 +623,6 @@ static int get_serial_info(struct gb_tty *gb_tty,
 {
struct serial_struct tmp;
 
-   if (!info)
-   return -EINVAL;
-
memset(&tmp, 0, sizeof(tmp));
tmp.flags = ASYNC_LOW_LATENCY | ASYNC_SKIP_TEST;
tmp.type = PORT_16550A;
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: iio: ad9832: allocate data before using

2016-11-08 Thread Arnd Bergmann
The regulator changes assigned data to an uninitialized pointer:

drivers/staging/iio/frequency/ad9832.c: In function 'ad9832_probe':
drivers/staging/iio/frequency/ad9832.c:214:11: error: 'st' may be used 
uninitialized in this function [-Werror=maybe-uninitialized]

This moves the allocation of the 'st' structure before its first
use, as it should have been.

Fixes: 43a07e48af44 ("staging: iio: ad9832: clean-up regulator 'reg'")
Fixes: a98461d79ba5 ("staging: iio: ad9832: add DVDD regulator")
Signed-off-by: Arnd Bergmann 
---
 drivers/staging/iio/frequency/ad9832.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c 
b/drivers/staging/iio/frequency/ad9832.c
index 639047fade30..a5b2f068168d 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -211,6 +211,13 @@ static int ad9832_probe(struct spi_device *spi)
return -ENODEV;
}
 
+   indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+   if (!indio_dev)
+   return -ENOMEM;
+
+   spi_set_drvdata(spi, indio_dev);
+   st = iio_priv(indio_dev);
+
st->avdd = devm_regulator_get(&spi->dev, "avdd");
if (IS_ERR(st->avdd))
return PTR_ERR(st->avdd);
@@ -233,13 +240,6 @@ static int ad9832_probe(struct spi_device *spi)
goto error_disable_avdd;
}
 
-   indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-   if (!indio_dev) {
-   ret = -ENOMEM;
-   goto error_disable_dvdd;
-   }
-   spi_set_drvdata(spi, indio_dev);
-   st = iio_priv(indio_dev);
st->mclk = pdata->mclk;
st->spi = spi;
 
-- 
2.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: iio: tsl2583: fix unused function warning

2016-11-08 Thread Arnd Bergmann
Removing a call to the taos_chip_off() makes it unused when CONFIG_PM
is disabled:

drivers/staging/iio/light/tsl2583.c:438:12: error: ‘taos_chip_off’ defined but 
not used [-Werror=unused-function]

This removes all the #ifdef in this file, and marks the PM functions as
__maybe_unused instead, which is more reliable and gives us better
compile time coverage.

Fixes: 0561155f6fc5 ("staging: iio: tsl2583: don't shutdown chip when updating 
the lux table")
Signed-off-by: Arnd Bergmann 
---
 drivers/staging/iio/light/tsl2583.c | 15 +++
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c 
b/drivers/staging/iio/light/tsl2583.c
index 7eab17f4557e..d74e33bacbf9 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -816,8 +816,7 @@ static int taos_probe(struct i2c_client *clientp,
return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int taos_suspend(struct device *dev)
+static int __maybe_unused taos_suspend(struct device *dev)
 {
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct tsl2583_chip *chip = iio_priv(indio_dev);
@@ -834,7 +833,7 @@ static int taos_suspend(struct device *dev)
return ret;
 }
 
-static int taos_resume(struct device *dev)
+static int __maybe_unused taos_resume(struct device *dev)
 {
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct tsl2583_chip *chip = iio_priv(indio_dev);
@@ -850,10 +849,6 @@ static int taos_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
-#define TAOS_PM_OPS (&taos_pm_ops)
-#else
-#define TAOS_PM_OPS NULL
-#endif
 
 static struct i2c_device_id taos_idtable[] = {
{ "tsl2580", 0 },
@@ -863,7 +858,6 @@ static struct i2c_device_id taos_idtable[] = {
 };
 MODULE_DEVICE_TABLE(i2c, taos_idtable);
 
-#ifdef CONFIG_OF
 static const struct of_device_id taos2583_of_match[] = {
{ .compatible = "amstaos,tsl2580", },
{ .compatible = "amstaos,tsl2581", },
@@ -871,15 +865,12 @@ static const struct of_device_id taos2583_of_match[] = {
{ },
 };
 MODULE_DEVICE_TABLE(of, taos2583_of_match);
-#else
-#define taos2583_of_match NULL
-#endif
 
 /* Driver definition */
 static struct i2c_driver taos_driver = {
.driver = {
.name = "tsl2583",
-   .pm = TAOS_PM_OPS,
+   .pm = &taos_pm_ops,
.of_match_table = taos2583_of_match,
},
.id_table = taos_idtable,
-- 
2.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/2] Staging: fsl-mc: include: mc-bus: Kernel type 's16' preferred over 'int16_t'

2016-11-08 Thread Shiva Kerdel
Follow the kernel type preferrences of using 's16' over 'int16_t'.

Signed-off-by: Shiva Kerdel 
---
 drivers/staging/fsl-mc/include/mc-bus.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/fsl-mc/include/mc-bus.h 
b/drivers/staging/fsl-mc/include/mc-bus.h
index e915574..c7cad87 100644
--- a/drivers/staging/fsl-mc/include/mc-bus.h
+++ b/drivers/staging/fsl-mc/include/mc-bus.h
@@ -42,8 +42,8 @@ struct msi_domain_info;
  */
 struct fsl_mc_resource_pool {
enum fsl_mc_pool_type type;
-   int16_t max_count;
-   int16_t free_count;
+   s16 max_count;
+   s16 free_count;
struct mutex mutex; /* serializes access to free_list */
struct list_head free_list;
struct fsl_mc_bus *mc_bus;
-- 
2.10.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/2] Staging: fsl-mc: include: mc: Kernel type 's32' preferred over 'int32_t'

2016-11-08 Thread Shiva Kerdel
Follow the kernel type preferrences of using 's32' over 'int32_t'.

Signed-off-by: Shiva Kerdel 
---
 drivers/staging/fsl-mc/include/mc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/fsl-mc/include/mc.h 
b/drivers/staging/fsl-mc/include/mc.h
index a781a36..1c46c0c 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -81,7 +81,7 @@ enum fsl_mc_pool_type {
  */
 struct fsl_mc_resource {
enum fsl_mc_pool_type type;
-   int32_t id;
+   s32 id;
void *data;
struct fsl_mc_resource_pool *parent_pool;
struct list_head node;
-- 
2.10.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging

2016-11-08 Thread Brian Masney
On Tue, Nov 08, 2016 at 02:29:20AM -0800, Joe Perches wrote:
> On Tue, 2016-11-08 at 05:16 -0500, Brian Masney wrote:
> > There are several places in the code where the function name is
> > hardcoded in the log message. Use the __func__ constant string to build
> > the log message. This also clarifies some of the error messages to match
> > the code and ensures that the correct priority is used since the message
> > is already being changed.
> []
> > diff --git a/drivers/staging/iio/light/tsl2583.c 
> > b/drivers/staging/iio/light/tsl2583.c
> []
> > @@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
> >  
> > ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
> > if (ret < 0) {
> > -   dev_err(&chip->client->dev, "taos_get_lux failed to read 
> > CMD_REG\n");
> > +   dev_err(&chip->client->dev, "%s failed to read CMD_REG 
> > register\n",
> > +   __func__);
> 
> Please use "%s: ", __func__ consistently
> 
> > @@ -545,12 +549,15 @@ static ssize_t in_illuminance_lux_table_store(struct 
> > device *dev,
> >  * and the last table entry is all 0.
> >  */
> > n = value[0];
> > -   if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
> > -   dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
> > +   if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
> > +   dev_err(dev,
> > +   "%s: The number of entries in the lux table must be a 
> > multiple of 3 and within the range [6, %zu]",
> > +   __func__, TSL2583_MAX_LUX_INTS);
> 
> Missing terminating '\n"

Thanks for the feedback Joe. I'll send out an updated patch series on
Friday.

Brian
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: xgifb: vgatypes: Replace decimal permissions with 4 digit octal

2016-11-08 Thread Shiva Kerdel
Replaced decimal permissions with 4 digit octal to solve checkpatch errors.

Signed-off-by: Shiva Kerdel 
---
 drivers/staging/xgifb/XGI_main_26.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/xgifb/XGI_main_26.c 
b/drivers/staging/xgifb/XGI_main_26.c
index 89bd4dd..982f90f 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -2058,19 +2058,19 @@ static struct pci_driver xgifb_driver = {
 /*  MODULE   */
 /*/
 
-module_param(mode, charp, 0);
+module_param(mode, charp, );
 MODULE_PARM_DESC(mode,
"Selects the desired default display mode in the format XxYxDepth (eg. 
1024x768x16).");
 
-module_param(forcecrt2type, charp, 0);
+module_param(forcecrt2type, charp, );
 MODULE_PARM_DESC(forcecrt2type,
"Force the second display output type. Possible values are NONE, LCD, 
TV, VGA, SVIDEO or COMPOSITE.");
 
-module_param(vesa, int, 0);
+module_param(vesa, int, );
 MODULE_PARM_DESC(vesa,
"Selects the desired default display mode by VESA mode number (eg. 
0x117).");
 
-module_param(filter, int, 0);
+module_param(filter, int, );
 MODULE_PARM_DESC(filter,
"Selects TV flicker filter type (only for systems with a SiS301 video 
bridge). Possible values 0-7. Default: [no filter]).");
 
-- 
2.10.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

2016-11-08 Thread Long Li


> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Monday, November 7, 2016 11:00 PM
> To: Long Li 
> Cc: KY Srinivasan ; Haiyang Zhang
> ; Bjorn Helgaas ;
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; linux-
> p...@vger.kernel.org
> Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall
> params buffer
> 
> On Tue, Nov 08, 2016 at 12:14:14AM -0800, Long Li wrote:
> > From: Long Li 
> >
> > hv_do_hypercall assumes that we pass a segment from a physically
> continuous buffer. Buffer allocated on the stack may not work if
> CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.
> 
> Please wrap your changelog at 72 columns.
> 
> >
> > Signed-off-by: Long Li 
> > Reported-by: Haiyang Zhang 
> > ---
> >  drivers/pci/host/pci-hyperv.c | 24 +---
> >  1 file changed, 13 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/pci/host/pci-hyperv.c
> > b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644
> > --- a/drivers/pci/host/pci-hyperv.c
> > +++ b/drivers/pci/host/pci-hyperv.c
> > @@ -378,6 +378,7 @@ struct hv_pcibus_device {
> > struct msi_domain_info msi_info;
> > struct msi_controller msi_chip;
> > struct irq_domain *irq_domain;
> > +   struct retarget_msi_interrupt retarget_msi_interrupt_params;
> 
> Can you handle potentially unaligned accesses like this?  Is there some lock
> preventing you from using this structure more than once at the same time?
> 
> >  };
> >
> >  /*
> > @@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
> > struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
> > struct irq_cfg *cfg = irqd_cfg(data);
> > -   struct retarget_msi_interrupt params;
> > +   struct retarget_msi_interrupt *params;
> > struct hv_pcibus_device *hbus;
> > struct cpumask *dest;
> > struct pci_bus *pbus;
> > @@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
> > pdev = msi_desc_to_pci_dev(msi_desc);
> > pbus = pdev->bus;
> > hbus = container_of(pbus->sysdata, struct hv_pcibus_device,
> > sysdata);
> > -
> > -   memset(¶ms, 0, sizeof(params));
> > -   params.partition_id = HV_PARTITION_ID_SELF;
> > -   params.source = 1; /* MSI(-X) */
> > -   params.address = msi_desc->msg.address_lo;
> > -   params.data = msi_desc->msg.data;
> > -   params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> > +   params = &hbus->retarget_msi_interrupt_params;
> > +
> > +   memset(params, 0, sizeof(*params));
> > +   params->partition_id = HV_PARTITION_ID_SELF;
> > +   params->source = 1; /* MSI(-X) */
> > +   params->address = msi_desc->msg.address_lo;
> > +   params->data = msi_desc->msg.data;
> > +   params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> >(hbus->hdev->dev_instance.b[4] << 16) |
> >(hbus->hdev->dev_instance.b[7] << 8) |
> >(hbus->hdev->dev_instance.b[6] & 0xf8) |
> >PCI_FUNC(pdev->devfn);
> > -   params.vector = cfg->vector;
> > +   params->vector = cfg->vector;
> >
> > for_each_cpu_and(cpu, dest, cpu_online_mask)
> > -   params.vp_mask |= (1ULL <<
> vmbus_cpu_number_to_vp_number(cpu));
> > +   params->vp_mask |= (1ULL <<
> vmbus_cpu_number_to_vp_number(cpu));
> >
> > -   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, ¶ms, NULL);
> > +   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);
> 
> As you only use this in one spot, why not just allocate it here and then free
> it?  Why add it to the pcibus device structure?

Thanks Greg. I will send a V2.

> 
> thanks,
> 
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

2016-11-08 Thread KY Srinivasan


> -Original Message-
> From: Long Li
> Sent: Tuesday, November 8, 2016 8:57 AM
> To: Greg KH 
> Cc: KY Srinivasan ; Haiyang Zhang
> ; Bjorn Helgaas ;
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; linux-
> p...@vger.kernel.org
> Subject: RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall
> params buffer
> 
> 
> 
> > -Original Message-
> > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > Sent: Monday, November 7, 2016 11:00 PM
> > To: Long Li 
> > Cc: KY Srinivasan ; Haiyang Zhang
> > ; Bjorn Helgaas ;
> > de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; linux-
> > p...@vger.kernel.org
> > Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall
> > params buffer
> >
> > On Tue, Nov 08, 2016 at 12:14:14AM -0800, Long Li wrote:
> > > From: Long Li 
> > >
> > > hv_do_hypercall assumes that we pass a segment from a physically
> > continuous buffer. Buffer allocated on the stack may not work if
> > CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.
> >
> > Please wrap your changelog at 72 columns.

Long, this should not be part of the commit message. Please include changes in
each version below the line ()

Regards,

K. Y 
> >
> > >
> > > Signed-off-by: Long Li 
> > > Reported-by: Haiyang Zhang 
> > > ---
> > >  drivers/pci/host/pci-hyperv.c | 24 +---
> > >  1 file changed, 13 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/pci/host/pci-hyperv.c
> > > b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644
> > > --- a/drivers/pci/host/pci-hyperv.c
> > > +++ b/drivers/pci/host/pci-hyperv.c
> > > @@ -378,6 +378,7 @@ struct hv_pcibus_device {
> > >   struct msi_domain_info msi_info;
> > >   struct msi_controller msi_chip;
> > >   struct irq_domain *irq_domain;
> > > + struct retarget_msi_interrupt retarget_msi_interrupt_params;
> >
> > Can you handle potentially unaligned accesses like this?  Is there some lock
> > preventing you from using this structure more than once at the same time?
> >
> > >  };
> > >
> > >  /*
> > > @@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
> > >   struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
> > >   struct irq_cfg *cfg = irqd_cfg(data);
> > > - struct retarget_msi_interrupt params;
> > > + struct retarget_msi_interrupt *params;
> > >   struct hv_pcibus_device *hbus;
> > >   struct cpumask *dest;
> > >   struct pci_bus *pbus;
> > > @@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
> > >   pdev = msi_desc_to_pci_dev(msi_desc);
> > >   pbus = pdev->bus;
> > >   hbus = container_of(pbus->sysdata, struct hv_pcibus_device,
> > > sysdata);
> > > -
> > > - memset(¶ms, 0, sizeof(params));
> > > - params.partition_id = HV_PARTITION_ID_SELF;
> > > - params.source = 1; /* MSI(-X) */
> > > - params.address = msi_desc->msg.address_lo;
> > > - params.data = msi_desc->msg.data;
> > > - params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> > > + params = &hbus->retarget_msi_interrupt_params;
> > > +
> > > + memset(params, 0, sizeof(*params));
> > > + params->partition_id = HV_PARTITION_ID_SELF;
> > > + params->source = 1; /* MSI(-X) */
> > > + params->address = msi_desc->msg.address_lo;
> > > + params->data = msi_desc->msg.data;
> > > + params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> > >  (hbus->hdev->dev_instance.b[4] << 16) |
> > >  (hbus->hdev->dev_instance.b[7] << 8) |
> > >  (hbus->hdev->dev_instance.b[6] & 0xf8) |
> > >  PCI_FUNC(pdev->devfn);
> > > - params.vector = cfg->vector;
> > > + params->vector = cfg->vector;
> > >
> > >   for_each_cpu_and(cpu, dest, cpu_online_mask)
> > > - params.vp_mask |= (1ULL <<
> > vmbus_cpu_number_to_vp_number(cpu));
> > > + params->vp_mask |= (1ULL <<
> > vmbus_cpu_number_to_vp_number(cpu));
> > >
> > > - hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, ¶ms, NULL);
> > > + hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);
> >
> > As you only use this in one spot, why not just allocate it here and then 
> > free
> > it?  Why add it to the pcibus device structure?
> 
> Thanks Greg. I will send a V2.
> 
> >
> > thanks,
> >
> > greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


My Friend,

2016-11-08 Thread Mrs Patricia Santos
My Friend,

Compliments of the season, thank you for your help I am very happy to
inform you about my success in getting those funds transfer.Now, I
want you to contact Mr Richard Frank with below contact Email ID:
(w...@grpcco.org ) Ask him to send you the sum of eight hundred and
seventy five thousand dollars only ($875,000.00) U.S.D through  ATM
VISA CARD,The needed information's is as detailed bellow:

Your Name:.
Your Age.
Your Address:.
Your Occupation:...
Your Phone:...
Your Country:..

Try and contact him as soon as you receive this mail because he is
expecting to hear
from you. Thanks.

Best Regards
Mrs Patricia Santos.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V3 07/14] Drivers: hv: vss: Operation timeouts should match host expectation

2016-11-08 Thread Stephen Hemminger
This looks messy, weird line wrap??

+/*
+ * Timeout values are based on expecations from host  */ #define 
+VSS_FREEZE_TIMEOUT (15 * 60)

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V3 13/14] Drivers: hv: vmbus: On write cleanup the logic to interrupt the host

2016-11-08 Thread Stephen Hemminger
Please don't add name/date information into comments.
This kind of meta data belongs in the commit message only.

My philosophy is that comments should be reserved for explain the semantics of 
the code, not the history.

+ *
+ * KYS: Oct. 30, 2016:
+ * It looks like Windows hosts have logic to deal with DOS attacks that
+ * can be triggered if it receives interrupts when it is not expecting
+ * the interrupt. The host expects interrupts only when the ring
+ * transitions from empty to non-empty (or full to non full on the 
+ guest
+ * to host ring).
+ * So, base the signaling decision solely on the ring state until the
+ * host logic is fixed.
  */



___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

2016-11-08 Thread Long Li
From: Long Li 

hv_do_hypercall assumes that we pass a segment from a physically
continuous buffer. Buffer allocated on the stack may not work if
CONFIG_VMAP_STACK=y is set.

Change to use kmalloc to allocate this buffer.

The v2 patch adds locking to access the pre-allocated buffer.

Signed-off-by: Long Li 
Reported-by: Haiyang Zhang 
---
 drivers/pci/host/pci-hyperv.c | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 763ff87..ca553df 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -378,6 +378,8 @@ struct hv_pcibus_device {
struct msi_domain_info msi_info;
struct msi_controller msi_chip;
struct irq_domain *irq_domain;
+   struct retarget_msi_interrupt retarget_msi_interrupt_params;
+   spinlock_t retarget_msi_interrupt_lock;;
 };
 
 /*
@@ -774,34 +776,40 @@ void hv_irq_unmask(struct irq_data *data)
 {
struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
struct irq_cfg *cfg = irqd_cfg(data);
-   struct retarget_msi_interrupt params;
+   struct retarget_msi_interrupt *params;
struct hv_pcibus_device *hbus;
struct cpumask *dest;
struct pci_bus *pbus;
struct pci_dev *pdev;
int cpu;
+   unsigned long flags;
 
dest = irq_data_get_affinity_mask(data);
pdev = msi_desc_to_pci_dev(msi_desc);
pbus = pdev->bus;
hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
 
-   memset(¶ms, 0, sizeof(params));
-   params.partition_id = HV_PARTITION_ID_SELF;
-   params.source = 1; /* MSI(-X) */
-   params.address = msi_desc->msg.address_lo;
-   params.data = msi_desc->msg.data;
-   params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
+   spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags);
+
+   params = &hbus->retarget_msi_interrupt_params;
+   memset(params, 0, sizeof(*params));
+   params->partition_id = HV_PARTITION_ID_SELF;
+   params->source = 1; /* MSI(-X) */
+   params->address = msi_desc->msg.address_lo;
+   params->data = msi_desc->msg.data;
+   params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
   (hbus->hdev->dev_instance.b[4] << 16) |
   (hbus->hdev->dev_instance.b[7] << 8) |
   (hbus->hdev->dev_instance.b[6] & 0xf8) |
   PCI_FUNC(pdev->devfn);
-   params.vector = cfg->vector;
+   params->vector = cfg->vector;
 
for_each_cpu_and(cpu, dest, cpu_online_mask)
-   params.vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
+   params->vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
+
+   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);
 
-   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, ¶ms, NULL);
+   spin_unlock_irqrestore(&hbus->retarget_msi_interrupt_lock, flags);
 
pci_msi_unmask_irq(data);
 }
@@ -2186,6 +2194,7 @@ static int hv_pci_probe(struct hv_device *hdev,
INIT_LIST_HEAD(&hbus->resources_for_children);
spin_lock_init(&hbus->config_lock);
spin_lock_init(&hbus->device_list_lock);
+   spin_lock_init(&hbus->retarget_msi_interrupt_lock);
sema_init(&hbus->enum_sem, 1);
init_completion(&hbus->remove_event);
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: ad9832: allocate data before using

2016-11-08 Thread Jonathan Cameron
On 08/11/16 14:00, Arnd Bergmann wrote:
> The regulator changes assigned data to an uninitialized pointer:
> 
> drivers/staging/iio/frequency/ad9832.c: In function 'ad9832_probe':
> drivers/staging/iio/frequency/ad9832.c:214:11: error: 'st' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
> 
> This moves the allocation of the 'st' structure before its first
> use, as it should have been.
> 
> Fixes: 43a07e48af44 ("staging: iio: ad9832: clean-up regulator 'reg'")
> Fixes: a98461d79ba5 ("staging: iio: ad9832: add DVDD regulator")
> Signed-off-by: Arnd Bergmann 
Thanks Arnd.

I think I've gotten too reliant on zero day and clearly am not checking my local
build warnings closely enough.  Time to go back to doing pre push out checks 
more
thoroughly.

Anyhow, applied to the togreg branch of iio.git.  Will probably be the weekend
at least before I send another pull request.

Thanks,

Jonathan
> ---
>  drivers/staging/iio/frequency/ad9832.c | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/iio/frequency/ad9832.c 
> b/drivers/staging/iio/frequency/ad9832.c
> index 639047fade30..a5b2f068168d 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -211,6 +211,13 @@ static int ad9832_probe(struct spi_device *spi)
>   return -ENODEV;
>   }
>  
> + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + spi_set_drvdata(spi, indio_dev);
> + st = iio_priv(indio_dev);
> +
>   st->avdd = devm_regulator_get(&spi->dev, "avdd");
>   if (IS_ERR(st->avdd))
>   return PTR_ERR(st->avdd);
> @@ -233,13 +240,6 @@ static int ad9832_probe(struct spi_device *spi)
>   goto error_disable_avdd;
>   }
>  
> - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> - if (!indio_dev) {
> - ret = -ENOMEM;
> - goto error_disable_dvdd;
> - }
> - spi_set_drvdata(spi, indio_dev);
> - st = iio_priv(indio_dev);
>   st->mclk = pdata->mclk;
>   st->spi = spi;
>  
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: tsl2583: fix unused function warning

2016-11-08 Thread Jonathan Cameron
On 08/11/16 14:01, Arnd Bergmann wrote:
> Removing a call to the taos_chip_off() makes it unused when CONFIG_PM
> is disabled:
> 
> drivers/staging/iio/light/tsl2583.c:438:12: error: ‘taos_chip_off’ defined 
> but not used [-Werror=unused-function]
> 
> This removes all the #ifdef in this file, and marks the PM functions as
> __maybe_unused instead, which is more reliable and gives us better
> compile time coverage.
> 
> Fixes: 0561155f6fc5 ("staging: iio: tsl2583: don't shutdown chip when 
> updating the lux table")
> Signed-off-by: Arnd Bergmann 
Thanks. Applied to the togreg branch of iio.git and pushed out as testing for 
the autobuilders to play with it.

thanks,

Jonathan
> ---
>  drivers/staging/iio/light/tsl2583.c | 15 +++
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c 
> b/drivers/staging/iio/light/tsl2583.c
> index 7eab17f4557e..d74e33bacbf9 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -816,8 +816,7 @@ static int taos_probe(struct i2c_client *clientp,
>   return 0;
>  }
>  
> -#ifdef CONFIG_PM_SLEEP
> -static int taos_suspend(struct device *dev)
> +static int __maybe_unused taos_suspend(struct device *dev)
>  {
>   struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>   struct tsl2583_chip *chip = iio_priv(indio_dev);
> @@ -834,7 +833,7 @@ static int taos_suspend(struct device *dev)
>   return ret;
>  }
>  
> -static int taos_resume(struct device *dev)
> +static int __maybe_unused taos_resume(struct device *dev)
>  {
>   struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>   struct tsl2583_chip *chip = iio_priv(indio_dev);
> @@ -850,10 +849,6 @@ static int taos_resume(struct device *dev)
>  }
>  
>  static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
> -#define TAOS_PM_OPS (&taos_pm_ops)
> -#else
> -#define TAOS_PM_OPS NULL
> -#endif
>  
>  static struct i2c_device_id taos_idtable[] = {
>   { "tsl2580", 0 },
> @@ -863,7 +858,6 @@ static struct i2c_device_id taos_idtable[] = {
>  };
>  MODULE_DEVICE_TABLE(i2c, taos_idtable);
>  
> -#ifdef CONFIG_OF
>  static const struct of_device_id taos2583_of_match[] = {
>   { .compatible = "amstaos,tsl2580", },
>   { .compatible = "amstaos,tsl2581", },
> @@ -871,15 +865,12 @@ static const struct of_device_id taos2583_of_match[] = {
>   { },
>  };
>  MODULE_DEVICE_TABLE(of, taos2583_of_match);
> -#else
> -#define taos2583_of_match NULL
> -#endif
>  
>  /* Driver definition */
>  static struct i2c_driver taos_driver = {
>   .driver = {
>   .name = "tsl2583",
> - .pm = TAOS_PM_OPS,
> + .pm = &taos_pm_ops,
>   .of_match_table = taos2583_of_match,
>   },
>   .id_table = taos_idtable,
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR

2016-11-08 Thread Jonathan Cameron
On 08/11/16 10:16, Brian Masney wrote:
> Added Brian Masney's copyright to the header and to the MODULE_AUTHOR
> for all of the staging cleanups that has been done to this driver.
> 
> Signed-off-by: Brian Masney 
> ---
>  drivers/staging/iio/light/tsl2583.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c 
> b/drivers/staging/iio/light/tsl2583.c
> index 013e7f6..5cb4ae3 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -3,6 +3,7 @@
>   * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
>   *
>   * Copyright (c) 2011, TAOS Corporation.
> + * Copyright (c) 2016 Brian Masney 
>   *
>   * 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
> @@ -910,6 +911,6 @@ static struct i2c_driver tsl2583_driver = {
>  };
>  module_i2c_driver(tsl2583_driver);
>  
> -MODULE_AUTHOR("J. August Brenner");
> +MODULE_AUTHOR("J. August Brenner  and Brian Masney 
> ");
IIRC preferred method is multiple MODULE_AUTHOR statements.

>  MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
>  MODULE_LICENSE("GPL");
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

2016-11-08 Thread Long Li


> -Original Message-
> From: devel [mailto:driverdev-devel-boun...@linuxdriverproject.org] On
> Behalf Of Long Li
> Sent: Tuesday, November 8, 2016 8:57 AM
> To: Greg KH 
> Cc: linux-...@vger.kernel.org; Haiyang Zhang ;
> linux-ker...@vger.kernel.org; Bjorn Helgaas ;
> de...@linuxdriverproject.org
> Subject: RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall
> params buffer
> 
> This sender failed our fraud detection checks and may not be who they
> appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing
> 
> > -Original Message-
> > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > Sent: Monday, November 7, 2016 11:00 PM
> > To: Long Li 
> > Cc: KY Srinivasan ; Haiyang Zhang
> > ; Bjorn Helgaas ;
> > de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; linux-
> > p...@vger.kernel.org
> > Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate
> > hypercall params buffer
> >
> > On Tue, Nov 08, 2016 at 12:14:14AM -0800, Long Li wrote:
> > > From: Long Li 
> > >
> > > hv_do_hypercall assumes that we pass a segment from a physically
> > continuous buffer. Buffer allocated on the stack may not work if
> > CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.
> >
> > Please wrap your changelog at 72 columns.
> >
> > >
> > > Signed-off-by: Long Li 
> > > Reported-by: Haiyang Zhang 
> > > ---
> > >  drivers/pci/host/pci-hyperv.c | 24 +---
> > >  1 file changed, 13 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/pci/host/pci-hyperv.c
> > > b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644
> > > --- a/drivers/pci/host/pci-hyperv.c
> > > +++ b/drivers/pci/host/pci-hyperv.c
> > > @@ -378,6 +378,7 @@ struct hv_pcibus_device {
> > > struct msi_domain_info msi_info;
> > > struct msi_controller msi_chip;
> > > struct irq_domain *irq_domain;
> > > +   struct retarget_msi_interrupt retarget_msi_interrupt_params;
> >
> > Can you handle potentially unaligned accesses like this?  Is there
> > some lock preventing you from using this structure more than once at the
> same time?
> >
> > >  };
> > >
> > >  /*
> > > @@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
> > > struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
> > > struct irq_cfg *cfg = irqd_cfg(data);
> > > -   struct retarget_msi_interrupt params;
> > > +   struct retarget_msi_interrupt *params;
> > > struct hv_pcibus_device *hbus;
> > > struct cpumask *dest;
> > > struct pci_bus *pbus;
> > > @@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
> > > pdev = msi_desc_to_pci_dev(msi_desc);
> > > pbus = pdev->bus;
> > > hbus = container_of(pbus->sysdata, struct hv_pcibus_device,
> > > sysdata);
> > > -
> > > -   memset(¶ms, 0, sizeof(params));
> > > -   params.partition_id = HV_PARTITION_ID_SELF;
> > > -   params.source = 1; /* MSI(-X) */
> > > -   params.address = msi_desc->msg.address_lo;
> > > -   params.data = msi_desc->msg.data;
> > > -   params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> > > +   params = &hbus->retarget_msi_interrupt_params;
> > > +
> > > +   memset(params, 0, sizeof(*params));
> > > +   params->partition_id = HV_PARTITION_ID_SELF;
> > > +   params->source = 1; /* MSI(-X) */
> > > +   params->address = msi_desc->msg.address_lo;
> > > +   params->data = msi_desc->msg.data;
> > > +   params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
> > >(hbus->hdev->dev_instance.b[4] << 16) |
> > >(hbus->hdev->dev_instance.b[7] << 8) |
> > >(hbus->hdev->dev_instance.b[6] & 0xf8) |
> > >PCI_FUNC(pdev->devfn);
> > > -   params.vector = cfg->vector;
> > > +   params->vector = cfg->vector;
> > >
> > > for_each_cpu_and(cpu, dest, cpu_online_mask)
> > > -   params.vp_mask |= (1ULL <<
> > vmbus_cpu_number_to_vp_number(cpu));
> > > +   params->vp_mask |= (1ULL <<
> > vmbus_cpu_number_to_vp_number(cpu));
> > >
> > > -   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, ¶ms, NULL);
> > > +   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);
> >
> > As you only use this in one spot, why not just allocate it here and
> > then free it?  Why add it to the pcibus device structure?
> 
> Thanks Greg. I will send a V2.

Sorry forgot to address the reason why we don't just allocate the buffer here. 
This function cannot fail. So it's better to pre-allocate the buffer.

> 
> >
> > thanks,
> >
> > greg k-h
> ___
> devel mailing list
> de...@linuxdriverproject.org
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdriverd
> ev.linuxdriverproject.org%2Fmailman%2Flistinfo%2Fdriverdev-
> devel&data=02%7C01%7Clongli%40microsoft.com%7C6e28f5459da345cdb5e
> 408d407f836f0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636142
> 210041216500&sdata=vvVxGQUet7KMuRgs9%2BRbR8JE70rKF1AJo%2Fu3zx%
> 2FQNwY%3D

Re: [PATCH v2 23/23] staging: iio: tsl2583: move out of staging

2016-11-08 Thread Jonathan Cameron
On 08/11/16 10:16, Brian Masney wrote:
> Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline.
> 
> Signed-off-by: Brian Masney 
A few minor bits and bobs inline - might need to push one or two into relevant
earlier patches, but was easier to just review the whole code in here as
I'm out of time for tonight.

Jonathan
> ---
>  .../ABI/testing/sysfs-bus-iio-light-tsl2583|  20 +
>  drivers/iio/light/Kconfig  |   7 +
>  drivers/iio/light/Makefile |   1 +
>  drivers/iio/light/tsl2583.c| 916 
> +
>  .../light/sysfs-bus-iio-light-tsl2583  |  20 -
>  drivers/staging/iio/light/Kconfig  |   7 -
>  drivers/staging/iio/light/Makefile |   1 -
>  drivers/staging/iio/light/tsl2583.c| 916 
> -
>  8 files changed, 944 insertions(+), 944 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
>  create mode 100644 drivers/iio/light/tsl2583.c
>  delete mode 100644 
> drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
>  delete mode 100644 drivers/staging/iio/light/tsl2583.c
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583 
> b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
> new file mode 100644
> index 000..a2e1996
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
> @@ -0,0 +1,20 @@
> +What:/sys/bus/iio/devices/device[n]/in_illuminance_calibrate
> +KernelVersion:   2.6.37
> +Contact: linux-...@vger.kernel.org
> +Description:
> + This property causes an internal calibration of the als gain 
> trim
> + value which is later used in calculating illuminance in lux.
> +
> +What:/sys/bus/iio/devices/device[n]/in_illuminance_lux_table
> +KernelVersion:   2.6.37
> +Contact: linux-...@vger.kernel.org
> +Description:
> + This property gets/sets the table of coefficients
> + used in calculating illuminance in lux.
> +
> +What:
> /sys/bus/iio/devices/device[n]/in_illuminance_input_target
> +KernelVersion:   2.6.37
> +Contact: linux-...@vger.kernel.org
> +Description:
> + This property is the known externally illuminance (in lux).
> + It is used in the process of calibrating the device accuracy.
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index d011720..298ea50 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -338,6 +338,13 @@ config SENSORS_TSL2563
>This driver can also be built as a module.  If so, the module
>will be called tsl2563.
>  
> +config TSL2583
> + tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
> + depends on I2C
> + help
> +  Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
> +  Access ALS data via iio, sysfs.
> +
>  config TSL4531
>   tristate "TAOS TSL4531 ambient light sensors"
>   depends on I2C
> diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
> index 15f24c5..4de5200 100644
> --- a/drivers/iio/light/Makefile
> +++ b/drivers/iio/light/Makefile
> @@ -31,6 +31,7 @@ obj-$(CONFIG_SI1145)+= si1145.o
>  obj-$(CONFIG_STK3310)  += stk3310.o
>  obj-$(CONFIG_TCS3414)+= tcs3414.o
>  obj-$(CONFIG_TCS3472)+= tcs3472.o
> +obj-$(CONFIG_TSL2583)+= tsl2583.o
>  obj-$(CONFIG_TSL4531)+= tsl4531.o
>  obj-$(CONFIG_US5182D)+= us5182d.o
>  obj-$(CONFIG_VCNL4000)   += vcnl4000.o
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> new file mode 100644
> index 000..5cb4ae3
> --- /dev/null
> +++ b/drivers/iio/light/tsl2583.c
> @@ -0,0 +1,916 @@
> +/*
> + * Device driver for monitoring ambient light intensity (lux)
> + * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
If we are going to have a list it should be complete.  tsl2583 as well.
> + *
> + * Copyright (c) 2011, TAOS Corporation.
> + * Copyright (c) 2016 Brian Masney 
> + *
> + * 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.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Device Registers and Masks */
> +#define TSL2583_CNTRL   

RE: [PATCH v2 1/2] Staging: fsl-mc: include: mc-bus: Kernel type 's16' preferred over 'int16_t'

2016-11-08 Thread Stuart Yoder


> -Original Message-
> From: Shiva Kerdel [mailto:sh...@exdev.nl]
> Sent: Tuesday, November 08, 2016 9:42 AM
> To: Stuart Yoder 
> Cc: gre...@linuxfoundation.org; german.riv...@freescale.com; German Rivera 
> ;
> tred...@nvidia.com; itai.k...@nxp.com; Nipun Gupta ; 
> linux-ker...@vger.kernel.org;
> de...@driverdev.osuosl.org; Shiva Kerdel 
> Subject: [PATCH v2 1/2] Staging: fsl-mc: include: mc-bus: Kernel type 's16' 
> preferred over 'int16_t'
> 
> Follow the kernel type preferrences of using 's16' over 'int16_t'.
> 
> Signed-off-by: Shiva Kerdel 
> ---
>  drivers/staging/fsl-mc/include/mc-bus.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/fsl-mc/include/mc-bus.h 
> b/drivers/staging/fsl-mc/include/mc-bus.h
> index e915574..c7cad87 100644
> --- a/drivers/staging/fsl-mc/include/mc-bus.h
> +++ b/drivers/staging/fsl-mc/include/mc-bus.h
> @@ -42,8 +42,8 @@ struct msi_domain_info;
>   */
>  struct fsl_mc_resource_pool {
>   enum fsl_mc_pool_type type;
> - int16_t max_count;
> - int16_t free_count;
> + s16 max_count;
> + s16 free_count;
>   struct mutex mutex; /* serializes access to free_list */
>   struct list_head free_list;
>   struct fsl_mc_bus *mc_bus;

Acked-by: Stuart Yoder 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v2 2/2] Staging: fsl-mc: include: mc: Kernel type 's32' preferred over 'int32_t'

2016-11-08 Thread Stuart Yoder


> -Original Message-
> From: Shiva Kerdel [mailto:sh...@exdev.nl]
> Sent: Tuesday, November 08, 2016 9:42 AM
> To: Stuart Yoder 
> Cc: gre...@linuxfoundation.org; german.riv...@freescale.com; German Rivera 
> ;
> tred...@nvidia.com; itai.k...@nxp.com; Nipun Gupta ; 
> linux-ker...@vger.kernel.org;
> de...@driverdev.osuosl.org; Shiva Kerdel 
> Subject: [PATCH v2 2/2] Staging: fsl-mc: include: mc: Kernel type 's32' 
> preferred over 'int32_t'
> 
> Follow the kernel type preferrences of using 's32' over 'int32_t'.
> 
> Signed-off-by: Shiva Kerdel 
> ---
>  drivers/staging/fsl-mc/include/mc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/fsl-mc/include/mc.h 
> b/drivers/staging/fsl-mc/include/mc.h
> index a781a36..1c46c0c 100644
> --- a/drivers/staging/fsl-mc/include/mc.h
> +++ b/drivers/staging/fsl-mc/include/mc.h
> @@ -81,7 +81,7 @@ enum fsl_mc_pool_type {
>   */
>  struct fsl_mc_resource {
>   enum fsl_mc_pool_type type;
> - int32_t id;
> + s32 id;
>   void *data;
>   struct fsl_mc_resource_pool *parent_pool;
>   struct list_head node;

Acked-by: Stuart Yoder 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [lustre-devel] [PATCH] staging: lustre: ldlm: pl_recalc time handling is wrong

2016-11-08 Thread Dilger, Andreas
On Nov 7, 2016, at 19:47, James Simmons  wrote:
> 
> The ldlm_pool field pl_recalc_time is set to the current
> monotonic clock value but the interval period is calculated
> with the wall clock. This means the interval period will
> always be far larger than the pl_recalc_period, which is
> just a small interval time period. The correct thing to
> do is to use monotomic clock current value instead of the
> wall clocks value when calculating recalc_interval_sec.

It looks like this was introduced by commit 8f83409cf
"staging/lustre: use 64-bit time for pl_recalc" but that patch changed
get_seconds() to a mix of ktime_get_seconds() and ktime_get_real_seconds()
for an unknown reason.  It doesn't appear that there is any difference
in overhead between the two (on 64-bit at least).

Since the ldlm pool recalculation interval is actually driven in response to
load on the server, it makes sense to use the "real" time instead of the
monotonic time (if I understand correctly) if the client is in a VM that
may periodically be blocked and "miss time" compared to the outside world.
Using the "real" clock, the recalc_interval_sec will correctly reflect the
actual elapsed time rather than just the number of ticks inside the VM.

Is my understanding of these different clocks correct?

Cheers, Andreas

> 
> Signed-off-by: James Simmons 
> ---
> drivers/staging/lustre/lustre/ldlm/ldlm_pool.c |6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c 
> b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
> index 19831c5..30d4f80 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
> @@ -256,7 +256,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl)
>   time64_t recalc_interval_sec;
>   int ret;
> 
> - recalc_interval_sec = ktime_get_real_seconds() - pl->pl_recalc_time;
> + recalc_interval_sec = ktime_get_seconds() - pl->pl_recalc_time;
>   if (recalc_interval_sec < pl->pl_recalc_period)
>   return 0;
> 
> @@ -264,7 +264,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl)
>   /*
>* Check if we need to recalc lists now.
>*/
> - recalc_interval_sec = ktime_get_real_seconds() - pl->pl_recalc_time;
> + recalc_interval_sec = ktime_get_seconds() - pl->pl_recalc_time;
>   if (recalc_interval_sec < pl->pl_recalc_period) {
>   spin_unlock(&pl->pl_lock);
>   return 0;
> @@ -301,7 +301,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl)
>* Time of LRU resizing might be longer than period,
>* so update after LRU resizing rather than before it.
>*/
> - pl->pl_recalc_time = ktime_get_real_seconds();
> + pl->pl_recalc_time = ktime_get_seconds();
>   lprocfs_counter_add(pl->pl_stats, LDLM_POOL_TIMING_STAT,
>   recalc_interval_sec);
>   spin_unlock(&pl->pl_lock);
> -- 
> 1.7.1
> 
> ___
> lustre-devel mailing list
> lustre-de...@lists.lustre.org
> http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: greybus: uart: fix invalid user-pointer check

2016-11-08 Thread Viresh Kumar
On Tue, Nov 8, 2016 at 6:01 PM, Johan Hovold  wrote:
> Drop invalid user-pointer check from TIOCGSERIAL handler.
>
> A NULL-pointer can be valid in user space and copy_to_user() takes care
> of sanity checking.
>
> Signed-off-by: Johan Hovold 
> ---
>  drivers/staging/greybus/uart.c | 3 ---
>  1 file changed, 3 deletions(-)

Reviewed-by: Viresh Kumar 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/2] staging: greybus: use get_icount tty operation

2016-11-08 Thread Viresh Kumar
On Tue, Nov 8, 2016 at 6:01 PM, Johan Hovold  wrote:
> Use the tty get_icount operation instead of implementing TIOCGICOUNT
> directly.
>
> Signed-off-by: Johan Hovold 
> ---
>  drivers/staging/greybus/uart.c | 31 ---
>  1 file changed, 12 insertions(+), 19 deletions(-)

Reviewed-by: Viresh Kumar 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: ad9832: allocate data before using

2016-11-08 Thread Eva Rachel Retuya
On Tue, Nov 08, 2016 at 03:00:49PM +0100, Arnd Bergmann wrote:
> The regulator changes assigned data to an uninitialized pointer:
> 
> drivers/staging/iio/frequency/ad9832.c: In function 'ad9832_probe':
> drivers/staging/iio/frequency/ad9832.c:214:11: error: 'st' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
> 
> This moves the allocation of the 'st' structure before its first
> use, as it should have been.
> 
> Fixes: 43a07e48af44 ("staging: iio: ad9832: clean-up regulator 'reg'")
> Fixes: a98461d79ba5 ("staging: iio: ad9832: add DVDD regulator")
> Signed-off-by: Arnd Bergmann 

Thank you, I completely missed this. Will be more careful next time.

Eva

> ---
>  drivers/staging/iio/frequency/ad9832.c | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/iio/frequency/ad9832.c 
> b/drivers/staging/iio/frequency/ad9832.c
> index 639047fade30..a5b2f068168d 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -211,6 +211,13 @@ static int ad9832_probe(struct spi_device *spi)
>   return -ENODEV;
>   }
>  
> + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + spi_set_drvdata(spi, indio_dev);
> + st = iio_priv(indio_dev);
> +
>   st->avdd = devm_regulator_get(&spi->dev, "avdd");
>   if (IS_ERR(st->avdd))
>   return PTR_ERR(st->avdd);
> @@ -233,13 +240,6 @@ static int ad9832_probe(struct spi_device *spi)
>   goto error_disable_avdd;
>   }
>  
> - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> - if (!indio_dev) {
> - ret = -ENOMEM;
> - goto error_disable_dvdd;
> - }
> - spi_set_drvdata(spi, indio_dev);
> - st = iio_priv(indio_dev);
>   st->mclk = pdata->mclk;
>   st->spi = spi;
>  
> -- 
> 2.9.0
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel